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
10
11 // Aligned allocation is required by std::experimental::pmr, but it was not provided
12 // before macosx10.13 and as a result we get linker errors when deploying to older than
13 // macosx10.13.
14 // XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12}}
15
16 // <experimental/map>
17
18 // namespace std { namespace experimental { namespace pmr {
19 // template <class K, class V, class Compare = less<Key> >
20 // using map =
21 // ::std::map<K, V, Compare, polymorphic_allocator<pair<const K, V>>>
22 //
23 // template <class K, class V, class Compare = less<Key> >
24 // using multimap =
25 // ::std::multimap<K, V, Compare, polymorphic_allocator<pair<const K, V>>>
26 //
27 // }}} // namespace std::experimental::pmr
28
29 #include <experimental/map>
30 #include <experimental/memory_resource>
31 #include <type_traits>
32 #include <cassert>
33
34 #include "test_macros.h"
35
36 namespace pmr = std::experimental::pmr;
37
main(int,char **)38 int main(int, char**)
39 {
40 using K = int;
41 using V = char;
42 using DC = std::less<int>;
43 using OC = std::greater<int>;
44 using P = std::pair<const K, V>;
45 {
46 using StdMap = std::map<K, V, DC, pmr::polymorphic_allocator<P>>;
47 using PmrMap = pmr::map<K, V>;
48 static_assert(std::is_same<StdMap, PmrMap>::value, "");
49 }
50 {
51 using StdMap = std::map<K, V, OC, pmr::polymorphic_allocator<P>>;
52 using PmrMap = pmr::map<K, V, OC>;
53 static_assert(std::is_same<StdMap, PmrMap>::value, "");
54 }
55 {
56 pmr::map<int, int> m;
57 assert(m.get_allocator().resource() == pmr::get_default_resource());
58 }
59 {
60 using StdMap = std::multimap<K, V, DC, pmr::polymorphic_allocator<P>>;
61 using PmrMap = pmr::multimap<K, V>;
62 static_assert(std::is_same<StdMap, PmrMap>::value, "");
63 }
64 {
65 using StdMap = std::multimap<K, V, OC, pmr::polymorphic_allocator<P>>;
66 using PmrMap = pmr::multimap<K, V, OC>;
67 static_assert(std::is_same<StdMap, PmrMap>::value, "");
68 }
69 {
70 pmr::multimap<int, int> m;
71 assert(m.get_allocator().resource() == pmr::get_default_resource());
72 }
73
74 return 0;
75 }
76