1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <queue> 11 // UNSUPPORTED: c++98, c++03, c++11, c++14 12 // UNSUPPORTED: libcpp-no-deduction-guides 13 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() 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 // This one is odd - you can pass an allocator in to use, but the allocator 75 // has to match the type of the one used by the underlying container 76 typedef short T; 77 typedef test_allocator<T> A; 78 typedef std::deque<T, A> C; 79 80 C c{0,1,2,3}; 81 std::queue<T, C> source(c); 82 std::queue que(source, A(2)); // queue(queue &, allocator) 83 static_assert(std::is_same_v<decltype(que)::value_type, T>, ""); 84 static_assert(std::is_same_v<decltype(que)::container_type, C>, ""); 85 assert(que.size() == 4); 86 assert(que.back() == 3); 87 } 88 89 } 90