Skip to content

Commit

Permalink
move checking unsuported range algorithms to a separate test case
Browse files Browse the repository at this point in the history
  • Loading branch information
m-fila committed Dec 18, 2024
1 parent 2a08920 commit 7e21a55
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions tests/unittests/std_interoperability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1215,24 +1215,6 @@ TEST_CASE("Collection and std algorithms", "[collection][iterator][std]") {

#if (__cplusplus >= 202002L)

// helper concept for unsupported algorithm compilation test
template <typename T>
concept is_range_adjacent_findable = requires(T coll) {
std::ranges::adjacent_find(coll, [](const auto& a, const auto& b) { return a.cellID() == b.cellID(); });
};

// helper concept for unsupported algorithm compilation test
template <typename T>
concept is_range_sortable = requires(T coll) {
std::ranges::sort(coll, [](const auto& a, const auto& b) { return a.cellID() < b.cellID(); });
};

// helper concept for unsupported algorithm compilation test
template <typename T>
concept is_range_fillable = requires(T coll) {
std::ranges::fill(coll, typename T::value_type{});
};

TEST_CASE("Collection and std ranges algorithms", "[collection][ranges][std]") {
auto coll = CollectionType();
coll.create().cellID(1);
Expand All @@ -1258,13 +1240,34 @@ TEST_CASE("Collection and std ranges algorithms", "[collection][ranges][std]") {
REQUIRE(subcoll.size() == 2);
REQUIRE(subcoll[0].cellID() == 5);
REQUIRE(subcoll[1].cellID() == 3);
}

// helper concept for unsupported algorithm compilation test
template <typename T>
concept is_range_adjacent_findable = requires(T coll) {
std::ranges::adjacent_find(coll, [](const auto& a, const auto& b) { return a.cellID() == b.cellID(); });
};

// helper concept for unsupported algorithm compilation test
template <typename T>
concept is_range_sortable = requires(T coll) {
std::ranges::sort(coll, [](const auto& a, const auto& b) { return a.cellID() < b.cellID(); });
};

// helper concept for unsupported algorithm compilation test
template <typename T>
concept is_range_fillable = requires(T coll) {
std::ranges::fill(coll, typename T::value_type{});
};

TEST_CASE("Collection and unsupported std ranges algorithms", "[collection][ranges][std]") {
// check that algorithms requiring unsupported iterator concepts won't compile
DOCUMENTED_STATIC_FAILURE(is_range_adjacent_findable<CollectionType>);
DOCUMENTED_STATIC_FAILURE(is_range_sortable<CollectionType>);
DOCUMENTED_STATIC_FAILURE(is_range_fillable<CollectionType>);
}
#endif

#endif // __cplusplus >= 202002L

#undef DOCUMENTED_STATIC_FAILURE
#undef DOCUMENTED_FAILURE

0 comments on commit 7e21a55

Please sign in to comment.