xref: /llvm-project/libcxx/test/std/iterators/predef.iterators/iterators.common/ctor.sentinel.pass.cpp (revision d2baefae6846765eef6a6dd69d4fdf1082ce29ad)
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 // constexpr common_iterator(S s);
12 
13 #include <iterator>
14 #include <cassert>
15 #include <type_traits>
16 
17 #include "test_iterators.h"
18 
19 template<class It>
test()20 constexpr bool test() {
21   using Sent = sentinel_wrapper<It>;
22   using CommonIt = std::common_iterator<It, Sent>;
23   int a[] = {1,2,3};
24   It it = It(a);
25   Sent sent = Sent(It(a+1));
26 
27   CommonIt lv = CommonIt(sent);
28   assert(lv == CommonIt(sent));
29   assert(lv != CommonIt(it));
30   if (!std::is_constant_evaluated()) {
31     assert(lv == std::next(CommonIt(it)));
32   }
33 
34   CommonIt rv = CommonIt(std::move(sent));
35   assert(rv == CommonIt(sent));
36   assert(rv != CommonIt(it));
37   if (!std::is_constant_evaluated()) {
38     assert(rv == std::next(CommonIt(it)));
39   }
40 
41   return true;
42 }
43 
main(int,char **)44 int main(int, char**) {
45   test<cpp17_input_iterator<int*>>();
46   test<forward_iterator<int*>>();
47   test<bidirectional_iterator<int*>>();
48   test<random_access_iterator<int*>>();
49   test<contiguous_iterator<int*>>();
50   test<int*>();
51   test<const int*>();
52 
53   static_assert(test<cpp17_input_iterator<int*>>());
54   static_assert(test<forward_iterator<int*>>());
55   static_assert(test<bidirectional_iterator<int*>>());
56   static_assert(test<random_access_iterator<int*>>());
57   static_assert(test<contiguous_iterator<int*>>());
58   static_assert(test<int*>());
59   static_assert(test<const int*>());
60 
61   return 0;
62 }
63