Skip to content

Commit

Permalink
check ranges concepts
Browse files Browse the repository at this point in the history
  • Loading branch information
m-fila committed Dec 11, 2024
1 parent 6ad08f5 commit aaf870f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
16 changes: 16 additions & 0 deletions doc/collections_as_container.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,22 @@ In addition to the *LegacyForwardIterator* the C++ standard specifies also the *
| `std::counted_iterator` | ✔️ yes | `operator->` not defined as it requires `std::contiguous_iterator` |


## Collection as a *range*

| Concept | Fulfilled by Collection? |
|---------|--------------------------|
| `std::ranges::range` | ✔️ yes |
| `std::ranges::borrowed_range` | ❌ no |
| `std::ranges::sized_range` | ✔️ yes |
| `std::ranges::input_range` | ✔️ yes |
| `std::ranges::output_range` | ❌ no |
| `std::ranges::forward_range` | ❌ no |
| `std::ranges::bidirectional_range` | ❌ no |
| `std::ranges::random_access_range` | ❌ no |
| `std::ranges::contiguous_range` | ❌ no |
| `std::ranges::common_range` | ✔️ yes |
| `std::ranges::viewable_range` | ✔️ yes |

## Collection and standard algorithms

Most of the standard algorithms require the iterators to be at least *InputIterator*. The iterators of PODIO collection don't fulfil this requirement, therefore they are not compatible with standard algorithms according to the specification.
Expand Down
36 changes: 36 additions & 0 deletions tests/unittests/std_interoperability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <iterator>
#include <limits>
#include <memory>
#include <ranges>
#include <stdexcept>
#include <type_traits>

Expand Down Expand Up @@ -1144,5 +1145,40 @@ TEST_CASE("Collection and std iterator adaptors", "[collection][container][adapt
#endif
}

#if (__cplusplus >= 202002L)
TEST_CASE("Collection as range", "[collection][ranges][std]") {
CollectionType coll;
coll.create();

// std::ranges::range
STATIC_REQUIRE(std::ranges::range<CollectionType>);
// std::range::borrowed_range
DOCUMENTED_STATIC_FAILURE(std::ranges::borrowed_range<CollectionType>);
// std::range::sized_range
STATIC_REQUIRE(std::ranges::sized_range<CollectionType>);
REQUIRE(std::ranges::size(coll) == 1);
REQUIRE(std::ranges::size(coll) ==
static_cast<decltype(std::ranges::size(coll))>(std::ranges::distance(std::begin(coll), std::end(coll))));
// std::ranges::input_range
STATIC_REQUIRE(std::ranges::input_range<CollectionType>);
// std::range::output_range
DOCUMENTED_STATIC_FAILURE(std::ranges::output_range<CollectionType, CollectionType::value_type>);
DOCUMENTED_STATIC_FAILURE(std::ranges::output_range<CollectionType, CollectionType::value_type::mutable_type>);
// std::range::forward_range
DOCUMENTED_STATIC_FAILURE(std::ranges::forward_range<CollectionType>);
// std::range::bidirectional_range
DOCUMENTED_STATIC_FAILURE(std::ranges::bidirectional_range<CollectionType>);
// std::range::random_access_range
DOCUMENTED_STATIC_FAILURE(std::ranges::random_access_range<CollectionType>);
// std::range::contiguous_range
DOCUMENTED_STATIC_FAILURE(std::ranges::contiguous_range<CollectionType>);
// std::range::common_range
STATIC_REQUIRE(std::ranges::common_range<CollectionType>);
// std::range::viewable_range
STATIC_REQUIRE(std::ranges::viewable_range<CollectionType>);
}
#endif


#undef DOCUMENTED_STATIC_FAILURE
#undef DOCUMENTED_FAILURE

0 comments on commit aaf870f

Please sign in to comment.