[libcxx-commits] [PATCH] D107920: [libcxx][ranges] Add `unreachable_sentinel`.
Arthur O'Dwyer via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Aug 11 11:36:01 PDT 2021
Quuxplusone accepted this revision as: Quuxplusone.
Quuxplusone added a comment.
LGTM % nits.
================
Comment at: libcxx/include/iterator:406-409
+// [unreachable.sentinel], unreachable sentinel
+struct unreachable_sentinel_t;
+inline constexpr unreachable_sentinel_t unreachable_sentinel{};
+
----------------
Swap this down to below [iterators.counted], to match https://eel.is/c++draft/iterator.synopsis
================
Comment at: libcxx/test/std/iterators/predef.iterators/unreachable.sentinel/unreachable_sentinel.pass.cpp:29-37
+ std::unreachable_sentinel_t s;
+ for (unsigned i = 0; i < 100; ++i) {
+ assert(i != s);
+ assert(i != std::unreachable_sentinel);
+ }
+
+ int *ptr = nullptr;
----------------
I'd test both normal and reversed comparisons, and equality and inequality, and at least one trivial SFINAE-friendliness test and noexceptness test. I.e. I'd replace this with some variation on
```
constexpr bool test() {
auto sentinel = std::unreachable_sentinel;
int i = 42;
assert(i != sentinel);
assert(sentinel != i);
assert(!(i == sentinel));
assert(!(sentinel == i));
assert(&i != sentinel);
assert(sentinel != &i);
assert(!(&i == sentinel));
assert(!(sentinel == &i));
int *p = nullptr;
assert(p != sentinel);
assert(sentinel != p);
assert(!(p == sentinel));
assert(!(sentinel == p));
assert( std::equality_comparable_with<std::unreachable_sentinel_t, int>);
assert( std::equality_comparable_with<std::unreachable_sentinel_t, int*>);
assert(!std::equality_comparable_with<std::unreachable_sentinel_t, void*>);
ASSERT_NOEXCEPT(sentinel == p);
ASSERT_NOEXCEPT(sentinel != p);
return true;
}
```
and remember to do the usual `test(); static_assert(test());` dance.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D107920/new/
https://reviews.llvm.org/D107920
More information about the libcxx-commits
mailing list