[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / container.adaptors / queue / queue.cons / deduct.pass.cpp
blob738a3a1701638612e6a313e02e2ffedd91646a0f
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 //===----------------------------------------------------------------------===//
9 // <queue>
10 // UNSUPPORTED: c++03, c++11, c++14
11 // UNSUPPORTED: clang-5, apple-clang-9
12 // UNSUPPORTED: libcpp-no-deduction-guides
13 // Clang 5 will generate bad implicit deduction guides
14 // Specifically, for the copy constructor.
16 // template<class Container>
17 // queue(Container) -> queue<typename Container::value_type, Container>;
19 // template<class Container, class Allocator>
20 // queue(Container, Allocator) -> queue<typename Container::value_type, Container>;
23 #include <queue>
24 #include <list>
25 #include <iterator>
26 #include <cassert>
27 #include <cstddef>
28 #include <climits> // INT_MAX
30 #include "test_macros.h"
31 #include "test_iterators.h"
32 #include "test_allocator.h"
34 struct A {};
36 int main(int, char**)
39 // Test the explicit deduction guides
41 std::list<int> l{0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
42 std::queue que(l);
44 static_assert(std::is_same_v<decltype(que), std::queue<int, std::list<int>>>, "");
45 assert(que.size() == l.size());
46 assert(que.back() == l.back());
50 std::list<long, test_allocator<long>> l{10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
51 std::queue que(l, test_allocator<long>(0,2)); // different allocator
52 static_assert(std::is_same_v<decltype(que)::container_type, std::list<long, test_allocator<long>>>, "");
53 static_assert(std::is_same_v<decltype(que)::value_type, long>, "");
54 assert(que.size() == 10);
55 assert(que.back() == 19);
56 // I'd like to assert that we've gotten the right allocator in the queue, but
57 // I don't know how to get at the underlying container.
60 // Test the implicit deduction guides
62 // We don't expect this one to work - no way to implicitly get value_type
63 // std::queue que(std::allocator<int>()); // queue (allocator &)
67 std::queue<A> source;
68 std::queue que(source); // queue(queue &)
69 static_assert(std::is_same_v<decltype(que)::value_type, A>, "");
70 static_assert(std::is_same_v<decltype(que)::container_type, std::deque<A>>, "");
71 assert(que.size() == 0);
75 // This one is odd - you can pass an allocator in to use, but the allocator
76 // has to match the type of the one used by the underlying container
77 typedef short T;
78 typedef test_allocator<T> Alloc;
79 typedef std::deque<T, Alloc> Container;
81 Container c{0,1,2,3};
82 std::queue<T, Container> source(c);
83 std::queue que(source, Alloc(2)); // queue(queue &, allocator)
84 static_assert(std::is_same_v<decltype(que)::value_type, T>, "");
85 static_assert(std::is_same_v<decltype(que)::container_type, Container>, "");
86 assert(que.size() == 4);
87 assert(que.back() == 3);
91 return 0;