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