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