1 //===----------------------------------------------------------------------===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 9 // <queue> 10 // UNSUPPORTED: c++03, c++11, c++14 11 12 // template<class Container> 13 // queue(Container) -> queue<typename Container::value_type, Container>; 14 // 15 // template<class Container, class Allocator> 16 // queue(Container, Allocator) -> queue<typename Container::value_type, Container>; 17 18 19 #include <queue> 20 #include <list> 21 #include <iterator> 22 #include <cassert> 23 #include <cstddef> 24 #include <climits> // INT_MAX 25 26 #include "test_macros.h" 27 #include "test_iterators.h" 28 #include "test_allocator.h" 29 30 struct A {}; 31 32 int main(int, char**) 33 { 34 35 // Test the explicit deduction guides 36 { 37 std::list<int> l{0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; 38 std::queue que(l); 39 40 static_assert(std::is_same_v<decltype(que), std::queue<int, std::list<int>>>, ""); 41 assert(que.size() == l.size()); 42 assert(que.back() == l.back()); 43 } 44 45 { 46 std::list<long, test_allocator<long>> l{10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; 47 std::queue que(l, test_allocator<long>(0,2)); // different allocator 48 static_assert(std::is_same_v<decltype(que)::container_type, std::list<long, test_allocator<long>>>, ""); 49 static_assert(std::is_same_v<decltype(que)::value_type, long>, ""); 50 assert(que.size() == 10); 51 assert(que.back() == 19); 52 // I'd like to assert that we've gotten the right allocator in the queue, but 53 // I don't know how to get at the underlying container. 54 } 55 56 // Test the implicit deduction guides 57 { 58 // We don't expect this one to work - no way to implicitly get value_type 59 // std::queue que(std::allocator<int>()); // queue (allocator &) 60 } 61 62 { 63 std::queue<A> source; 64 std::queue que(source); // queue(queue &) 65 static_assert(std::is_same_v<decltype(que)::value_type, A>, ""); 66 static_assert(std::is_same_v<decltype(que)::container_type, std::deque<A>>, ""); 67 assert(que.size() == 0); 68 } 69 70 { 71 typedef short T; 72 typedef test_allocator<T> Alloc; 73 typedef std::list<T, Alloc> Cont; 74 typedef test_allocator<int> ConvertibleToAlloc; 75 static_assert(std::uses_allocator_v<Cont, ConvertibleToAlloc> && 76 !std::is_same_v<typename Cont::allocator_type, ConvertibleToAlloc>); 77 78 { 79 Cont cont; 80 std::queue que(cont, Alloc(2)); 81 static_assert(std::is_same_v<decltype(que), std::queue<T, Cont>>); 82 } 83 84 { 85 Cont cont; 86 std::queue que(cont, ConvertibleToAlloc(2)); 87 static_assert(std::is_same_v<decltype(que), std::queue<T, Cont>>); 88 } 89 90 { 91 Cont cont; 92 std::queue que(std::move(cont), Alloc(2)); 93 static_assert(std::is_same_v<decltype(que), std::queue<T, Cont>>); 94 } 95 96 { 97 Cont cont; 98 std::queue que(std::move(cont), ConvertibleToAlloc(2)); 99 static_assert(std::is_same_v<decltype(que), std::queue<T, Cont>>); 100 } 101 } 102 103 { 104 typedef short T; 105 typedef test_allocator<T> Alloc; 106 typedef std::list<T, Alloc> Cont; 107 typedef test_allocator<int> ConvertibleToAlloc; 108 static_assert(std::uses_allocator_v<Cont, ConvertibleToAlloc> && 109 !std::is_same_v<typename Cont::allocator_type, ConvertibleToAlloc>); 110 111 { 112 std::queue<T, Cont> source; 113 std::queue que(source, Alloc(2)); 114 static_assert(std::is_same_v<decltype(que), std::queue<T, Cont>>); 115 } 116 117 { 118 std::queue<T, Cont> source; 119 std::queue que(source, ConvertibleToAlloc(2)); 120 static_assert(std::is_same_v<decltype(que), std::queue<T, Cont>>); 121 } 122 123 { 124 std::queue<T, Cont> source; 125 std::queue que(std::move(source), Alloc(2)); 126 static_assert(std::is_same_v<decltype(que), std::queue<T, Cont>>); 127 } 128 129 { 130 std::queue<T, Cont> source; 131 std::queue que(std::move(source), ConvertibleToAlloc(2)); 132 static_assert(std::is_same_v<decltype(que), std::queue<T, Cont>>); 133 } 134 } 135 136 return 0; 137 } 138