Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / iterators / predef.iterators / iterators.common / eq.pass.cpp
blobae6115b682efdbb672772ba4a2340b93b8fa9833
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 // template<class I2, sentinel_for<I> S2>
12 // requires sentinel_for<S, I2>
13 // friend bool operator==(
14 // const common_iterator& x, const common_iterator<I2, S2>& y);
15 // template<class I2, sentinel_for<I> S2>
16 // requires sentinel_for<S, I2> && equality_comparable_with<I, I2>
17 // friend bool operator==(
18 // const common_iterator& x, const common_iterator<I2, S2>& y);
20 #include <iterator>
21 #include <cassert>
23 #include "test_macros.h"
24 #include "types.h"
26 void test() {
27 int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8};
30 auto iter1 = simple_iterator<int*>(buffer);
31 auto commonIter1 = std::common_iterator<decltype(iter1), sentinel_type<int*>>(iter1);
32 auto commonSent1 = std::common_iterator<decltype(iter1), sentinel_type<int*>>(sentinel_type<int*>{buffer + 8});
34 const auto commonIter2 = std::common_iterator<decltype(iter1), sentinel_type<int*>>(iter1);
35 const auto commonSent2 = std::common_iterator<decltype(iter1), sentinel_type<int*>>(sentinel_type<int*>{buffer + 8});
37 assert(commonIter1 != commonSent1);
38 assert(commonIter2 != commonSent2);
39 assert(commonSent1 != commonIter1);
40 assert(commonSent2 != commonIter2);
42 for (auto i = 1; commonIter1 != commonSent1; ++i) {
43 assert(*(commonIter1++) == i);
45 assert(commonIter1 == commonSent1);
46 assert(commonSent1 == commonIter1);
49 auto iter1 = value_iterator<int*>(buffer);
50 auto commonIter1 = std::common_iterator<decltype(iter1), sentinel_type<int*>>(iter1);
51 auto commonSent1 = std::common_iterator<decltype(iter1), sentinel_type<int*>>(sentinel_type<int*>{buffer + 8});
53 const auto commonIter2 = std::common_iterator<decltype(iter1), sentinel_type<int*>>(iter1);
54 const auto commonSent2 = std::common_iterator<decltype(iter1), sentinel_type<int*>>(sentinel_type<int*>{buffer + 8});
56 assert(commonIter1 != commonSent1);
57 assert(commonIter2 != commonSent2);
58 assert(commonSent1 != commonIter1);
59 assert(commonSent2 != commonIter2);
61 for (auto i = 1; commonIter1 != commonSent1; ++i) {
62 assert(*(commonIter1++) == i);
64 assert(commonIter1 == commonSent1);
65 assert(commonSent1 == commonIter1);
68 auto iter1 = simple_iterator<int*>(buffer);
69 auto iter2 = comparable_iterator<int*>(buffer);
70 auto commonIter1 = std::common_iterator<decltype(iter1), sentinel_type<int*>>(iter1);
71 auto commonSent1 = std::common_iterator<decltype(iter1), sentinel_type<int*>>(sentinel_type<int*>{buffer + 8});
73 const auto commonIter2 = std::common_iterator<decltype(iter2), sentinel_type<int*>>(iter2);
74 const auto commonSent2 = std::common_iterator<decltype(iter2), sentinel_type<int*>>(sentinel_type<int*>{buffer + 8});
76 assert(commonIter1 == commonIter2);
77 assert(commonSent1 != commonIter2);
78 assert(commonSent1 == commonSent2);
79 assert(commonSent2 == commonSent1);
81 assert(commonIter1 != commonSent1);
82 assert(commonIter2 != commonSent2);
83 assert(commonSent1 != commonIter1);
84 assert(commonSent2 != commonIter2);
86 assert(commonIter1 == commonIter2);
87 assert(commonIter2 == commonIter1);
89 for (auto i = 1; commonIter1 != commonSent1; ++i) {
90 assert(*(commonIter1++) == i);
92 assert(commonIter1 == commonSent1);
93 assert(commonSent1 == commonIter1);
95 // This check may *seem* incorrect (our iterators point to two completely different
96 // elements of buffer). However, this is actually what the Standard wants.
97 // See https://eel.is/c++draft/iterators.common#common.iter.cmp-2.
98 assert(commonIter1 == commonIter2);
101 auto iter1 = cpp17_input_iterator<int*>(buffer);
102 auto commonIter1 = std::common_iterator<decltype(iter1), sentinel_type<int*>>(iter1);
103 auto commonSent1 = std::common_iterator<decltype(iter1), sentinel_type<int*>>(sentinel_type<int*>{buffer + 8});
105 const auto commonIter2 = std::common_iterator<decltype(iter1), sentinel_type<int*>>(iter1);
106 const auto commonSent2 = std::common_iterator<decltype(iter1), sentinel_type<int*>>(sentinel_type<int*>{buffer + 8});
108 assert(commonIter1 != commonSent1);
109 assert(commonIter2 != commonSent2);
110 assert(commonSent1 != commonIter1);
111 assert(commonSent2 != commonIter2);
113 for (auto i = 1; commonIter1 != commonSent1; ++i) {
114 assert(*(commonIter1++) == i);
116 assert(commonIter1 == commonSent1);
117 assert(commonSent1 == commonIter1);
120 auto iter1 = forward_iterator<int*>(buffer);
121 auto commonIter1 = std::common_iterator<decltype(iter1), sentinel_type<int*>>(iter1);
122 auto commonSent1 = std::common_iterator<decltype(iter1), sentinel_type<int*>>(sentinel_type<int*>{buffer + 8});
124 const auto commonIter2 = std::common_iterator<decltype(iter1), sentinel_type<int*>>(iter1);
125 const auto commonSent2 = std::common_iterator<decltype(iter1), sentinel_type<int*>>(sentinel_type<int*>{buffer + 8});
127 assert(commonIter1 != commonSent1);
128 assert(commonIter2 != commonSent2);
129 assert(commonSent1 != commonIter1);
130 assert(commonSent2 != commonIter2);
132 for (auto i = 1; commonIter1 != commonSent1; ++i) {
133 assert(*(commonIter1++) == i);
135 assert(commonIter1 == commonSent1);
136 assert(commonSent1 == commonIter1);
139 auto iter1 = random_access_iterator<int*>(buffer);
140 auto commonIter1 = std::common_iterator<decltype(iter1), sentinel_type<int*>>(iter1);
141 auto commonSent1 = std::common_iterator<decltype(iter1), sentinel_type<int*>>(sentinel_type<int*>{buffer + 8});
143 const auto commonIter2 = std::common_iterator<decltype(iter1), sentinel_type<int*>>(iter1);
144 const auto commonSent2 = std::common_iterator<decltype(iter1), sentinel_type<int*>>(sentinel_type<int*>{buffer + 8});
146 assert(commonIter1 != commonSent1);
147 assert(commonIter2 != commonSent2);
148 assert(commonSent1 != commonIter1);
149 assert(commonSent2 != commonIter2);
151 assert(commonSent1 == commonSent2);
152 assert(commonSent2 == commonSent1);
154 for (auto i = 1; commonIter1 != commonSent1; ++i) {
155 assert(*(commonIter1++) == i);
157 assert(commonIter1 == commonSent1);
158 assert(commonSent1 == commonIter1);
162 int main(int, char**) {
163 test();
165 return 0;