| 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_map> |
| 14 |
|
| 15 |
// namespace std::pmr { |
| 16 |
// template <class K, class V, class H = hash<K>, class P = equal_to<K> > |
| 17 |
// using unordered_map = |
| 18 |
// ::std::unordered_map<K, V, H, P, polymorphic_allocator<pair<const K, V>>> |
| 19 |
// |
| 20 |
// template <class K, class V, class H = hash<K>, class P = equal_to<K> > |
| 21 |
// using unordered_multimap = |
| 22 |
// ::std::unordered_multimap<K, V, H, P, polymorphic_allocator<pair<const K, V>>> |
| 23 |
// |
| 24 |
// } // namespace std::pmr |
| 25 |
|
| 26 |
#include <unordered_map> |
| 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 K = int; |
| 39 |
using V = char; |
| 40 |
using DH = std::hash<K>; |
| 41 |
using MH = MyHash<K>; |
| 42 |
using DP = std::equal_to<K>; |
| 43 |
using MP = MyPred<K>; |
| 44 |
using P = std::pair<const K, V>; |
| 45 |
{ |
| 46 |
using StdMap = std::unordered_map<K, V, DH, DP, std::pmr::polymorphic_allocator<P>>; |
| 47 |
using PmrMap = std::pmr::unordered_map<K, V>; |
| 48 |
static_assert(std::is_same<StdMap, PmrMap>::value, ""); |
| 49 |
} |
| 50 |
{ |
| 51 |
using StdMap = std::unordered_map<K, V, MH, DP, std::pmr::polymorphic_allocator<P>>; |
| 52 |
using PmrMap = std::pmr::unordered_map<K, V, MH>; |
| 53 |
static_assert(std::is_same<StdMap, PmrMap>::value, ""); |
| 54 |
} |
| 55 |
{ |
| 56 |
using StdMap = std::unordered_map<K, V, MH, MP, std::pmr::polymorphic_allocator<P>>; |
| 57 |
using PmrMap = std::pmr::unordered_map<K, V, MH, MP>; |
| 58 |
static_assert(std::is_same<StdMap, PmrMap>::value, ""); |
| 59 |
} |
| 60 |
{ |
| 61 |
std::pmr::unordered_map<int, int> m; |
| 62 |
assert(m.get_allocator().resource() == std::pmr::get_default_resource()); |
| 63 |
} |
| 64 |
{ |
| 65 |
using StdMap = std::unordered_multimap<K, V, DH, DP, std::pmr::polymorphic_allocator<P>>; |
| 66 |
using PmrMap = std::pmr::unordered_multimap<K, V>; |
| 67 |
static_assert(std::is_same<StdMap, PmrMap>::value, ""); |
| 68 |
} |
| 69 |
{ |
| 70 |
using StdMap = std::unordered_multimap<K, V, MH, DP, std::pmr::polymorphic_allocator<P>>; |
| 71 |
using PmrMap = std::pmr::unordered_multimap<K, V, MH>; |
| 72 |
static_assert(std::is_same<StdMap, PmrMap>::value, ""); |
| 73 |
} |
| 74 |
{ |
| 75 |
using StdMap = std::unordered_multimap<K, V, MH, MP, std::pmr::polymorphic_allocator<P>>; |
| 76 |
using PmrMap = std::pmr::unordered_multimap<K, V, MH, MP>; |
| 77 |
static_assert(std::is_same<StdMap, PmrMap>::value, ""); |
| 78 |
} |
| 79 |
{ |
| 80 |
std::pmr::unordered_multimap<int, int> m; |
| 81 |
assert(m.get_allocator().resource() == std::pmr::get_default_resource()); |
| 82 |
} |
| 83 |
|
| 84 |
return 0; |
| 85 |
} |