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 //===----------------------------------------------------------------------===//
11 // template <class InputIterator>
12 // void assign(InputIterator f, InputIterator l);
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"
27 make(int size
, int start
= 0 )
29 const int b
= 4096 / sizeof(int);
33 init
= (start
+1) / b
+ ((start
+1) % b
!= 0);
38 for (int i
= 0; i
< init
-start
; ++i
)
40 for (int i
= 0; i
< size
; ++i
)
42 for (int i
= 0; i
< start
; ++i
)
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());
58 testN(int start
, int N
, int M
)
60 C c1
= make
<C
>(N
, start
);
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());
78 testNI(int start
, int N
, int M
)
80 C c1
= make
<C
>(N
, start
);
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);
109 void test_emplacable_concept() {
110 #if TEST_STD_VER >= 11
112 int arr2
[] = {1, 101, 42};
114 using T
= EmplaceConstructibleMoveableAndAssignable
<int>;
115 using It
= random_access_iterator
<int*>;
118 v
.assign(It(arr1
), It(std::end(arr1
)));
119 assert(v
[0].value
== 42);
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*>;
134 v
.assign(It(arr1
), It(std::end(arr1
)));
135 assert(v
[0].copied
== 0);
136 assert(v
[0].value
== 42);
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);
152 int main(int, char**) {
154 test_emplacable_concept();