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 Container>
13 // queue(Container) -> queue<typename Container::value_type, Container>;
15 // template<class Container, class Allocator>
16 // queue(Container, Allocator) -> queue<typename Container::value_type, Container>;
18 // template<ranges::input_range R>
19 // queue(from_range_t, R&&) -> queue<ranges::range_value_t<R>>; // since C++23
21 // template<ranges::input_range R, class Allocator>
22 // queue(from_range_t, R&&, Allocator)
23 // -> queue<ranges::range_value_t<R>, deque<ranges::range_value_t<R>, Allocator>>; // since C++23
32 #include "deduction_guides_sfinae_checks.h"
33 #include "test_macros.h"
34 #include "test_iterators.h"
35 #include "test_allocator.h"
42 // Test the explicit deduction guides
44 std::list
<int> l
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
47 static_assert(std::is_same_v
<decltype(que
), std::queue
<int, std::list
<int>>>, "");
48 assert(que
.size() == l
.size());
49 assert(que
.back() == l
.back());
53 std::list
<long, test_allocator
<long>> l
{10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
54 std::queue
que(l
, test_allocator
<long>(0,2)); // different allocator
55 static_assert(std::is_same_v
<decltype(que
)::container_type
, std::list
<long, test_allocator
<long>>>, "");
56 static_assert(std::is_same_v
<decltype(que
)::value_type
, long>, "");
57 assert(que
.size() == 10);
58 assert(que
.back() == 19);
59 // I'd like to assert that we've gotten the right allocator in the queue, but
60 // I don't know how to get at the underlying container.
63 // Test the implicit deduction guides
65 // We don't expect this one to work - no way to implicitly get value_type
66 // std::queue que(std::allocator<int>()); // queue (allocator &)
71 std::queue
que(source
); // queue(queue &)
72 static_assert(std::is_same_v
<decltype(que
)::value_type
, A
>, "");
73 static_assert(std::is_same_v
<decltype(que
)::container_type
, std::deque
<A
>>, "");
74 assert(que
.size() == 0);
79 typedef test_allocator
<T
> Alloc
;
80 typedef std::list
<T
, Alloc
> Cont
;
81 typedef test_allocator
<int> ConvertibleToAlloc
;
82 static_assert(std::uses_allocator_v
<Cont
, ConvertibleToAlloc
> &&
83 !std::is_same_v
<typename
Cont::allocator_type
, ConvertibleToAlloc
>);
87 std::queue
que(cont
, Alloc(2));
88 static_assert(std::is_same_v
<decltype(que
), std::queue
<T
, Cont
>>);
93 std::queue
que(cont
, ConvertibleToAlloc(2));
94 static_assert(std::is_same_v
<decltype(que
), std::queue
<T
, Cont
>>);
99 std::queue
que(std::move(cont
), Alloc(2));
100 static_assert(std::is_same_v
<decltype(que
), std::queue
<T
, Cont
>>);
105 std::queue
que(std::move(cont
), ConvertibleToAlloc(2));
106 static_assert(std::is_same_v
<decltype(que
), std::queue
<T
, Cont
>>);
112 typedef test_allocator
<T
> Alloc
;
113 typedef std::list
<T
, Alloc
> Cont
;
114 typedef test_allocator
<int> ConvertibleToAlloc
;
115 static_assert(std::uses_allocator_v
<Cont
, ConvertibleToAlloc
> &&
116 !std::is_same_v
<typename
Cont::allocator_type
, ConvertibleToAlloc
>);
119 std::queue
<T
, Cont
> source
;
120 std::queue
que(source
, Alloc(2));
121 static_assert(std::is_same_v
<decltype(que
), std::queue
<T
, Cont
>>);
125 std::queue
<T
, Cont
> source
;
126 std::queue
que(source
, ConvertibleToAlloc(2));
127 static_assert(std::is_same_v
<decltype(que
), std::queue
<T
, Cont
>>);
131 std::queue
<T
, Cont
> source
;
132 std::queue
que(std::move(source
), Alloc(2));
133 static_assert(std::is_same_v
<decltype(que
), std::queue
<T
, Cont
>>);
137 std::queue
<T
, Cont
> source
;
138 std::queue
que(std::move(source
), ConvertibleToAlloc(2));
139 static_assert(std::is_same_v
<decltype(que
), std::queue
<T
, Cont
>>);
143 #if TEST_STD_VER >= 23
146 typedef test_allocator
<T
> Alloc
;
149 std::queue
q(a
.begin(), a
.end());
150 static_assert(std::is_same_v
<decltype(q
), std::queue
<T
>>);
153 std::queue
q(a
.begin(), a
.end(), Alloc());
154 static_assert(std::is_same_v
<decltype(q
), std::queue
<T
, std::deque
<T
, Alloc
>>>);
160 std::queue
c(std::from_range
, std::array
<int, 0>());
161 static_assert(std::is_same_v
<decltype(c
), std::queue
<int>>);
165 using Alloc
= test_allocator
<int>;
166 std::queue
c(std::from_range
, std::array
<int, 0>(), Alloc());
167 static_assert(std::is_same_v
<decltype(c
), std::queue
<int, std::deque
<int, Alloc
>>>);
172 ContainerAdaptorDeductionGuidesSfinaeAway
<std::queue
, std::queue
<int>>();