[X86] Use NSW/NUW flags on ISD::TRUNCATE nodes to improve X86 PACKSS/PACKUS lowering...
[llvm-project.git] / libcxx / test / std / iterators / predef.iterators / iterators.common / arrow.pass.cpp
blobee7628b3e4dbb694d8ffadb79a8f6f1d6920cc35
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // auto operator->() const
12 // requires see below;
14 #include <iterator>
15 #include <cassert>
16 #include <concepts>
18 #include "test_iterators.h"
19 #include "test_macros.h"
20 #include "types.h"
22 void test() {
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>>;
30 Common common(iter);
31 std::same_as<Iterator> decltype(auto) result = common.operator->();
32 assert(base(result) == buffer);
34 Common const ccommon(iter);
35 std::same_as<Iterator> decltype(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*>>;
50 Common common(iter);
51 std::same_as<int*> decltype(auto) result = common.operator->();
52 assert(result == buffer);
54 Common const ccommon(iter);
55 std::same_as<int*> decltype(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*>>;
74 Common common(iter);
75 auto proxy = common.operator->();
76 std::same_as<int const*> decltype(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*> decltype(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**) {
93 test();
95 return 0;