| 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 | // <map> |
| 14 | |
| 15 | // namespace std::pmr { |
| 16 | // template <class K, class V, class Compare = less<Key> > |
| 17 | // using map = |
| 18 | // ::std::map<K, V, Compare, polymorphic_allocator<pair<const K, V>>> |
| 19 | // |
| 20 | // template <class K, class V, class Compare = less<Key> > |
| 21 | // using multimap = |
| 22 | // ::std::multimap<K, V, Compare, polymorphic_allocator<pair<const K, V>>> |
| 23 | // |
| 24 | // } // namespace std::pmr |
| 25 | |
| 26 | #include <map> |
| 27 | #include <memory_resource> |
| 28 | #include <type_traits> |
| 29 | #include <cassert> |
| 30 | |
| 31 | int main(int, char**) { |
| 32 | using K = int; |
| 33 | using V = char; |
| 34 | using DC = std::less<int>; |
| 35 | using OC = std::greater<int>; |
| 36 | using P = std::pair<const K, V>; |
| 37 | { |
| 38 | using StdMap = std::map<K, V, DC, std::pmr::polymorphic_allocator<P>>; |
| 39 | using PmrMap = std::pmr::map<K, V>; |
| 40 | static_assert(std::is_same<StdMap, PmrMap>::value, "" ); |
| 41 | } |
| 42 | { |
| 43 | using StdMap = std::map<K, V, OC, std::pmr::polymorphic_allocator<P>>; |
| 44 | using PmrMap = std::pmr::map<K, V, OC>; |
| 45 | static_assert(std::is_same<StdMap, PmrMap>::value, "" ); |
| 46 | } |
| 47 | { |
| 48 | std::pmr::map<int, int> m; |
| 49 | assert(m.get_allocator().resource() == std::pmr::get_default_resource()); |
| 50 | } |
| 51 | { |
| 52 | using StdMap = std::multimap<K, V, DC, std::pmr::polymorphic_allocator<P>>; |
| 53 | using PmrMap = std::pmr::multimap<K, V>; |
| 54 | static_assert(std::is_same<StdMap, PmrMap>::value, "" ); |
| 55 | } |
| 56 | { |
| 57 | using StdMap = std::multimap<K, V, OC, std::pmr::polymorphic_allocator<P>>; |
| 58 | using PmrMap = std::pmr::multimap<K, V, OC>; |
| 59 | static_assert(std::is_same<StdMap, PmrMap>::value, "" ); |
| 60 | } |
| 61 | { |
| 62 | std::pmr::multimap<int, int> m; |
| 63 | assert(m.get_allocator().resource() == std::pmr::get_default_resource()); |
| 64 | } |
| 65 | |
| 66 | return 0; |
| 67 | } |
| 68 | |