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 //===----------------------------------------------------------------------===//
8
9 // <deque>
10
11 // template <class InputIterator> deque(InputIterator f, InputIterator l);
12
13 #include <deque>
14 #include <cassert>
15 #include <cstddef>
16
17 #include "test_macros.h"
18 #include "test_allocator.h"
19 #include "test_iterators.h"
20 #include "min_allocator.h"
21 #if TEST_STD_VER >= 11
22 #include "emplace_constructible.h"
23 #endif
24
25 template <class InputIterator>
26 void
test(InputIterator f,InputIterator l)27 test(InputIterator f, InputIterator l)
28 {
29 typedef typename std::iterator_traits<InputIterator>::value_type T;
30 typedef std::allocator<T> Allocator;
31 typedef std::deque<T, Allocator> C;
32 typedef typename C::const_iterator const_iterator;
33 C d(f, l);
34 assert(d.size() == static_cast<std::size_t>(std::distance(f, l)));
35 assert(static_cast<std::size_t>(distance(d.begin(), d.end())) == d.size());
36 for (const_iterator i = d.begin(), e = d.end(); i != e; ++i, ++f)
37 assert(*i == *f);
38 }
39
40 template <class Allocator, class InputIterator>
41 void
test(InputIterator f,InputIterator l)42 test(InputIterator f, InputIterator l)
43 {
44 typedef typename std::iterator_traits<InputIterator>::value_type T;
45 typedef std::deque<T, Allocator> C;
46 typedef typename C::const_iterator const_iterator;
47 C d(f, l);
48 assert(d.size() == static_cast<std::size_t>(std::distance(f, l)));
49 assert(static_cast<std::size_t>(distance(d.begin(), d.end())) == d.size());
50 for (const_iterator i = d.begin(), e = d.end(); i != e; ++i, ++f)
51 assert(*i == *f);
52 }
53
basic_test()54 void basic_test()
55 {
56 int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};
57 int* an = ab + sizeof(ab)/sizeof(ab[0]);
58 test(input_iterator<const int*>(ab), input_iterator<const int*>(an));
59 test(forward_iterator<const int*>(ab), forward_iterator<const int*>(an));
60 test(bidirectional_iterator<const int*>(ab), bidirectional_iterator<const int*>(an));
61 test(random_access_iterator<const int*>(ab), random_access_iterator<const int*>(an));
62 test<limited_allocator<int, 4096> >(ab, an);
63 #if TEST_STD_VER >= 11
64 test<min_allocator<int> >(ab, an);
65 #endif
66 }
67
68
test_emplacable_concept()69 void test_emplacable_concept() {
70 #if TEST_STD_VER >= 11
71 int arr1[] = {42};
72 int arr2[] = {1, 101, 42};
73 {
74 using T = EmplaceConstructibleAndMoveable<int>;
75 using It = random_access_iterator<int*>;
76 {
77 std::deque<T> v(It(arr1), It(std::end(arr1)));
78 assert(v[0].value == 42);
79 }
80 {
81 std::deque<T> v(It(arr2), It(std::end(arr2)));
82 assert(v[0].value == 1);
83 assert(v[1].value == 101);
84 assert(v[2].value == 42);
85 }
86 }
87 {
88 using T = EmplaceConstructibleAndMoveable<int>;
89 using It = input_iterator<int*>;
90 {
91 std::deque<T> v(It(arr1), It(std::end(arr1)));
92 assert(v[0].copied == 0);
93 assert(v[0].value == 42);
94 }
95 {
96 std::deque<T> v(It(arr2), It(std::end(arr2)));
97 //assert(v[0].copied == 0);
98 assert(v[0].value == 1);
99 //assert(v[1].copied == 0);
100 assert(v[1].value == 101);
101 assert(v[2].copied == 0);
102 assert(v[2].value == 42);
103 }
104 }
105 #endif
106 }
107
main(int,char **)108 int main(int, char**) {
109 basic_test();
110 test_emplacable_concept();
111
112 return 0;
113 }
114