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
12 // template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
13 // deque(InputIterator, InputIterator, Allocator = Allocator())
14 // -> deque<typename iterator_traits<InputIterator>::value_type, Allocator>;
16 // template<ranges::input_range R, class Allocator = allocator<ranges::range_value_t<R>>>
17 // deque(from_range_t, R&&, Allocator = Allocator())
18 // -> deque<ranges::range_value_t<R>, Allocator>; // C++23
20 #include "asan_testing.h"
23 #include <climits> // INT_MAX
28 #include "deduction_guides_sfinae_checks.h"
29 #include "test_macros.h"
30 #include "test_iterators.h"
31 #include "test_allocator.h"
38 // Test the explicit deduction guides
40 const int arr
[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
41 std::deque
deq(std::begin(arr
), std::end(arr
));
43 static_assert(std::is_same_v
<decltype(deq
), std::deque
<int>>, "");
44 assert(std::equal(deq
.begin(), deq
.end(), std::begin(arr
), std::end(arr
)));
45 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(deq
));
49 const long arr
[] = {INT_MAX
, 1L, 2L, 3L };
50 std::deque
deq(std::begin(arr
), std::end(arr
), std::allocator
<long>());
51 static_assert(std::is_same_v
<decltype(deq
)::value_type
, long>, "");
52 assert(deq
.size() == 4);
53 assert(deq
[0] == INT_MAX
);
56 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(deq
));
59 // Test the implicit deduction guides
62 // We don't expect this one to work.
63 // std::deque deq(std::allocator<int>()); // deque (allocator &)
67 std::deque
deq(1, A
{}); // deque (size_type, T)
68 static_assert(std::is_same_v
<decltype(deq
)::value_type
, A
>, "");
69 static_assert(std::is_same_v
<decltype(deq
)::allocator_type
, std::allocator
<A
>>, "");
70 assert(deq
.size() == 1);
71 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(deq
));
75 std::deque
deq(1, A
{}, test_allocator
<A
>()); // deque (size_type, T, allocator)
76 static_assert(std::is_same_v
<decltype(deq
)::value_type
, A
>, "");
77 static_assert(std::is_same_v
<decltype(deq
)::allocator_type
, test_allocator
<A
>>, "");
78 assert(deq
.size() == 1);
79 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(deq
));
83 std::deque deq
{1U, 2U, 3U, 4U, 5U}; // deque(initializer-list)
84 static_assert(std::is_same_v
<decltype(deq
)::value_type
, unsigned>, "");
85 assert(deq
.size() == 5);
87 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(deq
));
91 std::deque
deq({1.0, 2.0, 3.0, 4.0}, test_allocator
<double>()); // deque(initializer-list, allocator)
92 static_assert(std::is_same_v
<decltype(deq
)::value_type
, double>, "");
93 static_assert(std::is_same_v
<decltype(deq
)::allocator_type
, test_allocator
<double>>, "");
94 assert(deq
.size() == 4);
95 assert(deq
[3] == 4.0);
96 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(deq
));
100 std::deque
<long double> source
;
101 std::deque
deq(source
); // deque(deque &)
102 static_assert(std::is_same_v
<decltype(deq
)::value_type
, long double>, "");
103 static_assert(std::is_same_v
<decltype(deq
)::allocator_type
, std::allocator
<long double>>, "");
104 assert(deq
.size() == 0);
105 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(deq
));
109 typedef test_allocator
<short> Alloc
;
110 typedef test_allocator
<int> ConvertibleToAlloc
;
113 std::deque
<short, Alloc
> source
;
114 std::deque
deq(source
, Alloc(2));
115 static_assert(std::is_same_v
<decltype(deq
), decltype(source
)>);
116 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(deq
));
117 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(source
));
121 std::deque
<short, Alloc
> source
;
122 std::deque
deq(source
, ConvertibleToAlloc(2));
123 static_assert(std::is_same_v
<decltype(deq
), decltype(source
)>);
124 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(deq
));
125 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(source
));
129 std::deque
<short, Alloc
> source
;
130 std::deque
deq(std::move(source
), Alloc(2));
131 static_assert(std::is_same_v
<decltype(deq
), decltype(source
)>);
132 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(deq
));
133 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(source
));
137 std::deque
<short, Alloc
> source
;
138 std::deque
deq(std::move(source
), ConvertibleToAlloc(2));
139 static_assert(std::is_same_v
<decltype(deq
), decltype(source
)>);
140 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(deq
));
141 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(source
));
145 #if TEST_STD_VER >= 23
148 std::deque
c(std::from_range
, std::array
<int, 0>());
149 static_assert(std::is_same_v
<decltype(c
), std::deque
<int>>);
153 using Alloc
= test_allocator
<int>;
154 std::deque
c(std::from_range
, std::array
<int, 0>(), Alloc());
155 static_assert(std::is_same_v
<decltype(c
), std::deque
<int, Alloc
>>);
160 SequenceContainerDeductionGuidesSfinaeAway
<std::deque
, std::deque
<int>>();