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 // UNSUPPORTED: libcpp-has-no-incomplete-ranges
11 
12 // friend constexpr bool operator==(const inner-iterator& x, const inner-iterator& y);
13 //   requires forward_range<Base>;
14 //
15 // friend constexpr bool operator==(const inner-iterator& x, default_sentinel_t);
16 
17 #include <ranges>
18 
19 #include <concepts>
20 #include <string_view>
21 #include "../types.h"
22 
23 template <class Iter>
24 concept CanCallEquals = requires(const Iter& i) {
25   i == i;
26   i != i;
27 };
28 
test()29 constexpr bool test() {
30   // When `View` is a forward range, `inner-iterator` supports both overloads of `operator==`.
31   {
32     SplitViewForward v("abc def", " ");
33     auto val = *v.begin();
34     auto b = val.begin();
35     std::same_as<std::default_sentinel_t> decltype(auto) e = val.end();
36 
37     // inner-iterator == inner-iterator
38     {
39       assert(b == b);
40       assert(!(b != b));
41     }
42 
43     // inner-iterator == default_sentinel
44     {
45       assert(!(b == e));
46       assert(b != e);
47 
48       assert(!(b == std::default_sentinel));
49       assert(b != std::default_sentinel);
50     }
51   }
52 
53   // When `View` is an input range, `inner-iterator only supports comparing an `inner-iterator` to the default sentinel.
54   {
55     SplitViewInput v("abc def", ' ');
56     auto val = *v.begin();
57     auto b = val.begin();
58     std::same_as<std::default_sentinel_t> decltype(auto) e = val.end();
59 
60     static_assert(!CanCallEquals<decltype(b)>);
61 
62     assert(!(b == std::default_sentinel));
63     assert(b != std::default_sentinel);
64     assert(!(b == e));
65     assert(b != e);
66   }
67 
68   return true;
69 }
70 
main(int,char **)71 int main(int, char**) {
72   test();
73   static_assert(test());
74 
75   return 0;
76 }
77