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 const I& base() const &;
12 // constexpr I base() &&;
16 #include "test_macros.h"
17 #include "test_iterators.h"
19 struct InputOrOutputArchetype
{
20 using difference_type
= int;
24 int operator*() { return *ptr
; }
25 void operator++(int) { ++ptr
; }
26 InputOrOutputArchetype
& operator++() { ++ptr
; return *this; }
29 constexpr bool test() {
30 int buffer
[8] = {1, 2, 3, 4, 5, 6, 7, 8};
33 std::counted_iterator
iter(cpp20_input_iterator
<int*>{buffer
}, 8);
34 assert(base(iter
.base()) == buffer
);
35 assert(base(std::move(iter
).base()) == buffer
);
37 ASSERT_NOEXCEPT(iter
.base());
38 ASSERT_SAME_TYPE(decltype(iter
.base()), const cpp20_input_iterator
<int*>&);
39 ASSERT_SAME_TYPE(decltype(std::move(iter
).base()), cpp20_input_iterator
<int*>);
43 std::counted_iterator
iter(forward_iterator
<int*>{buffer
}, 8);
44 assert(base(iter
.base()) == buffer
);
45 assert(base(std::move(iter
).base()) == buffer
);
47 ASSERT_SAME_TYPE(decltype(iter
.base()), const forward_iterator
<int*>&);
48 ASSERT_SAME_TYPE(decltype(std::move(iter
).base()), forward_iterator
<int*>);
52 std::counted_iterator
iter(contiguous_iterator
<int*>{buffer
}, 8);
53 assert(base(iter
.base()) == buffer
);
54 assert(base(std::move(iter
).base()) == buffer
);
56 ASSERT_SAME_TYPE(decltype(iter
.base()), const contiguous_iterator
<int*>&);
57 ASSERT_SAME_TYPE(decltype(std::move(iter
).base()), contiguous_iterator
<int*>);
61 std::counted_iterator
iter(InputOrOutputArchetype
{buffer
}, 6);
62 assert(iter
.base().ptr
== buffer
);
63 assert(std::move(iter
).base().ptr
== buffer
);
65 ASSERT_SAME_TYPE(decltype(iter
.base()), const InputOrOutputArchetype
&);
66 ASSERT_SAME_TYPE(decltype(std::move(iter
).base()), InputOrOutputArchetype
);
70 const std::counted_iterator
iter(cpp20_input_iterator
<int*>{buffer
}, 8);
71 assert(base(iter
.base()) == buffer
);
72 assert(base(std::move(iter
).base()) == buffer
);
74 ASSERT_SAME_TYPE(decltype(iter
.base()), const cpp20_input_iterator
<int*>&);
75 ASSERT_SAME_TYPE(decltype(std::move(iter
).base()), const cpp20_input_iterator
<int*>&);
79 const std::counted_iterator
iter(forward_iterator
<int*>{buffer
}, 7);
80 assert(base(iter
.base()) == buffer
);
81 assert(base(std::move(iter
).base()) == buffer
);
83 ASSERT_SAME_TYPE(decltype(iter
.base()), const forward_iterator
<int*>&);
84 ASSERT_SAME_TYPE(decltype(std::move(iter
).base()), const forward_iterator
<int*>&);
88 const std::counted_iterator
iter(contiguous_iterator
<int*>{buffer
}, 6);
89 assert(base(iter
.base()) == buffer
);
90 assert(base(std::move(iter
).base()) == buffer
);
92 ASSERT_SAME_TYPE(decltype(iter
.base()), const contiguous_iterator
<int*>&);
93 ASSERT_SAME_TYPE(decltype(std::move(iter
).base()), const contiguous_iterator
<int*>&);
97 const std::counted_iterator
iter(InputOrOutputArchetype
{buffer
}, 6);
98 assert(iter
.base().ptr
== buffer
);
99 assert(std::move(iter
).base().ptr
== buffer
);
101 ASSERT_SAME_TYPE(decltype(iter
.base()), const InputOrOutputArchetype
&);
102 ASSERT_SAME_TYPE(decltype(std::move(iter
).base()), const InputOrOutputArchetype
&);
108 int main(int, char**) {
110 static_assert(test());