[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / sequences / deque / deque.cons / assign_iter_iter.pass.cpp
blobd59943574f001ba3b709bfe85f6ff8ec08757d2c
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 // <deque>
11 // template <class InputIterator>
12 // void assign(InputIterator f, InputIterator l);
14 #include <deque>
15 #include <cassert>
16 #include <cstddef>
18 #include "test_macros.h"
19 #include "test_iterators.h"
20 #include "min_allocator.h"
21 #if TEST_STD_VER >= 11
22 #include "emplace_constructible.h"
23 #endif
25 template <class C>
27 make(int size, int start = 0 )
29 const int b = 4096 / sizeof(int);
30 int init = 0;
31 if (start > 0)
33 init = (start+1) / b + ((start+1) % b != 0);
34 init *= b;
35 --init;
37 C c(init, 0);
38 for (int i = 0; i < init-start; ++i)
39 c.pop_back();
40 for (int i = 0; i < size; ++i)
41 c.push_back(i);
42 for (int i = 0; i < start; ++i)
43 c.pop_front();
44 return c;
47 template <class C>
48 void
49 test(C& c1, const C& c2)
51 c1.assign(c2.begin(), c2.end());
52 assert(static_cast<std::size_t>(distance(c1.begin(), c1.end())) == c1.size());
53 assert(c1 == c2);
56 template <class C>
57 void
58 testN(int start, int N, int M)
60 C c1 = make<C>(N, start);
61 C c2 = make<C>(M);
62 test(c1, c2);
65 template <class C>
66 void
67 testI(C& c1, const C& c2)
69 typedef typename C::const_iterator CI;
70 typedef input_iterator<CI> ICI;
71 c1.assign(ICI(c2.begin()), ICI(c2.end()));
72 assert(static_cast<std::size_t>(distance(c1.begin(), c1.end())) == c1.size());
73 assert(c1 == c2);
76 template <class C>
77 void
78 testNI(int start, int N, int M)
80 C c1 = make<C>(N, start);
81 C c2 = make<C>(M);
82 testI(c1, c2);
85 void basic_test()
88 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
89 const int N = sizeof(rng)/sizeof(rng[0]);
90 for (int i = 0; i < N; ++i)
91 for (int j = 0; j < N; ++j)
92 for (int k = 0; k < N; ++k)
93 testN<std::deque<int> >(rng[i], rng[j], rng[k]);
94 testNI<std::deque<int> >(1500, 2000, 1000);
96 #if TEST_STD_VER >= 11
98 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
99 const int N = sizeof(rng)/sizeof(rng[0]);
100 for (int i = 0; i < N; ++i)
101 for (int j = 0; j < N; ++j)
102 for (int k = 0; k < N; ++k)
103 testN<std::deque<int, min_allocator<int>> >(rng[i], rng[j], rng[k]);
104 testNI<std::deque<int, min_allocator<int>> >(1500, 2000, 1000);
106 #endif
109 void test_emplacable_concept() {
110 #if TEST_STD_VER >= 11
111 int arr1[] = {42};
112 int arr2[] = {1, 101, 42};
114 using T = EmplaceConstructibleMoveableAndAssignable<int>;
115 using It = random_access_iterator<int*>;
117 std::deque<T> v;
118 v.assign(It(arr1), It(std::end(arr1)));
119 assert(v[0].value == 42);
122 std::deque<T> v;
123 v.assign(It(arr2), It(std::end(arr2)));
124 assert(v[0].value == 1);
125 assert(v[1].value == 101);
126 assert(v[2].value == 42);
130 using T = EmplaceConstructibleMoveableAndAssignable<int>;
131 using It = input_iterator<int*>;
133 std::deque<T> v;
134 v.assign(It(arr1), It(std::end(arr1)));
135 assert(v[0].copied == 0);
136 assert(v[0].value == 42);
139 std::deque<T> v;
140 v.assign(It(arr2), It(std::end(arr2)));
141 //assert(v[0].copied == 0);
142 assert(v[0].value == 1);
143 //assert(v[1].copied == 0);
144 assert(v[1].value == 101);
145 assert(v[2].copied == 0);
146 assert(v[2].value == 42);
149 #endif
152 int main(int, char**) {
153 basic_test();
154 test_emplacable_concept();
156 return 0;