| 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 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// UNSUPPORTED: c++03, c++11, c++14 |
| 10 |
// TODO: Change to XFAIL once https://github.com/llvm/llvm-project/issues/40340 is fixed |
| 11 |
// UNSUPPORTED: availability-pmr-missing |
| 12 |
|
| 13 |
// <unordered_set> |
| 14 |
|
| 15 |
// namespace std::pmr { |
| 16 |
// template <class V, class H = hash<V>, class P = equal_to<V> > |
| 17 |
// using unordered_set = |
| 18 |
// ::std::unordered_set<V, H, P, polymorphic_allocator<V>> |
| 19 |
// |
| 20 |
// template <class V, class H = hash<V>, class P = equal_to<V> > |
| 21 |
// using unordered_multiset = |
| 22 |
// ::std::unordered_multiset<V, H, P, polymorphic_allocator<V>> |
| 23 |
// |
| 24 |
// } // namespace std::pmr |
| 25 |
|
| 26 |
#include <unordered_set> |
| 27 |
#include <memory_resource> |
| 28 |
#include <type_traits> |
| 29 |
#include <cassert> |
| 30 |
|
| 31 |
template <class T> |
| 32 |
struct MyHash : std::hash<T> {}; |
| 33 |
|
| 34 |
template <class T> |
| 35 |
struct MyPred : std::equal_to<T> {}; |
| 36 |
|
| 37 |
int main(int, char**) { |
| 38 |
using V = char; |
| 39 |
using DH = std::hash<V>; |
| 40 |
using MH = MyHash<V>; |
| 41 |
using DP = std::equal_to<V>; |
| 42 |
using MP = MyPred<V>; |
| 43 |
{ |
| 44 |
using StdSet = std::unordered_set<V, DH, DP, std::pmr::polymorphic_allocator<V>>; |
| 45 |
using PmrSet = std::pmr::unordered_set<V>; |
| 46 |
static_assert(std::is_same<StdSet, PmrSet>::value, ""); |
| 47 |
} |
| 48 |
{ |
| 49 |
using StdSet = std::unordered_set<V, MH, DP, std::pmr::polymorphic_allocator<V>>; |
| 50 |
using PmrSet = std::pmr::unordered_set<V, MH>; |
| 51 |
static_assert(std::is_same<StdSet, PmrSet>::value, ""); |
| 52 |
} |
| 53 |
{ |
| 54 |
using StdSet = std::unordered_set<V, MH, MP, std::pmr::polymorphic_allocator<V>>; |
| 55 |
using PmrSet = std::pmr::unordered_set<V, MH, MP>; |
| 56 |
static_assert(std::is_same<StdSet, PmrSet>::value, ""); |
| 57 |
} |
| 58 |
{ |
| 59 |
std::pmr::unordered_set<int> m; |
| 60 |
assert(m.get_allocator().resource() == std::pmr::get_default_resource()); |
| 61 |
} |
| 62 |
{ |
| 63 |
using StdSet = std::unordered_multiset<V, DH, DP, std::pmr::polymorphic_allocator<V>>; |
| 64 |
using PmrSet = std::pmr::unordered_multiset<V>; |
| 65 |
static_assert(std::is_same<StdSet, PmrSet>::value, ""); |
| 66 |
} |
| 67 |
{ |
| 68 |
using StdSet = std::unordered_multiset<V, MH, DP, std::pmr::polymorphic_allocator<V>>; |
| 69 |
using PmrSet = std::pmr::unordered_multiset<V, MH>; |
| 70 |
static_assert(std::is_same<StdSet, PmrSet>::value, ""); |
| 71 |
} |
| 72 |
{ |
| 73 |
using StdSet = std::unordered_multiset<V, MH, MP, std::pmr::polymorphic_allocator<V>>; |
| 74 |
using PmrSet = std::pmr::unordered_multiset<V, MH, MP>; |
| 75 |
static_assert(std::is_same<StdSet, PmrSet>::value, ""); |
| 76 |
} |
| 77 |
{ |
| 78 |
std::pmr::unordered_multiset<int> m; |
| 79 |
assert(m.get_allocator().resource() == std::pmr::get_default_resource()); |
| 80 |
} |
| 81 |
|
| 82 |
return 0; |
| 83 |
} |