1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 4 // The LLVM Compiler Infrastructure 5 // 6 // This file is dual licensed under the MIT and the University of Illinois Open 7 // Source Licenses. See LICENSE.TXT for details. 8 // 9 //===----------------------------------------------------------------------===// 10 11 // REQUIRES: c++experimental 12 // UNSUPPORTED: c++98, c++03 13 14 // <experimental/unordered_map> 15 16 // namespace std { namespace experimental { namespace pmr { 17 // template <class K, class V, class H = hash<K>, class P = equal_to<K> > 18 // using unordered_map = 19 // ::std::unordered_map<K, V, H, P, polymorphic_allocator<pair<const K, V>>> 20 // 21 // template <class K, class V, class H = hash<K>, class P = equal_to<K> > 22 // using unordered_multimap = 23 // ::std::unordered_multimap<K, V, H, P, polymorphic_allocator<pair<const K, V>>> 24 // 25 // }}} // namespace std::experimental::pmr 26 27 #include <experimental/unordered_map> 28 #include <experimental/memory_resource> 29 #include <type_traits> 30 #include <cassert> 31 32 namespace pmr = std::experimental::pmr; 33 34 template <class T> 35 struct MyHash : std::hash<T> {}; 36 37 template <class T> 38 struct MyPred : std::equal_to<T> {}; 39 40 int main() 41 { 42 using K = int; 43 using V = char; 44 using DH = std::hash<K>; 45 using MH = MyHash<K>; 46 using DP = std::equal_to<K>; 47 using MP = MyPred<K>; 48 using P = std::pair<const K, V>; 49 { 50 using StdMap = std::unordered_map<K, V, DH, DP, pmr::polymorphic_allocator<P>>; 51 using PmrMap = pmr::unordered_map<K, V>; 52 static_assert(std::is_same<StdMap, PmrMap>::value, ""); 53 } 54 { 55 using StdMap = std::unordered_map<K, V, MH, DP, pmr::polymorphic_allocator<P>>; 56 using PmrMap = pmr::unordered_map<K, V, MH>; 57 static_assert(std::is_same<StdMap, PmrMap>::value, ""); 58 } 59 { 60 using StdMap = std::unordered_map<K, V, MH, MP, pmr::polymorphic_allocator<P>>; 61 using PmrMap = pmr::unordered_map<K, V, MH, MP>; 62 static_assert(std::is_same<StdMap, PmrMap>::value, ""); 63 } 64 { 65 pmr::unordered_map<int, int> m; 66 assert(m.get_allocator().resource() == pmr::get_default_resource()); 67 } 68 { 69 using StdMap = std::unordered_multimap<K, V, DH, DP, pmr::polymorphic_allocator<P>>; 70 using PmrMap = pmr::unordered_multimap<K, V>; 71 static_assert(std::is_same<StdMap, PmrMap>::value, ""); 72 } 73 { 74 using StdMap = std::unordered_multimap<K, V, MH, DP, pmr::polymorphic_allocator<P>>; 75 using PmrMap = pmr::unordered_multimap<K, V, MH>; 76 static_assert(std::is_same<StdMap, PmrMap>::value, ""); 77 } 78 { 79 using StdMap = std::unordered_multimap<K, V, MH, MP, pmr::polymorphic_allocator<P>>; 80 using PmrMap = pmr::unordered_multimap<K, V, MH, MP>; 81 static_assert(std::is_same<StdMap, PmrMap>::value, ""); 82 } 83 { 84 pmr::unordered_multimap<int, int> m; 85 assert(m.get_allocator().resource() == pmr::get_default_resource()); 86 } 87 } 88