| 1 |
// { dg-do compile { target c++17 } } |
| 2 |
|
| 3 |
#include <set> |
| 4 |
#include <testsuite_allocator.h> |
| 5 |
#include <testsuite_iterators.h> |
| 6 |
|
| 7 |
using __gnu_test::SimpleAllocator; |
| 8 |
using value_type = std::set<int>::value_type; |
| 9 |
|
| 10 |
static_assert(std::is_same_v< |
| 11 |
decltype(std::set{1, 2, 3}), |
| 12 |
std::set<int>>); |
| 13 |
|
| 14 |
static_assert(std::is_same_v< |
| 15 |
decltype(std::set{1, 2, 3}), |
| 16 |
std::set<int>>); |
| 17 |
|
| 18 |
static_assert(std::is_same_v< |
| 19 |
decltype(std::set{{1, 2, 3}, |
| 20 |
std::less<int>{}, {}}), |
| 21 |
std::set<int>>); |
| 22 |
|
| 23 |
static_assert(std::is_same_v< |
| 24 |
decltype(std::set{{1, 2, 3}, |
| 25 |
std::less<int>{}}), |
| 26 |
std::set<int>>); |
| 27 |
|
| 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>>>); |
| 33 |
|
| 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>>>); |
| 39 |
|
| 40 |
void f() |
| 41 |
{ |
| 42 |
std::set<int> x; |
| 43 |
|
| 44 |
static_assert(std::is_same_v< |
| 45 |
decltype(std::set(x.begin(), x.end())), |
| 46 |
std::set<int>>); |
| 47 |
|
| 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>>); |
| 53 |
|
| 54 |
static_assert(std::is_same_v< |
| 55 |
decltype(std::set{x.begin(), x.end(), |
| 56 |
std::less<int>{}, {}}), |
| 57 |
std::set<int>>); |
| 58 |
|
| 59 |
static_assert(std::is_same_v< |
| 60 |
decltype(std::set(x.begin(), x.end(), |
| 61 |
std::less<int>{})), |
| 62 |
std::set<int>>); |
| 63 |
|
| 64 |
static_assert(std::is_same_v< |
| 65 |
decltype(std::set{x.begin(), x.end(), |
| 66 |
{}, |
| 67 |
std::allocator<int>{}}), |
| 68 |
std::set<int>>); |
| 69 |
|
| 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>>>); |
| 74 |
|
| 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>>>); |
| 80 |
} |
| 81 |
|
| 82 |
using __gnu_test::test_container; |
| 83 |
using __gnu_test::input_iterator_wrapper; |
| 84 |
|
| 85 |
void g() |
| 86 |
{ |
| 87 |
value_type array[1]; |
| 88 |
test_container<value_type, input_iterator_wrapper> x(array); |
| 89 |
|
| 90 |
static_assert(std::is_same_v< |
| 91 |
decltype(std::set(x.begin(), x.end())), |
| 92 |
std::set<int>>); |
| 93 |
|
| 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>>); |
| 99 |
|
| 100 |
static_assert(std::is_same_v< |
| 101 |
decltype(std::set{x.begin(), x.end(), |
| 102 |
std::less<int>{}, {}}), |
| 103 |
std::set<int>>); |
| 104 |
|
| 105 |
static_assert(std::is_same_v< |
| 106 |
decltype(std::set(x.begin(), x.end(), |
| 107 |
std::less<int>{})), |
| 108 |
std::set<int>>); |
| 109 |
|
| 110 |
static_assert(std::is_same_v< |
| 111 |
decltype(std::set{x.begin(), x.end(), |
| 112 |
std::allocator<value_type>{}}), |
| 113 |
std::set<int>>); |
| 114 |
|
| 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>>>); |
| 120 |
|
| 121 |
static_assert(std::is_same_v< |
| 122 |
decltype(std::set{x.begin(), x.end(), |
| 123 |
{}, |
| 124 |
std::allocator<value_type>{}}), |
| 125 |
std::set<int>>); |
| 126 |
|
| 127 |
static_assert(std::is_same_v< |
| 128 |
decltype(std::set{x.begin(), x.end(), |
| 129 |
{}, |
| 130 |
SimpleAllocator<value_type>{}}), |
| 131 |
std::set<int, std::less<int>, |
| 132 |
SimpleAllocator<value_type>>>); |
| 133 |
} |
| 134 |
|
| 135 |
template<typename T, typename U> struct require_same; |
| 136 |
template<typename T> struct require_same<T, T> { using type = void; }; |
| 137 |
|
| 138 |
template<typename T, typename U> |
| 139 |
typename require_same<T, U>::type |
| 140 |
check_type(U&) { } |
| 141 |
|
| 142 |
struct Pool; |
| 143 |
|
| 144 |
template<typename T> |
| 145 |
struct Alloc : __gnu_test::SimpleAllocator<T> |
| 146 |
{ |
| 147 |
Alloc(Pool*) { } |
| 148 |
|
| 149 |
template<typename U> |
| 150 |
Alloc(const Alloc<U>&) { } |
| 151 |
}; |
| 152 |
|
| 153 |
void |
| 154 |
test_p1518r2() |
| 155 |
{ |
| 156 |
// P1518R2 - Stop overconstraining allocators in container deduction guides. |
| 157 |
// This is a C++23 feature but we support it for C++17 too. |
| 158 |
|
| 159 |
using Set = std::set<unsigned, std::greater<>, Alloc<unsigned>>; |
| 160 |
Pool* p = nullptr; |
| 161 |
Set s(p); |
| 162 |
|
| 163 |
std::set s1(s, p); |
| 164 |
check_type<Set>(s1); |
| 165 |
|
| 166 |
std::set s2(std::move(s), p); |
| 167 |
check_type<Set>(s2); |
| 168 |
} |