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 // <array>
11 // UNSUPPORTED: c++98, c++03, c++11, c++14
12 // UNSUPPORTED: libcpp-no-deduction-guides
13
14
15 // template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
16 // deque(InputIterator, InputIterator, Allocator = Allocator())
17 // -> deque<typename iterator_traits<InputIterator>::value_type, Allocator>;
18 //
19
20
21 #include <deque>
22 #include <iterator>
23 #include <cassert>
24 #include <cstddef>
25 #include <climits> // INT_MAX
26
27 #include "test_macros.h"
28 #include "test_iterators.h"
29 #include "test_allocator.h"
30
31 struct A {};
32
main()33 int main()
34 {
35
36 // Test the explicit deduction guides
37 {
38 const int arr[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
39 std::deque deq(std::begin(arr), std::end(arr));
40
41 static_assert(std::is_same_v<decltype(deq), std::deque<int>>, "");
42 assert(std::equal(deq.begin(), deq.end(), std::begin(arr), std::end(arr)));
43 }
44
45 {
46 const long arr[] = {INT_MAX, 1L, 2L, 3L };
47 std::deque deq(std::begin(arr), std::end(arr), std::allocator<long>());
48 static_assert(std::is_same_v<decltype(deq)::value_type, long>, "");
49 assert(deq.size() == 4);
50 assert(deq[0] == INT_MAX);
51 assert(deq[1] == 1L);
52 assert(deq[2] == 2L);
53 }
54
55 // Test the implicit deduction guides
56
57 {
58 // We don't expect this one to work.
59 // std::deque deq(std::allocator<int>()); // deque (allocator &)
60 }
61
62 {
63 std::deque deq(1, A{}); // deque (size_type, T)
64 static_assert(std::is_same_v<decltype(deq)::value_type, A>, "");
65 static_assert(std::is_same_v<decltype(deq)::allocator_type, std::allocator<A>>, "");
66 assert(deq.size() == 1);
67 }
68
69 {
70 std::deque deq(1, A{}, test_allocator<A>()); // deque (size_type, T, allocator)
71 static_assert(std::is_same_v<decltype(deq)::value_type, A>, "");
72 static_assert(std::is_same_v<decltype(deq)::allocator_type, test_allocator<A>>, "");
73 assert(deq.size() == 1);
74 }
75
76 {
77 std::deque deq{1U, 2U, 3U, 4U, 5U}; // deque(initializer-list)
78 static_assert(std::is_same_v<decltype(deq)::value_type, unsigned>, "");
79 assert(deq.size() == 5);
80 assert(deq[2] == 3U);
81 }
82
83 {
84 std::deque deq({1.0, 2.0, 3.0, 4.0}, test_allocator<double>()); // deque(initializer-list, allocator)
85 static_assert(std::is_same_v<decltype(deq)::value_type, double>, "");
86 static_assert(std::is_same_v<decltype(deq)::allocator_type, test_allocator<double>>, "");
87 assert(deq.size() == 4);
88 assert(deq[3] == 4.0);
89 }
90
91 {
92 std::deque<long double> source;
93 std::deque deq(source); // deque(deque &)
94 static_assert(std::is_same_v<decltype(deq)::value_type, long double>, "");
95 static_assert(std::is_same_v<decltype(deq)::allocator_type, std::allocator<long double>>, "");
96 assert(deq.size() == 0);
97 }
98 }
99