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++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::deque
deq(std::begin(arr
), std::end(arr
));
40 static_assert(std::is_same_v
<decltype(deq
), std::deque
<int>>, "");
41 assert(std::equal(deq
.begin(), deq
.end(), std::begin(arr
), std::end(arr
)));
45 const long arr
[] = {INT_MAX
, 1L, 2L, 3L };
46 std::deque
deq(std::begin(arr
), std::end(arr
), std::allocator
<long>());
47 static_assert(std::is_same_v
<decltype(deq
)::value_type
, long>, "");
48 assert(deq
.size() == 4);
49 assert(deq
[0] == INT_MAX
);
54 // Test the implicit deduction guides
57 // We don't expect this one to work.
58 // std::deque deq(std::allocator<int>()); // deque (allocator &)
62 std::deque
deq(1, A
{}); // deque (size_type, T)
63 static_assert(std::is_same_v
<decltype(deq
)::value_type
, A
>, "");
64 static_assert(std::is_same_v
<decltype(deq
)::allocator_type
, std::allocator
<A
>>, "");
65 assert(deq
.size() == 1);
69 std::deque
deq(1, A
{}, test_allocator
<A
>()); // deque (size_type, T, allocator)
70 static_assert(std::is_same_v
<decltype(deq
)::value_type
, A
>, "");
71 static_assert(std::is_same_v
<decltype(deq
)::allocator_type
, test_allocator
<A
>>, "");
72 assert(deq
.size() == 1);
76 std::deque deq
{1U, 2U, 3U, 4U, 5U}; // deque(initializer-list)
77 static_assert(std::is_same_v
<decltype(deq
)::value_type
, unsigned>, "");
78 assert(deq
.size() == 5);
83 std::deque
deq({1.0, 2.0, 3.0, 4.0}, test_allocator
<double>()); // deque(initializer-list, allocator)
84 static_assert(std::is_same_v
<decltype(deq
)::value_type
, double>, "");
85 static_assert(std::is_same_v
<decltype(deq
)::allocator_type
, test_allocator
<double>>, "");
86 assert(deq
.size() == 4);
87 assert(deq
[3] == 4.0);
91 std::deque
<long double> source
;
92 std::deque
deq(source
); // deque(deque &)
93 static_assert(std::is_same_v
<decltype(deq
)::value_type
, long double>, "");
94 static_assert(std::is_same_v
<decltype(deq
)::allocator_type
, std::allocator
<long double>>, "");
95 assert(deq
.size() == 0);