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