Skip to content

Commit 2317b2d

Browse files
committed
add tests for interop with C++23 const_iterator adaptor
1 parent 68c4dbc commit 2317b2d

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

doc/collections_as_container.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ In addition to the *LegacyForwardIterator* the C++ standard specifies also the *
167167
| `std::back_insert_iterator` | ❗ attention | Compatible only with SubsetCollections, otherwise throws `std::invalid_argument` |
168168
| `std::front_insert_iterator` | ❌ no | `push_front` not defined |
169169
| `std::insert_iterator` | ❌ no | `insert` not defined |
170-
| `std::const_iterator` (C++23) | ❌ no | C++23 not supported yet |
170+
| `std::const_iterator` (C++23) | ❗ attention | `operator->` not defined as `iterator`'s and `const_iterator`'s `operator->` are non-`const`. |
171171
| `std::move_iterator` | ✔️ yes | Limited usefulness since dereference returns `reference` type not rvalue reference (`&&`) |
172-
| `std::counted_iterator` | ✔️ yes | `operator->` not defined as it requires `std::contiguous_iterator` |
172+
| `std::counted_iterator` | ❗ attention | `operator->` not defined as it requires `std::contiguous_iterator` |
173173

174174

175175
## Collection as a *range*

tests/unittests/std_interoperability.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -993,10 +993,40 @@ TEST_CASE("Collection and std iterator adaptors", "[collection][container][adapt
993993
// TODO add runtime checks here
994994
}
995995

996+
#if (__cplusplus >= 202302L)
996997
SECTION("Const iterator") {
997-
// C++23 required
998-
DOCUMENTED_STATIC_FAILURE((__cplusplus >= 202302L));
998+
// iterator
999+
STATIC_REQUIRE(std::is_base_of_v<std::input_iterator_tag, std::iterator_traits<iterator>::iterator_category>);
1000+
STATIC_REQUIRE(std::input_iterator<iterator>);
1001+
// make_const_iterator(iterator) gives basic_const_iterator not our iterator or our const_iterator
1002+
STATIC_REQUIRE(std::is_same_v<std::const_iterator<iterator>, std::basic_const_iterator<iterator>>);
1003+
{
1004+
auto coll = CollectionType();
1005+
coll.create().cellID(42);
1006+
auto cit = std::make_const_iterator(std::begin(coll));
1007+
REQUIRE((*cit).cellID() == 42);
1008+
// can't -> because iterators' -> is non-const
1009+
DOCUMENTED_STATIC_FAILURE(traits::has_member_of_pointer_v<std::const_iterator<iterator>>);
1010+
// REQUIRE(cit->cellID() == 42)
1011+
// REQUIRE(counted.base()->cellID() == 42);
1012+
}
1013+
// const_iterator
1014+
STATIC_REQUIRE(std::is_base_of_v<std::input_iterator_tag, std::iterator_traits<const_iterator>::iterator_category>);
1015+
STATIC_REQUIRE(std::input_iterator<const_iterator>);
1016+
// make_const_iterator(iterator) gives basic_const_iterator not our iterator or our const_iterator
1017+
STATIC_REQUIRE(std::is_same_v<std::const_iterator<const_iterator>, std::basic_const_iterator<const_iterator>>);
1018+
{
1019+
auto coll = CollectionType();
1020+
coll.create().cellID(42);
1021+
auto cit = std::make_const_iterator(std::cbegin(coll));
1022+
REQUIRE((*cit).cellID() == 42);
1023+
// can't -> because const_iterators' -> is non-const
1024+
DOCUMENTED_STATIC_FAILURE(traits::has_member_of_pointer_v<std::const_iterator<const_iterator>>);
1025+
// REQUIRE(cit->cellID() == 42)
1026+
// REQUIRE(counted.base()->cellID() == 42);
1027+
}
9991028
}
1029+
#endif
10001030

10011031
SECTION("Move iterator") {
10021032
// iterator

0 commit comments

Comments
 (0)