1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // REQUIRES: c++experimental
11 // UNSUPPORTED: c++98, c++03
13 // <experimental/memory_resource>
15 // template <class T> class polymorphic_allocator
17 // template <class P1, class P2, class U1, class U2>
18 // void polymorphic_allocator<T>::construct(pair<P1, P2>*, pair<U1, U2> const&)
20 #include <experimental/memory_resource>
21 #include <type_traits>
27 #include "test_macros.h"
28 #include "test_memory_resource.hpp"
29 #include "uses_alloc_types.hpp"
30 #include "controlled_allocators.hpp"
31 #include "test_allocator.h"
33 namespace ex = std::experimental::pmr;
36 template <class UA1, class UA2, class TT, class UU>
37 bool doTest(UsesAllocatorType TExpect, UsesAllocatorType UExpect,
38 std::pair<TT, UU> const& p)
40 using P = std::pair<UA1, UA2>;
42 ex::memory_resource * M = &R;
43 ex::polymorphic_allocator<P> A(M);
44 P * ptr = (P*)std::malloc(sizeof(P));
45 P * ptr2 = (P*)std::malloc(sizeof(P));
50 A.construct(ptr2, std::piecewise_construct,
51 std::forward_as_tuple(p.first),
52 std::forward_as_tuple(p.second));
55 bool tres = checkConstruct<decltype((p.first))>(ptr->first, TExpect, M) &&
56 checkConstructionEquiv(ptr->first, ptr2->first);
58 bool ures = checkConstruct<decltype((p.second))>(ptr->second, UExpect, M) &&
59 checkConstructionEquiv(ptr->second, ptr2->second);
69 template <class Alloc, class TT, class UU>
70 void test_pmr_uses_allocator(std::pair<TT, UU> const& p)
73 using T = NotUsesAllocator<Alloc, 1>;
74 using U = NotUsesAllocator<Alloc, 1>;
75 assert((doTest<T, U>(UA_None, UA_None, p)));
78 using T = UsesAllocatorV1<Alloc, 1>;
79 using U = UsesAllocatorV2<Alloc, 1>;
80 assert((doTest<T, U>(UA_AllocArg, UA_AllocLast, p)));
83 using T = UsesAllocatorV2<Alloc, 1>;
84 using U = UsesAllocatorV3<Alloc, 1>;
85 assert((doTest<T, U>(UA_AllocLast, UA_AllocArg, p)));
88 using T = UsesAllocatorV3<Alloc, 1>;
89 using U = NotUsesAllocator<Alloc, 1>;
90 assert((doTest<T, U>(UA_AllocArg, UA_None, p)));
98 using ERT = std::experimental::erased_type;
99 using PMR = ex::memory_resource*;
100 using PMA = ex::polymorphic_allocator<char>;
104 const std::pair<int, int&> p(x, y);
105 test_pmr_uses_allocator<ERT>(p);
106 test_pmr_uses_allocator<PMR>(p);
107 test_pmr_uses_allocator<PMA>(p);
112 const std::pair<int&, int&&> p(x, std::move(y));
113 test_pmr_uses_allocator<ERT>(p);
114 test_pmr_uses_allocator<PMR>(p);
115 test_pmr_uses_allocator<PMA>(p);