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 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: c++98, c++03, c++11, c++14
11 // UNSUPPORTED: libcpp-no-deduction-guides
14 // template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
15 // deque(InputIterator, InputIterator, Allocator = Allocator())
16 // -> deque<typename iterator_traits<InputIterator>::value_type, Allocator>;
24 #include <climits> // INT_MAX
26 #include "test_macros.h"
27 #include "test_iterators.h"
28 #include "test_allocator.h"
35 // Test the explicit deduction guides
37 const int arr
[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
38 std::vector
vec(std::begin(arr
), std::end(arr
));
40 static_assert(std::is_same_v
<decltype(vec
), std::vector
<int>>, "");
41 assert(std::equal(vec
.begin(), vec
.end(), std::begin(arr
), std::end(arr
)));
45 const long arr
[] = {INT_MAX
, 1L, 2L, 3L };
46 std::vector
vec(std::begin(arr
), std::end(arr
), std::allocator
<long>());
47 static_assert(std::is_same_v
<decltype(vec
)::value_type
, long>, "");
48 assert(vec
.size() == 4);
49 assert(vec
[0] == INT_MAX
);
54 // Test the implicit deduction guides
57 // We don't expect this one to work.
58 // std::vector vec(std::allocator<int>()); // vector (allocator &)
62 std::vector
vec(1, A
{}); // vector (size_type, T)
63 static_assert(std::is_same_v
<decltype(vec
)::value_type
, A
>, "");
64 static_assert(std::is_same_v
<decltype(vec
)::allocator_type
, std::allocator
<A
>>, "");
65 assert(vec
.size() == 1);
69 std::vector
vec(1, A
{}, test_allocator
<A
>()); // vector (size_type, T, allocator)
70 static_assert(std::is_same_v
<decltype(vec
)::value_type
, A
>, "");
71 static_assert(std::is_same_v
<decltype(vec
)::allocator_type
, test_allocator
<A
>>, "");
72 assert(vec
.size() == 1);
76 std::vector vec
{1U, 2U, 3U, 4U, 5U}; // vector(initializer-list)
77 static_assert(std::is_same_v
<decltype(vec
)::value_type
, unsigned>, "");
78 assert(vec
.size() == 5);
83 std::vector
vec({1.0, 2.0, 3.0, 4.0}, test_allocator
<double>()); // vector(initializer-list, allocator)
84 static_assert(std::is_same_v
<decltype(vec
)::value_type
, double>, "");
85 static_assert(std::is_same_v
<decltype(vec
)::allocator_type
, test_allocator
<double>>, "");
86 assert(vec
.size() == 4);
87 assert(vec
[3] == 4.0);
91 std::vector
<long double> source
;
92 std::vector
vec(source
); // vector(vector &)
93 static_assert(std::is_same_v
<decltype(vec
)::value_type
, long double>, "");
94 static_assert(std::is_same_v
<decltype(vec
)::allocator_type
, std::allocator
<long double>>, "");
95 assert(vec
.size() == 0);
99 // A couple of vector<bool> tests, too!
101 std::vector
vec(3, true); // vector(initializer-list)
102 static_assert(std::is_same_v
<decltype(vec
)::value_type
, bool>, "");
103 static_assert(std::is_same_v
<decltype(vec
)::allocator_type
, std::allocator
<bool>>, "");
104 assert(vec
.size() == 3);
105 assert(vec
[0] && vec
[1] && vec
[2]);
109 std::vector
<bool> source
;
110 std::vector
vec(source
); // vector(vector &)
111 static_assert(std::is_same_v
<decltype(vec
)::value_type
, bool>, "");
112 static_assert(std::is_same_v
<decltype(vec
)::allocator_type
, std::allocator
<bool>>, "");
113 assert(vec
.size() == 0);