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-no-concepts
11 // UNSUPPORTED: gcc-10
12 
13 // constexpr auto operator->() const noexcept
14 //   requires contiguous_iterator<I>;
15 
16 #include <iterator>
17 
18 #include "test_macros.h"
19 #include "test_iterators.h"
20 
21 template<class Iter>
22 concept ArrowEnabled = requires(Iter& iter) {
23   iter.operator->();
24 };
25 
26 constexpr bool test() {
27   int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8};
28 
29   {
30     std::counted_iterator iter(contiguous_iterator<int*>{buffer}, 8);
31     for (int i = 0; i < 8; ++i, ++iter)
32       assert(iter.operator->() == buffer + i);
33 
34     static_assert(noexcept(iter.operator->()));
35   }
36   {
37     const std::counted_iterator iter(contiguous_iterator<int*>{buffer}, 8);
38     assert(iter.operator->() == buffer);
39 
40     static_assert(noexcept(iter.operator->()));
41   }
42 
43   {
44       static_assert( ArrowEnabled<std::counted_iterator<contiguous_iterator<int*>>>);
45       static_assert(!ArrowEnabled<std::counted_iterator<random_access_iterator<int*>>>);
46   }
47 
48   return true;
49 }
50 
51 int main(int, char**) {
52   test();
53   static_assert(test());
54 
55   return 0;
56 }
57