Skip to content

Commit

Permalink
add tests for interop with C++23 const_iterator adaptor
Browse files Browse the repository at this point in the history
  • Loading branch information
m-fila committed Dec 18, 2024
1 parent 68c4dbc commit 2317b2d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
4 changes: 2 additions & 2 deletions doc/collections_as_container.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ In addition to the *LegacyForwardIterator* the C++ standard specifies also the *
| `std::back_insert_iterator` | ❗ attention | Compatible only with SubsetCollections, otherwise throws `std::invalid_argument` |
| `std::front_insert_iterator` | ❌ no | `push_front` not defined |
| `std::insert_iterator` | ❌ no | `insert` not defined |
| `std::const_iterator` (C++23) | ❌ no | C++23 not supported yet |
| `std::const_iterator` (C++23) | ❗ attention | `operator->` not defined as `iterator`'s and `const_iterator`'s `operator->` are non-`const`. |
| `std::move_iterator` | ✔️ yes | Limited usefulness since dereference returns `reference` type not rvalue reference (`&&`) |
| `std::counted_iterator` | ✔️ yes | `operator->` not defined as it requires `std::contiguous_iterator` |
| `std::counted_iterator` | ❗ attention | `operator->` not defined as it requires `std::contiguous_iterator` |


## Collection as a *range*
Expand Down
34 changes: 32 additions & 2 deletions tests/unittests/std_interoperability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,10 +993,40 @@ TEST_CASE("Collection and std iterator adaptors", "[collection][container][adapt
// TODO add runtime checks here
}

#if (__cplusplus >= 202302L)
SECTION("Const iterator") {
// C++23 required
DOCUMENTED_STATIC_FAILURE((__cplusplus >= 202302L));
// iterator
STATIC_REQUIRE(std::is_base_of_v<std::input_iterator_tag, std::iterator_traits<iterator>::iterator_category>);
STATIC_REQUIRE(std::input_iterator<iterator>);
// make_const_iterator(iterator) gives basic_const_iterator not our iterator or our const_iterator
STATIC_REQUIRE(std::is_same_v<std::const_iterator<iterator>, std::basic_const_iterator<iterator>>);
{
auto coll = CollectionType();
coll.create().cellID(42);
auto cit = std::make_const_iterator(std::begin(coll));
REQUIRE((*cit).cellID() == 42);
// can't -> because iterators' -> is non-const
DOCUMENTED_STATIC_FAILURE(traits::has_member_of_pointer_v<std::const_iterator<iterator>>);
// REQUIRE(cit->cellID() == 42)
// REQUIRE(counted.base()->cellID() == 42);
}
// const_iterator
STATIC_REQUIRE(std::is_base_of_v<std::input_iterator_tag, std::iterator_traits<const_iterator>::iterator_category>);
STATIC_REQUIRE(std::input_iterator<const_iterator>);
// make_const_iterator(iterator) gives basic_const_iterator not our iterator or our const_iterator
STATIC_REQUIRE(std::is_same_v<std::const_iterator<const_iterator>, std::basic_const_iterator<const_iterator>>);
{
auto coll = CollectionType();
coll.create().cellID(42);
auto cit = std::make_const_iterator(std::cbegin(coll));
REQUIRE((*cit).cellID() == 42);
// can't -> because const_iterators' -> is non-const
DOCUMENTED_STATIC_FAILURE(traits::has_member_of_pointer_v<std::const_iterator<const_iterator>>);
// REQUIRE(cit->cellID() == 42)
// REQUIRE(counted.base()->cellID() == 42);
}
}
#endif

SECTION("Move iterator") {
// iterator
Expand Down

0 comments on commit 2317b2d

Please sign in to comment.