| 1 |
// { dg-do compile { target c++11 } } |
| 2 |
#include <unordered_map> |
| 3 |
|
| 4 |
static_assert( std::is_default_constructible<std::unordered_map<int, int>>{}, "" ); |
| 5 |
|
| 6 |
template<typename T> |
| 7 |
struct NoDefaultConsAlloc |
| 8 |
{ |
| 9 |
using value_type = T; |
| 10 |
|
| 11 |
NoDefaultConsAlloc(int) noexcept { } |
| 12 |
|
| 13 |
template<typename U> |
| 14 |
NoDefaultConsAlloc(const NoDefaultConsAlloc<U>&) { } |
| 15 |
|
| 16 |
T *allocate(std::size_t n) |
| 17 |
{ return std::allocator<T>().allocate(n); } |
| 18 |
|
| 19 |
void deallocate(T *p, std::size_t n) |
| 20 |
{ std::allocator<T>().deallocate(p, n); } |
| 21 |
|
| 22 |
bool operator==(const NoDefaultConsAlloc&) const { return true; } |
| 23 |
bool operator!=(const NoDefaultConsAlloc&) const { return false; } |
| 24 |
}; |
| 25 |
|
| 26 |
using Map = std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, |
| 27 |
NoDefaultConsAlloc<std::pair<const int, int>>>; |
| 28 |
static_assert( ! std::is_default_constructible<Map>{}, "PR libstdc++/100863" ); |
| 29 |
|
| 30 |
struct Hash : std::hash<int> { Hash(int) { } }; |
| 31 |
using Map2 = std::unordered_map<int, int, Hash>; |
| 32 |
static_assert( ! std::is_default_constructible<Map2>{}, "PR libstdc++/100863" ); |
| 33 |
|
| 34 |
struct Equal : std::equal_to<int> { Equal(int) { } }; |
| 35 |
using Map3 = std::unordered_map<int, int, std::hash<int>, Equal>; |
| 36 |
static_assert( ! std::is_default_constructible<Map3>{}, "PR libstdc++/100863" ); |
| 37 |
|
| 38 |
// PR libstdc++/101583 |
| 39 |
// verify non-default ctors can still be used |
| 40 |
using Map4 = std::unordered_map<int, int, Hash, Equal, |
| 41 |
NoDefaultConsAlloc<std::pair<const int, int>>>; |
| 42 |
Hash h(1); |
| 43 |
Equal eq(1); |
| 44 |
Map4::allocator_type a(1); |
| 45 |
Map4 m{1, h, eq, a}; |
| 46 |
Map4 m2{m.begin(), m.end(), m.size(), h, eq, a}; |
| 47 |
Map4 m3{{{1,1}, {2,2}, {3,3}}, 3, h, eq, a}; |
| 48 |
Map4 m4{m}; |
| 49 |
Map4 m5{m, a}; |
| 50 |
Map4 m6{std::move(m)}; |
| 51 |
Map4 m7{std::move(m6), a}; |