1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++03, c++11, c++14, c++17
10
11// struct unreachable_sentinel_t;
12// inline constexpr unreachable_sentinel_t unreachable_sentinel;
13
14#include <iterator>
15
16#include <cassert>
17#include <concepts>
18#include <type_traits>
19
20#include "test_macros.h"
21
22template<class T, class U>
23concept weakly_equality_comparable_with = requires(const T& t, const U& u) {
24 { t == u } -> std::same_as<bool>;
25 { t != u } -> std::same_as<bool>;
26 { u == t } -> std::same_as<bool>;
27 { u != t } -> std::same_as<bool>;
28};
29
30constexpr bool test() {
31 static_assert(std::is_empty_v<std::unreachable_sentinel_t>);
32 static_assert(std::semiregular<std::unreachable_sentinel_t>);
33
34 static_assert(std::same_as<decltype(std::unreachable_sentinel), const std::unreachable_sentinel_t>);
35
36 auto sentinel = std::unreachable_sentinel;
37 int i = 42;
38 assert(i != sentinel);
39 assert(sentinel != i);
40 assert(!(i == sentinel));
41 assert(!(sentinel == i));
42
43 assert(&i != sentinel);
44 assert(sentinel != &i);
45 assert(!(&i == sentinel));
46 assert(!(sentinel == &i));
47
48 int *p = nullptr;
49 assert(p != sentinel);
50 assert(sentinel != p);
51 assert(!(p == sentinel));
52 assert(!(sentinel == p));
53
54 static_assert( weakly_equality_comparable_with<std::unreachable_sentinel_t, int>);
55 static_assert( weakly_equality_comparable_with<std::unreachable_sentinel_t, int*>);
56 static_assert(!weakly_equality_comparable_with<std::unreachable_sentinel_t, void*>);
57 ASSERT_NOEXCEPT(sentinel == p);
58 ASSERT_NOEXCEPT(sentinel != p);
59
60 return true;
61}
62
63int main(int, char**) {
64 test();
65 static_assert(test());
66
67 return 0;
68}
69

source code of libcxx/test/std/iterators/predef.iterators/unreachable.sentinel/unreachable_sentinel.pass.cpp