match.pd: Fix indefinite recursion during exp-log transformations [PR118490]
[gcc.git] / libstdc++-v3 / testsuite / 23_containers / priority_queue / deduction.cc
blob195762d122a279bf151cd16105f26674a452ed78
1 // Copyright (C) 2019-2025 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-do compile { target c++17 } }
20 #include <queue>
21 #include <deque>
22 #include <vector>
23 #include <testsuite_iterators.h>
24 #include <testsuite_allocator.h>
26 template<typename T, typename U> struct require_same;
27 template<typename T> struct require_same<T, T> { using type = void; };
29 template<typename T, typename U>
30 typename require_same<T, U>::type
31 check_type(U&) { }
33 void
34 test01()
36 std::priority_queue<unsigned> s0;
38 std::priority_queue s1 = s0;
39 check_type<std::priority_queue<unsigned>>(s1);
41 std::priority_queue s2 = std::move(s0);
42 check_type<std::priority_queue<unsigned>>(s2);
44 const std::priority_queue s3 = s0;
45 check_type<const std::priority_queue<unsigned>>(s3);
47 const std::priority_queue s4 = s3;
48 check_type<const std::priority_queue<unsigned>>(s4);
50 std::allocator<unsigned> a;
51 std::priority_queue s5(s0, a);
52 check_type<std::priority_queue<unsigned>>(s5);
54 std::priority_queue s6(std::move(s0), a);
55 check_type<std::priority_queue<unsigned>>(s6);
57 const std::priority_queue s7(s3, a);
58 check_type<const std::priority_queue<unsigned>>(s7);
61 template<typename T>
62 using input_iterator_seq
63 = __gnu_test::test_container<T, __gnu_test::input_iterator_wrapper>;
65 void
66 test02()
68 using Deque = std::deque<int>;
69 Deque d;
70 using Vector = std::vector<short>;
71 Vector v;
72 using Cmp = std::greater<long>;
73 Cmp cmp;
75 std::priority_queue s1(cmp, d);
76 check_type<std::priority_queue<int, Deque, Cmp>>(s1);
78 std::priority_queue s2(cmp, d, d.get_allocator());
79 check_type<std::priority_queue<int, Deque, Cmp>>(s2);
81 std::priority_queue s3(cmp, std::move(d));
82 check_type<std::priority_queue<int, Deque, Cmp>>(s3);
84 std::priority_queue s4(cmp, std::move(d), d.get_allocator());
85 check_type<std::priority_queue<int, Deque, Cmp>>(s4);
87 std::priority_queue s5(cmp, v);
88 check_type<std::priority_queue<short, Vector, Cmp>>(s5);
90 std::priority_queue s6(cmp, v, v.get_allocator());
91 check_type<std::priority_queue<short, Vector, Cmp>>(s6);
93 std::priority_queue s7(cmp, std::move(v));
94 check_type<std::priority_queue<short, Vector, Cmp>>(s7);
96 std::priority_queue s8(cmp, std::move(v), v.get_allocator());
97 check_type<std::priority_queue<short, Vector, Cmp>>(s8);
99 short a[1] = {};
100 input_iterator_seq<short> seq(a);
102 std::priority_queue s9(seq.begin(), seq.end());
103 check_type<std::priority_queue<short>>(s9);
105 std::priority_queue s10(seq.begin(), seq.end(), {});
106 check_type<std::priority_queue<short>>(s10);
108 std::priority_queue s11(seq.begin(), seq.end(), {}, {});
109 check_type<std::priority_queue<short>>(s11);
111 std::priority_queue s12(seq.begin(), seq.end(), cmp);
112 check_type<std::priority_queue<short, Vector, Cmp>>(s12);
114 std::priority_queue s13(seq.begin(), seq.end(), cmp, {});
115 check_type<std::priority_queue<short, Vector, Cmp>>(s13);
117 std::priority_queue s14(seq.begin(), seq.end(), cmp, std::deque<short>{});
118 check_type<std::priority_queue<short, std::deque<short>, Cmp>>(s14);
121 struct Pool;
123 template<typename T>
124 struct Alloc : __gnu_test::SimpleAllocator<T>
126 Alloc(Pool*) { }
128 template<typename U>
129 Alloc(const Alloc<U>&) { }
132 void
133 test_p1518r2()
135 // P1518R2 - Stop overconstraining allocators in container deduction guides.
136 // This is a C++23 feature but we support it for C++17 too.
138 using Vector = std::vector<short, Alloc<short>>;
139 using Cmp = std::greater<long>;
140 Pool* p = nullptr;
141 Vector v(p);
142 Cmp cmp;
144 std::priority_queue q1(cmp, v, p);
145 check_type<std::priority_queue<short, Vector, Cmp>>(q1);
147 std::priority_queue q2(cmp, std::move(v), p);
148 check_type<std::priority_queue<short, Vector, Cmp>>(q2);
150 std::priority_queue q3(q1, p);
151 check_type<std::priority_queue<short, Vector, Cmp>>(q3);
153 std::priority_queue q4(std::move(q1), p);
154 check_type<std::priority_queue<short, Vector, Cmp>>(q4);