xref: /llvm-project/libcxx/test/std/iterators/predef.iterators/move.iterators/move.sentinel/op_eq.pass.cpp (revision b06049bc3b79be4a037a60dec4ad19a68e196a8f)
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 // <iterator>
12 
13 // move_sentinel
14 
15 // template <class Iter, class Sent>
16 //   constexpr bool operator==(const move_iterator<Iter>& x, const move_sentinel<Sent>& y);
17 
18 #include <iterator>
19 #include <cassert>
20 
21 #include "test_macros.h"
22 #include "test_iterators.h"
23 
24 template<class T, class U> concept HasEquals = requires (T t, U u) { t == u; };
25 template<class T, class U> concept HasNotEquals = requires (T t, U u) { t != u; };
26 template<class T, class U> concept HasLess = requires (T t, U u) { t < u; };
27 
28 static_assert(!HasEquals<std::move_iterator<int*>, std::move_sentinel<char*>>);
29 static_assert(!HasNotEquals<std::move_iterator<int*>, std::move_sentinel<char*>>);
30 static_assert(!HasLess<std::move_iterator<int*>, std::move_sentinel<char*>>);
31 
32 static_assert( HasEquals<std::move_iterator<int*>, std::move_sentinel<const int*>>);
33 static_assert( HasNotEquals<std::move_iterator<int*>, std::move_sentinel<const int*>>);
34 static_assert(!HasLess<std::move_iterator<int*>, std::move_sentinel<const int*>>);
35 
36 static_assert( HasEquals<std::move_iterator<const int*>, std::move_sentinel<int*>>);
37 static_assert( HasNotEquals<std::move_iterator<const int*>, std::move_sentinel<int*>>);
38 static_assert(!HasLess<std::move_iterator<const int*>, std::move_sentinel<int*>>);
39 
40 template <class It>
test_one()41 constexpr void test_one() {
42   char s[] = "abc";
43   const auto it = std::move_iterator<It>(It(s));
44   const auto sent1 = std::move_sentinel<sentinel_wrapper<It>>(sentinel_wrapper<It>(It(s)));
45   const auto sent2 = std::move_sentinel<sentinel_wrapper<It>>(sentinel_wrapper<It>(It(s + 1)));
46   ASSERT_SAME_TYPE(decltype(it == sent1), bool);
47   assert( (it == sent1));
48   assert(!(it != sent1));
49   assert(!(it == sent2));
50   assert( (it != sent2));
51   assert( (sent1 == it));
52   assert(!(sent1 != it));
53   assert(!(sent2 == it));
54   assert( (sent2 != it));
55   static_assert(!HasEquals<decltype(sent1), decltype(sent1)>);
56   static_assert(!HasLess<decltype(sent1), decltype(sent1)>);
57 }
58 
test()59 constexpr bool test() {
60   test_one<cpp17_input_iterator<char*>>();
61   test_one<cpp20_input_iterator<char*>>();
62   test_one<forward_iterator<char*>>();
63   test_one<bidirectional_iterator<char*>>();
64   test_one<random_access_iterator<char*>>();
65   test_one<contiguous_iterator<char*>>();
66   test_one<three_way_contiguous_iterator<char*>>();
67   test_one<char*>();
68   test_one<const char*>();
69 
70   return true;
71 }
72 
main(int,char **)73 int main(int, char**) {
74   test();
75   static_assert(test());
76 
77   return 0;
78 }
79