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