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: clang-5, apple-clang-9 13 // UNSUPPORTED: libcpp-no-deduction-guides 14 // Clang 5 will generate bad implicit deduction guides 15 // Specifically, for the copy constructor. 16 17 // template<class Container> 18 // queue(Container) -> queue<typename Container::value_type, Container>; 19 // 20 // template<class Container, class Allocator> 21 // queue(Container, Allocator) -> queue<typename Container::value_type, Container>; 22 23 24 #include <queue> 25 #include <list> 26 #include <iterator> 27 #include <cassert> 28 #include <cstddef> 29 #include <climits> // INT_MAX 30 31 #include "test_macros.h" 32 #include "test_iterators.h" 33 #include "test_allocator.h" 34 35 struct A {}; 36 37 int main() 38 { 39 40 // Test the explicit deduction guides 41 { 42 std::list<int> l{0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; 43 std::queue que(l); 44 45 static_assert(std::is_same_v<decltype(que), std::queue<int, std::list<int>>>, ""); 46 assert(que.size() == l.size()); 47 assert(que.back() == l.back()); 48 } 49 50 { 51 std::list<long, test_allocator<long>> l{10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; 52 std::queue que(l, test_allocator<long>(0,2)); // different allocator 53 static_assert(std::is_same_v<decltype(que)::container_type, std::list<long, test_allocator<long>>>, ""); 54 static_assert(std::is_same_v<decltype(que)::value_type, long>, ""); 55 assert(que.size() == 10); 56 assert(que.back() == 19); 57 // I'd like to assert that we've gotten the right allocator in the queue, but 58 // I don't know how to get at the underlying container. 59 } 60 61 // Test the implicit deduction guides 62 { 63 // We don't expect this one to work - no way to implicitly get value_type 64 // std::queue que(std::allocator<int>()); // queue (allocator &) 65 } 66 67 { 68 std::queue<A> source; 69 std::queue que(source); // queue(queue &) 70 static_assert(std::is_same_v<decltype(que)::value_type, A>, ""); 71 static_assert(std::is_same_v<decltype(que)::container_type, std::deque<A>>, ""); 72 assert(que.size() == 0); 73 } 74 75 { 76 // This one is odd - you can pass an allocator in to use, but the allocator 77 // has to match the type of the one used by the underlying container 78 typedef short T; 79 typedef test_allocator<T> A; 80 typedef std::deque<T, A> C; 81 82 C c{0,1,2,3}; 83 std::queue<T, C> source(c); 84 std::queue que(source, A(2)); // queue(queue &, allocator) 85 static_assert(std::is_same_v<decltype(que)::value_type, T>, ""); 86 static_assert(std::is_same_v<decltype(que)::container_type, C>, ""); 87 assert(que.size() == 4); 88 assert(que.back() == 3); 89 } 90 91 } 92