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 // deque(InputIterator f, InputIterator l, const allocator_type& a);
18 #include "test_macros.h"
19 #include "test_iterators.h"
20 #include "test_allocator.h"
21 #include "min_allocator.h"
22 #if TEST_STD_VER >= 11
23 #include "emplace_constructible.h"
26 template <class InputIterator
, class Allocator
>
28 test(InputIterator f
, InputIterator l
, const Allocator
& a
)
30 typedef typename
std::iterator_traits
<InputIterator
>::value_type T
;
31 typedef std::deque
<T
, Allocator
> C
;
32 typedef typename
C::const_iterator const_iterator
;
34 assert(d
.get_allocator() == a
);
35 assert(d
.size() == static_cast<std::size_t>(std::distance(f
, l
)));
36 assert(static_cast<std::size_t>(distance(d
.begin(), d
.end())) == d
.size());
37 for (const_iterator i
= d
.begin(), e
= d
.end(); i
!= e
; ++i
, ++f
)
43 int ab
[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};
44 int* an
= ab
+ sizeof(ab
)/sizeof(ab
[0]);
45 test(input_iterator
<const int*>(ab
), input_iterator
<const int*>(an
), test_allocator
<int>(3));
46 test(forward_iterator
<const int*>(ab
), forward_iterator
<const int*>(an
), test_allocator
<int>(4));
47 test(bidirectional_iterator
<const int*>(ab
), bidirectional_iterator
<const int*>(an
), test_allocator
<int>(5));
48 test(random_access_iterator
<const int*>(ab
), random_access_iterator
<const int*>(an
), test_allocator
<int>(6));
49 #if TEST_STD_VER >= 11
50 test(input_iterator
<const int*>(ab
), input_iterator
<const int*>(an
), min_allocator
<int>());
51 test(forward_iterator
<const int*>(ab
), forward_iterator
<const int*>(an
), min_allocator
<int>());
52 test(bidirectional_iterator
<const int*>(ab
), bidirectional_iterator
<const int*>(an
), min_allocator
<int>());
53 test(random_access_iterator
<const int*>(ab
), random_access_iterator
<const int*>(an
), min_allocator
<int>());
58 void test_emplacable_concept() {
59 #if TEST_STD_VER >= 11
61 int arr2
[] = {1, 101, 42};
63 using T
= EmplaceConstructibleAndMoveable
<int>;
64 using It
= random_access_iterator
<int*>;
67 std::deque
<T
> v(It(arr1
), It(std::end(arr1
)), a
);
68 assert(v
[0].value
== 42);
71 std::deque
<T
> v(It(arr2
), It(std::end(arr2
)), a
);
72 assert(v
[0].value
== 1);
73 assert(v
[1].value
== 101);
74 assert(v
[2].value
== 42);
78 using T
= EmplaceConstructibleAndMoveable
<int>;
79 using It
= input_iterator
<int*>;
82 std::deque
<T
> v(It(arr1
), It(std::end(arr1
)), a
);
83 assert(v
[0].copied
== 0);
84 assert(v
[0].value
== 42);
87 std::deque
<T
> v(It(arr2
), It(std::end(arr2
)), a
);
88 //assert(v[0].copied == 0);
89 assert(v
[0].value
== 1);
90 //assert(v[1].copied == 0);
91 assert(v
[1].value
== 101);
92 assert(v
[2].copied
== 0);
93 assert(v
[2].value
== 42);
99 int main(int, char**) {
101 test_emplacable_concept();