diff --git a/tests/unittest.cpp b/tests/unittest.cpp index 3421e248f..9f294fa84 100644 --- a/tests/unittest.cpp +++ b/tests/unittest.cpp @@ -447,23 +447,36 @@ TEST_CASE("Iterator concepts", "[iterator-concepts]") { // a collection to play with auto collection = ExampleHitCollection(); - // bidirectional iterator traits + // input iterator traits STATIC_REQUIRE(std::is_same_v::iterator_category, - std::bidirectional_iterator_tag>); + std::input_iterator_tag>); STATIC_REQUIRE(std::is_same_v::iterator_category, - std::bidirectional_iterator_tag>); + std::input_iterator_tag>); STATIC_REQUIRE(std::is_same_v::iterator_category, - std::bidirectional_iterator_tag>); + std::input_iterator_tag>); STATIC_REQUIRE(std::is_same_v::iterator_category, - std::bidirectional_iterator_tag>); - -#ifdef __cpp_lib_ranges - // bidirectional iterator concepts (C++20) - STATIC_REQUIRE(std::bidirectional_iterator); - STATIC_REQUIRE(std::bidirectional_iterator); - STATIC_REQUIRE(std::bidirectional_iterator); - STATIC_REQUIRE(std::bidirectional_iterator); - STATIC_REQUIRE(std::ranges::bidirectional_range); + std::input_iterator_tag>); + + STATIC_REQUIRE_FALSE(std::is_same_v::iterator_category, + std::forward_iterator_tag>); + STATIC_REQUIRE_FALSE(std::is_same_v::iterator_category, + std::forward_iterator_tag>); + STATIC_REQUIRE_FALSE(std::is_same_v::iterator_category, + std::forward_iterator_tag>); + STATIC_REQUIRE_FALSE(std::is_same_v::iterator_category, + std::forward_iterator_tag>); + +#if __cpp_concepts + // input iterator concepts (C++20) + STATIC_REQUIRE(std::input_iterator); + STATIC_REQUIRE(std::input_iterator); + STATIC_REQUIRE(std::input_iterator); + STATIC_REQUIRE(std::input_iterator); + // but not foward iterator concept + STATIC_REQUIRE_FALSE(std::forward_iterator); + STATIC_REQUIRE_FALSE(std::forward_iterator); + STATIC_REQUIRE_FALSE(std::forward_iterator); + STATIC_REQUIRE_FALSE(std::forward_iterator); #endif // iterator loops @@ -519,8 +532,15 @@ TEST_CASE("Iterator concepts", "[iterator-concepts]") { auto not_found_reverse = std::find_if(collection.rbegin(), collection.rend(), [](const auto& h) { return h.cellID() == 0x1ULL; }); REQUIRE(not_found_reverse == collection.rend()); +} +TEST_CASE("Ranges (C++20)", "[ranges]") { #ifdef __cpp_lib_ranges + // a collection to play with + auto collection = ExampleHitCollection(); + + STATIC_REQUIRE(std::ranges::input_range); + // ranged views (C++20) auto is_non_zero = [](const auto& p) { return p.cellID() > 0; }; auto half_energy = [](const auto& p) { @@ -533,21 +553,21 @@ TEST_CASE("Iterator concepts", "[iterator-concepts]") { collection.create(0x42ULL, 1., 1., 1., 1.); // pipe syntax int count_pipe_syntax = 0; - for (auto c : collection | std::views::filter(is_non_zero) | std::views::reverse) { + for (auto c : collection | std::views::filter(is_non_zero)) { STATIC_REQUIRE(std::is_same_v); ++count_pipe_syntax; } REQUIRE(count_pipe_syntax == 1); // composing syntax auto count_composing = 0; - for (auto c : std::views::reverse(std::views::filter(collection, is_non_zero))) { + for (auto c : std::views::filter(collection, is_non_zero)) { STATIC_REQUIRE(std::is_same_v); ++count_composing; } REQUIRE(count_composing == 1); // take_while auto count_take_while = 0; - for (auto c : collection | std::views::take_while(is_non_zero) | std::views::reverse) { + for (auto c : collection | std::views::take_while(is_non_zero)) { STATIC_REQUIRE(std::is_same_v); ++count_take_while; }