15b8b8b5dSMarshall Clow //===----------------------------------------------------------------------===//
25b8b8b5dSMarshall Clow //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65b8b8b5dSMarshall Clow //
75b8b8b5dSMarshall Clow //===----------------------------------------------------------------------===//
85b8b8b5dSMarshall Clow
95b8b8b5dSMarshall Clow // <queue>
1031cbe0f2SLouis Dionne // UNSUPPORTED: c++03, c++11, c++14
115b8b8b5dSMarshall Clow
125b8b8b5dSMarshall Clow // template<class Container>
135b8b8b5dSMarshall Clow // queue(Container) -> queue<typename Container::value_type, Container>;
145b8b8b5dSMarshall Clow //
155b8b8b5dSMarshall Clow // template<class Container, class Allocator>
165b8b8b5dSMarshall Clow // queue(Container, Allocator) -> queue<typename Container::value_type, Container>;
175b8b8b5dSMarshall Clow
185b8b8b5dSMarshall Clow
19*f3aed369SNikolas Klauser #include <array>
205b8b8b5dSMarshall Clow #include <queue>
215b8b8b5dSMarshall Clow #include <list>
225b8b8b5dSMarshall Clow #include <iterator>
235b8b8b5dSMarshall Clow #include <cassert>
245b8b8b5dSMarshall Clow #include <cstddef>
255b8b8b5dSMarshall Clow
2668072a71SKonstantin Varlamov #include "deduction_guides_sfinae_checks.h"
275b8b8b5dSMarshall Clow #include "test_macros.h"
285b8b8b5dSMarshall Clow #include "test_iterators.h"
295b8b8b5dSMarshall Clow #include "test_allocator.h"
305b8b8b5dSMarshall Clow
315b8b8b5dSMarshall Clow struct A {};
325b8b8b5dSMarshall Clow
main(int,char **)332df59c50SJF Bastien int main(int, char**)
345b8b8b5dSMarshall Clow {
355b8b8b5dSMarshall Clow
365b8b8b5dSMarshall Clow // Test the explicit deduction guides
375b8b8b5dSMarshall Clow {
385b8b8b5dSMarshall Clow std::list<int> l{0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
395b8b8b5dSMarshall Clow std::queue que(l);
405b8b8b5dSMarshall Clow
415b8b8b5dSMarshall Clow static_assert(std::is_same_v<decltype(que), std::queue<int, std::list<int>>>, "");
425b8b8b5dSMarshall Clow assert(que.size() == l.size());
435b8b8b5dSMarshall Clow assert(que.back() == l.back());
445b8b8b5dSMarshall Clow }
455b8b8b5dSMarshall Clow
465b8b8b5dSMarshall Clow {
475b8b8b5dSMarshall Clow std::list<long, test_allocator<long>> l{10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
485b8b8b5dSMarshall Clow std::queue que(l, test_allocator<long>(0,2)); // different allocator
495b8b8b5dSMarshall Clow static_assert(std::is_same_v<decltype(que)::container_type, std::list<long, test_allocator<long>>>, "");
505b8b8b5dSMarshall Clow static_assert(std::is_same_v<decltype(que)::value_type, long>, "");
515b8b8b5dSMarshall Clow assert(que.size() == 10);
525b8b8b5dSMarshall Clow assert(que.back() == 19);
535b8b8b5dSMarshall Clow // I'd like to assert that we've gotten the right allocator in the queue, but
545b8b8b5dSMarshall Clow // I don't know how to get at the underlying container.
555b8b8b5dSMarshall Clow }
565b8b8b5dSMarshall Clow
575b8b8b5dSMarshall Clow // Test the implicit deduction guides
585b8b8b5dSMarshall Clow {
595b8b8b5dSMarshall Clow // We don't expect this one to work - no way to implicitly get value_type
605b8b8b5dSMarshall Clow // std::queue que(std::allocator<int>()); // queue (allocator &)
615b8b8b5dSMarshall Clow }
625b8b8b5dSMarshall Clow
635b8b8b5dSMarshall Clow {
645b8b8b5dSMarshall Clow std::queue<A> source;
655b8b8b5dSMarshall Clow std::queue que(source); // queue(queue &)
665b8b8b5dSMarshall Clow static_assert(std::is_same_v<decltype(que)::value_type, A>, "");
675b8b8b5dSMarshall Clow static_assert(std::is_same_v<decltype(que)::container_type, std::deque<A>>, "");
685b8b8b5dSMarshall Clow assert(que.size() == 0);
695b8b8b5dSMarshall Clow }
705b8b8b5dSMarshall Clow
715b8b8b5dSMarshall Clow {
725b8b8b5dSMarshall Clow typedef short T;
73c479e0c9SLouis Dionne typedef test_allocator<T> Alloc;
74dd15c272SArthur O'Dwyer typedef std::list<T, Alloc> Cont;
75dd15c272SArthur O'Dwyer typedef test_allocator<int> ConvertibleToAlloc;
76dd15c272SArthur O'Dwyer static_assert(std::uses_allocator_v<Cont, ConvertibleToAlloc> &&
77dd15c272SArthur O'Dwyer !std::is_same_v<typename Cont::allocator_type, ConvertibleToAlloc>);
785b8b8b5dSMarshall Clow
79dd15c272SArthur O'Dwyer {
80dd15c272SArthur O'Dwyer Cont cont;
81dd15c272SArthur O'Dwyer std::queue que(cont, Alloc(2));
82dd15c272SArthur O'Dwyer static_assert(std::is_same_v<decltype(que), std::queue<T, Cont>>);
835b8b8b5dSMarshall Clow }
845b8b8b5dSMarshall Clow
85dd15c272SArthur O'Dwyer {
86dd15c272SArthur O'Dwyer Cont cont;
87dd15c272SArthur O'Dwyer std::queue que(cont, ConvertibleToAlloc(2));
88dd15c272SArthur O'Dwyer static_assert(std::is_same_v<decltype(que), std::queue<T, Cont>>);
89dd15c272SArthur O'Dwyer }
90dd15c272SArthur O'Dwyer
91dd15c272SArthur O'Dwyer {
92dd15c272SArthur O'Dwyer Cont cont;
93dd15c272SArthur O'Dwyer std::queue que(std::move(cont), Alloc(2));
94dd15c272SArthur O'Dwyer static_assert(std::is_same_v<decltype(que), std::queue<T, Cont>>);
95dd15c272SArthur O'Dwyer }
96dd15c272SArthur O'Dwyer
97dd15c272SArthur O'Dwyer {
98dd15c272SArthur O'Dwyer Cont cont;
99dd15c272SArthur O'Dwyer std::queue que(std::move(cont), ConvertibleToAlloc(2));
100dd15c272SArthur O'Dwyer static_assert(std::is_same_v<decltype(que), std::queue<T, Cont>>);
101dd15c272SArthur O'Dwyer }
102dd15c272SArthur O'Dwyer }
103dd15c272SArthur O'Dwyer
104dd15c272SArthur O'Dwyer {
105dd15c272SArthur O'Dwyer typedef short T;
106dd15c272SArthur O'Dwyer typedef test_allocator<T> Alloc;
107dd15c272SArthur O'Dwyer typedef std::list<T, Alloc> Cont;
108dd15c272SArthur O'Dwyer typedef test_allocator<int> ConvertibleToAlloc;
109dd15c272SArthur O'Dwyer static_assert(std::uses_allocator_v<Cont, ConvertibleToAlloc> &&
110dd15c272SArthur O'Dwyer !std::is_same_v<typename Cont::allocator_type, ConvertibleToAlloc>);
111dd15c272SArthur O'Dwyer
112dd15c272SArthur O'Dwyer {
113dd15c272SArthur O'Dwyer std::queue<T, Cont> source;
114dd15c272SArthur O'Dwyer std::queue que(source, Alloc(2));
115dd15c272SArthur O'Dwyer static_assert(std::is_same_v<decltype(que), std::queue<T, Cont>>);
116dd15c272SArthur O'Dwyer }
117dd15c272SArthur O'Dwyer
118dd15c272SArthur O'Dwyer {
119dd15c272SArthur O'Dwyer std::queue<T, Cont> source;
120dd15c272SArthur O'Dwyer std::queue que(source, ConvertibleToAlloc(2));
121dd15c272SArthur O'Dwyer static_assert(std::is_same_v<decltype(que), std::queue<T, Cont>>);
122dd15c272SArthur O'Dwyer }
123dd15c272SArthur O'Dwyer
124dd15c272SArthur O'Dwyer {
125dd15c272SArthur O'Dwyer std::queue<T, Cont> source;
126dd15c272SArthur O'Dwyer std::queue que(std::move(source), Alloc(2));
127dd15c272SArthur O'Dwyer static_assert(std::is_same_v<decltype(que), std::queue<T, Cont>>);
128dd15c272SArthur O'Dwyer }
129dd15c272SArthur O'Dwyer
130dd15c272SArthur O'Dwyer {
131dd15c272SArthur O'Dwyer std::queue<T, Cont> source;
132dd15c272SArthur O'Dwyer std::queue que(std::move(source), ConvertibleToAlloc(2));
133dd15c272SArthur O'Dwyer static_assert(std::is_same_v<decltype(que), std::queue<T, Cont>>);
134dd15c272SArthur O'Dwyer }
135dd15c272SArthur O'Dwyer }
1362df59c50SJF Bastien
13768072a71SKonstantin Varlamov // Deduction guides should be SFINAE'd away when given:
13868072a71SKonstantin Varlamov // - a "bad" allocator (that is, a type not qualifying as an allocator);
13968072a71SKonstantin Varlamov // - an allocator instead of a container;
14068072a71SKonstantin Varlamov // - an allocator and a container that uses a different allocator.
14168072a71SKonstantin Varlamov {
14268072a71SKonstantin Varlamov using Cont = std::list<int>;
14368072a71SKonstantin Varlamov using Alloc = std::allocator<int>;
14468072a71SKonstantin Varlamov using DiffAlloc = test_allocator<int>;
145*f3aed369SNikolas Klauser using Iter = int*;
14668072a71SKonstantin Varlamov
147*f3aed369SNikolas Klauser struct NotIter{};
148*f3aed369SNikolas Klauser struct NotAlloc {};
14968072a71SKonstantin Varlamov
150*f3aed369SNikolas Klauser static_assert(SFINAEs_away<std::queue, Alloc, NotAlloc>);
151*f3aed369SNikolas Klauser static_assert(SFINAEs_away<std::queue, Cont, NotAlloc>);
15268072a71SKonstantin Varlamov static_assert(SFINAEs_away<std::queue, Cont, DiffAlloc>);
153*f3aed369SNikolas Klauser static_assert(SFINAEs_away<std::queue, Iter, NotIter>);
154*f3aed369SNikolas Klauser #if TEST_STD_VER > 20
155*f3aed369SNikolas Klauser static_assert(SFINAEs_away<std::queue, Iter, NotIter, Alloc>);
156*f3aed369SNikolas Klauser static_assert(SFINAEs_away<std::queue, Iter, Iter, NotAlloc>);
157*f3aed369SNikolas Klauser #endif
15868072a71SKonstantin Varlamov }
159*f3aed369SNikolas Klauser #if TEST_STD_VER > 20
160*f3aed369SNikolas Klauser {
161*f3aed369SNikolas Klauser typedef short T;
162*f3aed369SNikolas Klauser typedef test_allocator<T> Alloc;
163*f3aed369SNikolas Klauser std::list<T> a;
164*f3aed369SNikolas Klauser {
165*f3aed369SNikolas Klauser std::queue q(a.begin(), a.end());
166*f3aed369SNikolas Klauser static_assert(std::is_same_v<decltype(q), std::queue<T>>);
167*f3aed369SNikolas Klauser }
168*f3aed369SNikolas Klauser {
169*f3aed369SNikolas Klauser std::queue q(a.begin(), a.end(), Alloc());
170*f3aed369SNikolas Klauser static_assert(std::is_same_v<decltype(q), std::queue<T, std::deque<T, Alloc>>>);
171*f3aed369SNikolas Klauser }
172*f3aed369SNikolas Klauser }
173*f3aed369SNikolas Klauser #endif
1742df59c50SJF Bastien return 0;
1755b8b8b5dSMarshall Clow }
176