This is an archive of the discontinued LLVM Phabricator instance.

[libcxx][ranges] Add `unreachable_sentinel`.

Authored by zoecarver on Aug 11 2021, 11:17 AM.


Diff Detail

Event Timeline

zoecarver created this revision.Aug 11 2021, 11:17 AM
zoecarver requested review of this revision.Aug 11 2021, 11:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 11 2021, 11:17 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript

Generate private header tests.

Quuxplusone added a subscriber: Quuxplusone.

LGTM % nits.


Swap this down to below [iterators.counted], to match


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.

ldionne accepted this revision.Aug 11 2021, 12:57 PM

LGTM but please implement Arthur's comments, I agree with everything. Also, is there something that needs updating in the paper status?

I don't need to see this again.

This revision is now accepted and ready to land.Aug 11 2021, 12:57 PM
cjdb accepted this revision.Aug 11 2021, 1:09 PM

What the others have said.

Also, is there something that needs updating in the paper status?

I can't find anything.

Thanks for the reviews everyone. Thanks for the tests Arthur.

This revision was automatically updated to reflect the committed changes.