1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // constexpr decltype(auto) operator*();
12 // constexpr decltype(auto) operator*() const
13 // requires dereferenceable<const I>;
17 #include "test_macros.h"
18 #include "test_iterators.h"
20 struct InputOrOutputArchetype
{
21 using difference_type
= int;
25 constexpr int operator*() const { return *ptr
; }
26 constexpr void operator++(int) { ++ptr
; }
27 constexpr InputOrOutputArchetype
& operator++() { ++ptr
; return *this; }
30 struct NonConstDeref
{
31 using difference_type
= int;
35 constexpr int operator*() { return *ptr
; }
36 constexpr void operator++(int) { ++ptr
; }
37 constexpr NonConstDeref
& operator++() { ++ptr
; return *this; }
41 concept IsDereferenceable
= requires(T
& i
) {
45 constexpr bool test() {
46 int buffer
[8] = {1, 2, 3, 4, 5, 6, 7, 8};
49 static_assert( IsDereferenceable
<std::counted_iterator
<InputOrOutputArchetype
>>);
50 static_assert( IsDereferenceable
<const std::counted_iterator
<InputOrOutputArchetype
>>);
51 static_assert( IsDereferenceable
<std::counted_iterator
<NonConstDeref
>>);
52 static_assert(!IsDereferenceable
<const std::counted_iterator
<NonConstDeref
>>);
56 std::counted_iterator
iter(cpp20_input_iterator
<int*>{buffer
}, 8);
57 for (int i
= 1; i
< 9; ++i
, ++iter
)
62 std::counted_iterator
iter(forward_iterator
<int*>{buffer
}, 8);
63 for (int i
= 1; i
< 9; ++i
, ++iter
)
68 std::counted_iterator
iter(contiguous_iterator
<int*>{buffer
}, 8);
69 for (int i
= 1; i
< 9; ++i
, ++iter
)
74 std::counted_iterator
iter(InputOrOutputArchetype
{buffer
}, 8);
75 for (int i
= 1; i
< 9; ++i
, ++iter
)
80 const std::counted_iterator
iter(cpp20_input_iterator
<int*>{buffer
}, 8);
85 const std::counted_iterator
iter(forward_iterator
<int*>{buffer
+ 1}, 7);
90 const std::counted_iterator
iter(contiguous_iterator
<int*>{buffer
+ 2}, 6);
95 const std::counted_iterator
iter(InputOrOutputArchetype
{buffer
+ 2}, 6);
102 int main(int, char**) {
104 static_assert(test());