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 // decltype(auto) operator->() const
12 // requires see below;
18 #include "test_iterators.h"
19 #include "test_macros.h"
23 // Case 1: http://eel.is/c++draft/iterators.common#common.iter.access-5.1
25 auto check
= []<class Iterator
>() {
26 int buffer
[8] = {1, 2, 3, 4, 5, 6, 7, 8};
27 Iterator
iter(buffer
);
28 using Common
= std::common_iterator
<Iterator
, sentinel_wrapper
<Iterator
>>;
31 std::same_as
<Iterator
> auto result
= common
.operator->();
32 assert(base(result
) == buffer
);
34 Common
const ccommon(iter
);
35 std::same_as
<Iterator
> auto cresult
= ccommon
.operator->();
36 assert(base(cresult
) == buffer
);
39 check
.operator()<contiguous_iterator
<int*>>();
40 check
.operator()<int*>();
43 // Case 2: http://eel.is/c++draft/iterators.common#common.iter.access-5.2
45 auto check
= []<class Iterator
>() {
46 int buffer
[8] = {1, 2, 3, 4, 5, 6, 7, 8};
47 Iterator
iter(buffer
);
48 using Common
= std::common_iterator
<Iterator
, sentinel_type
<int*>>;
51 std::same_as
<int*> auto result
= common
.operator->();
52 assert(result
== buffer
);
54 Common
const ccommon(iter
);
55 std::same_as
<int*> auto cresult
= ccommon
.operator->();
56 assert(cresult
== buffer
);
59 check
.operator()<simple_iterator
<int*>>();
60 check
.operator()<cpp17_input_iterator
<int*>>();
61 // cpp20_input_iterator can't be used with common_iterator because it's not copyable
62 check
.operator()<forward_iterator
<int*>>();
63 check
.operator()<bidirectional_iterator
<int*>>();
64 check
.operator()<random_access_iterator
<int*>>();
67 // Case 3: http://eel.is/c++draft/iterators.common#common.iter.access-5.3
69 auto check
= []<class Iterator
>() {
70 int buffer
[8] = {1, 2, 3, 4, 5, 6, 7, 8};
71 Iterator
iter(buffer
);
72 using Common
= std::common_iterator
<Iterator
, sentinel_type
<int*>>;
75 auto proxy
= common
.operator->();
76 std::same_as
<int const*> auto result
= proxy
.operator->();
77 assert(result
!= buffer
); // we copied to a temporary proxy
78 assert(*result
== *buffer
);
80 Common
const ccommon(iter
);
81 auto cproxy
= ccommon
.operator->();
82 std::same_as
<int const*> auto cresult
= cproxy
.operator->();
83 assert(cresult
!= buffer
); // we copied to a temporary proxy
84 assert(*cresult
== *buffer
);
87 check
.operator()<value_iterator
<int*>>();
88 check
.operator()<void_plus_plus_iterator
<int*>>();
92 int main(int, char**) {