Skip to content

Commit

Permalink
c++17 concepts with CPP_template for engine/idTable/ files (#1746)
Browse files Browse the repository at this point in the history
Backport C++20 concepts in the `src/engine/idTable` directory back to C++17 using macros from `range-v3`
  • Loading branch information
sebastian-wieczorek authored Feb 10, 2025
1 parent caae483 commit 5caf9f4
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 87 deletions.
23 changes: 16 additions & 7 deletions src/engine/idTable/CompressedExternalIdTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@

namespace ad_utility {

namespace compressedExternalIdTable::detail {
template <typename B, typename R>
CPP_requires(HasPushBackRequires, requires(B& b, const R& r)(b.push_back(r)));

template <typename B, typename R>
CPP_concept HasPushBack = CPP_requires_ref(HasPushBackRequires, B, R);
} // namespace compressedExternalIdTable::detail

using namespace ad_utility::memory_literals;

// The default size for compressed blocks in the following classes.
Expand Down Expand Up @@ -338,8 +346,9 @@ class CompressedExternalIdTableBase {
}
// Add a single row to the input. The type of `row` needs to be something that
// can be `push_back`ed to a `IdTable`.
void push(const auto& row) requires requires { currentBlock_.push_back(row); }
{
CPP_template(typename R)(
requires compressedExternalIdTable::detail::HasPushBack<
decltype(currentBlock_), R>) void push(const R& row) {
++numElementsPushed_;
currentBlock_.push_back(row);
if (currentBlock_.size() >= blocksize_) {
Expand Down Expand Up @@ -456,11 +465,11 @@ class CompressedExternalIdTable

// When we have a static number of columns, then the `numCols` argument to the
// constructor is redundant.
explicit CompressedExternalIdTable(
CPP_member explicit CPP_ctor(CompressedExternalIdTable)(
std::string filename, ad_utility::MemorySize memory,
ad_utility::AllocatorWithLimit<Id> allocator,
MemorySize blocksizeCompression = DEFAULT_BLOCKSIZE_EXTERNAL_ID_TABLE)
requires(NumStaticCols > 0)
MemorySize blocksizeCompression = DEFAULT_BLOCKSIZE_EXTERNAL_ID_TABLE)(
requires(NumStaticCols > 0))
: CompressedExternalIdTable(std::move(filename), NumStaticCols, memory,
std::move(allocator), blocksizeCompression) {}

Expand Down Expand Up @@ -583,11 +592,11 @@ class CompressedExternalIdTableSorter

// When we have a static number of columns, then the `numCols` argument to the
// constructor is redundant.
CompressedExternalIdTableSorter(
CPP_member CPP_ctor(CompressedExternalIdTableSorter)(
std::string filename, ad_utility::MemorySize memory,
ad_utility::AllocatorWithLimit<Id> allocator,
MemorySize blocksizeCompression = DEFAULT_BLOCKSIZE_EXTERNAL_ID_TABLE,
Comparator comp = {}) requires(NumStaticCols > 0)
Comparator comp = {})(requires(NumStaticCols > 0))
: CompressedExternalIdTableSorter(std::move(filename), NumStaticCols,
memory, std::move(allocator),
blocksizeCompression, comp) {}
Expand Down
Loading

0 comments on commit 5caf9f4

Please sign in to comment.