Skip to content

Commit

Permalink
Have printing function as class members in the header
Browse files Browse the repository at this point in the history
  • Loading branch information
Qup42 committed Jun 21, 2024
1 parent b536a2a commit 2c4b4e7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
18 changes: 9 additions & 9 deletions src/engine/idTable/IdTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,15 @@ class IdTableStatic
*(static_cast<Base*>(this)) = std::move(b);
return *this;
}

friend std::ostream& operator<<(std::ostream& os,
const IdTableStatic& idTable) {
os << "{ ";
std::ranges::copy(
idTable, std::ostream_iterator<columnBasedIdTable::Row<Id>>(os, " "));
os << "}";
return os;
}
};

// This was previously implemented as an alias (`using IdTable =
Expand All @@ -766,15 +775,6 @@ class IdTable : public IdTableStatic<0> {
IdTable(Base&& b) : Base(std::move(b)) {}
};

// ____________________________________________________________________________
std::ostream& operator<<(std::ostream& os, const IdTable& idTable) {
os << "{ ";
std::ranges::copy(
idTable, std::ostream_iterator<columnBasedIdTable::Row<Id>>(os, " "));
os << "}";
return os;
}

/// A constant view into an IdTable that does not own its data
template <int COLS>
using IdTableView =
Expand Down
17 changes: 8 additions & 9 deletions src/engine/idTable/IdTableRow.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,16 @@ class Row {
std::ranges::copy(*this, result.begin());
return result;
}
};

// ____________________________________________________________________________
std::ostream& operator<<(std::ostream& os,
const columnBasedIdTable::Row<Id>& idTableRow) {
os << "(";
for (size_t i = 0; i < idTableRow.numColumns(); ++i) {
os << idTableRow[i] << (i < idTableRow.numColumns() - 1 ? " " : ")");
template <std::enable_if_t<std::is_same_v<T, Id>, bool> = true>
friend std::ostream& operator<<(std::ostream& os, const Row& idTableRow) {
os << "(";
for (size_t i = 0; i < idTableRow.numColumns(); ++i) {
os << idTableRow[i] << (i < idTableRow.numColumns() - 1 ? " " : ")");
}
return os;
}
return os;
}
};

// The following two classes store a reference to a row in the underlying
// column-based `Table`. This has to be its own class instead of `Row&` because
Expand Down

0 comments on commit 2c4b4e7

Please sign in to comment.