Refactor ix86_expand_vecop_qihi2.
[gcc.git] / libstdc++-v3 / testsuite / 23_containers / set / cons / deduction.cc
blobd77b9fcb73df8e53afa59c983b90525392fd6f6b
1 // { dg-do compile { target c++17 } }
3 #include <set>
4 #include <testsuite_allocator.h>
5 #include <testsuite_iterators.h>
7 using __gnu_test::SimpleAllocator;
8 using value_type = std::set<int>::value_type;
10 static_assert(std::is_same_v<
11 decltype(std::set{1, 2, 3}),
12 std::set<int>>);
14 static_assert(std::is_same_v<
15 decltype(std::set{1, 2, 3}),
16 std::set<int>>);
18 static_assert(std::is_same_v<
19 decltype(std::set{{1, 2, 3},
20 std::less<int>{}, {}}),
21 std::set<int>>);
23 static_assert(std::is_same_v<
24 decltype(std::set{{1, 2, 3},
25 std::less<int>{}}),
26 std::set<int>>);
28 static_assert(std::is_same_v<
29 decltype(std::set{{1, 2, 3},
30 SimpleAllocator<int>{}}),
31 std::set<int, std::less<int>,
32 SimpleAllocator<int>>>);
34 static_assert(std::is_same_v<
35 decltype(std::set{{1, 2, 3},
36 {}, SimpleAllocator<int>{}}),
37 std::set<int, std::less<int>,
38 SimpleAllocator<int>>>);
40 void f()
42 std::set<int> x;
44 static_assert(std::is_same_v<
45 decltype(std::set(x.begin(), x.end())),
46 std::set<int>>);
48 static_assert(std::is_same_v<
49 decltype(std::set{x.begin(), x.end(),
50 std::less<int>{},
51 std::allocator<int>{}}),
52 std::set<int>>);
54 static_assert(std::is_same_v<
55 decltype(std::set{x.begin(), x.end(),
56 std::less<int>{}, {}}),
57 std::set<int>>);
59 static_assert(std::is_same_v<
60 decltype(std::set(x.begin(), x.end(),
61 std::less<int>{})),
62 std::set<int>>);
64 static_assert(std::is_same_v<
65 decltype(std::set{x.begin(), x.end(),
66 {},
67 std::allocator<int>{}}),
68 std::set<int>>);
70 static_assert(std::is_same_v<
71 decltype(std::set{x.begin(), x.end(),
72 SimpleAllocator<int>{}}),
73 std::set<int, std::less<int>, SimpleAllocator<int>>>);
75 static_assert(std::is_same_v<
76 decltype(std::set{x.begin(), x.end(),
77 {},
78 SimpleAllocator<int>{}}),
79 std::set<int, std::less<int>, SimpleAllocator<int>>>);
82 using __gnu_test::test_container;
83 using __gnu_test::input_iterator_wrapper;
85 void g()
87 value_type array[1];
88 test_container<value_type, input_iterator_wrapper> x(array);
90 static_assert(std::is_same_v<
91 decltype(std::set(x.begin(), x.end())),
92 std::set<int>>);
94 static_assert(std::is_same_v<
95 decltype(std::set{x.begin(), x.end(),
96 std::less<int>{},
97 std::allocator<value_type>{}}),
98 std::set<int>>);
100 static_assert(std::is_same_v<
101 decltype(std::set{x.begin(), x.end(),
102 std::less<int>{}, {}}),
103 std::set<int>>);
105 static_assert(std::is_same_v<
106 decltype(std::set(x.begin(), x.end(),
107 std::less<int>{})),
108 std::set<int>>);
110 static_assert(std::is_same_v<
111 decltype(std::set{x.begin(), x.end(),
112 std::allocator<value_type>{}}),
113 std::set<int>>);
115 static_assert(std::is_same_v<
116 decltype(std::set{x.begin(), x.end(),
117 SimpleAllocator<value_type>{}}),
118 std::set<int, std::less<int>,
119 SimpleAllocator<value_type>>>);
121 static_assert(std::is_same_v<
122 decltype(std::set{x.begin(), x.end(),
124 std::allocator<value_type>{}}),
125 std::set<int>>);
127 static_assert(std::is_same_v<
128 decltype(std::set{x.begin(), x.end(),
130 SimpleAllocator<value_type>{}}),
131 std::set<int, std::less<int>,
132 SimpleAllocator<value_type>>>);
135 template<typename T, typename U> struct require_same;
136 template<typename T> struct require_same<T, T> { using type = void; };
138 template<typename T, typename U>
139 typename require_same<T, U>::type
140 check_type(U&) { }
142 struct Pool;
144 template<typename T>
145 struct Alloc : __gnu_test::SimpleAllocator<T>
147 Alloc(Pool*) { }
149 template<typename U>
150 Alloc(const Alloc<U>&) { }
153 void
154 test_p1518r2()
156 // P1518R2 - Stop overconstraining allocators in container deduction guides.
157 // This is a C++23 feature but we support it for C++17 too.
159 using Set = std::set<unsigned, std::greater<>, Alloc<unsigned>>;
160 Pool* p = nullptr;
161 Set s(p);
163 std::set s1(s, p);
164 check_type<Set>(s1);
166 std::set s2(std::move(s), p);
167 check_type<Set>(s2);