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 // UNSUPPORTED: c++98, c++03
14 // template <class OtherAlloc, class ...InnerAlloc>
15 // class scoped_allocator_adaptor
17 // template <class U1, class U2>
18 // void scoped_allocator_adaptor::construct(pair<U1, U2>*)
20 #include <scoped_allocator>
21 #include <type_traits>
26 #include "uses_alloc_types.hpp"
27 #include "controlled_allocators.hpp"
30 void test_no_inner_alloc()
32 using VoidAlloc = CountingAllocator<void>;
35 using T = UsesAllocatorV1<VoidAlloc, 0>;
36 using U = UsesAllocatorV2<VoidAlloc, 0>;
37 using Pair = std::pair<T, U>;
38 using Alloc = CountingAllocator<Pair>;
39 using SA = std::scoped_allocator_adaptor<Alloc>;
40 static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, "");
41 Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
45 assert(checkConstruct<>(ptr->first, UA_AllocArg, CA));
46 assert(checkConstruct<>(ptr->second, UA_AllocLast, CA));
47 assert((P.checkConstruct<std::piecewise_construct_t const&,
48 std::tuple<std::allocator_arg_t, SA&>&&,
57 using T = UsesAllocatorV3<VoidAlloc, 0>;
58 using U = NotUsesAllocator<VoidAlloc, 0>;
59 using Pair = std::pair<T, U>;
60 using Alloc = CountingAllocator<Pair>;
61 using SA = std::scoped_allocator_adaptor<Alloc>;
62 static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, "");
63 Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
67 assert(checkConstruct<>(ptr->first, UA_AllocArg, CA));
68 assert(checkConstruct<>(ptr->second, UA_None));
69 assert((P.checkConstruct<std::piecewise_construct_t const&,
70 std::tuple<std::allocator_arg_t, SA&>&&,
78 void test_with_inner_alloc()
80 using VoidAlloc1 = CountingAllocator<void, 1>;
81 using VoidAlloc2 = CountingAllocator<void, 2>;
83 AllocController POuter;
84 AllocController PInner;
86 using T = UsesAllocatorV1<VoidAlloc2, 0>;
87 using U = UsesAllocatorV2<VoidAlloc2, 0>;
88 using Pair = std::pair<T, U>;
89 using Outer = CountingAllocator<Pair, 1>;
90 using Inner = CountingAllocator<Pair, 2>;
91 using SA = std::scoped_allocator_adaptor<Outer, Inner>;
92 using SAInner = std::scoped_allocator_adaptor<Inner>;
93 static_assert(!std::uses_allocator<T, Outer>::value, "");
94 static_assert(std::uses_allocator<T, Inner>::value, "");
95 Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
100 assert(checkConstruct<>(ptr->first, UA_AllocArg, I));
101 assert(checkConstruct<>(ptr->second, UA_AllocLast));
102 assert((POuter.checkConstruct<std::piecewise_construct_t const&,
103 std::tuple<std::allocator_arg_t, SAInner&>&&,
104 std::tuple<SAInner&>&&
112 using T = UsesAllocatorV3<VoidAlloc2, 0>;
113 using U = NotUsesAllocator<VoidAlloc2, 0>;
114 using Pair = std::pair<T, U>;
115 using Outer = CountingAllocator<Pair, 1>;
116 using Inner = CountingAllocator<Pair, 2>;
117 using SA = std::scoped_allocator_adaptor<Outer, Inner>;
118 using SAInner = std::scoped_allocator_adaptor<Inner>;
119 static_assert(!std::uses_allocator<T, Outer>::value, "");
120 static_assert(std::uses_allocator<T, Inner>::value, "");
121 Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
126 assert(checkConstruct<>(ptr->first, UA_AllocArg, I));
127 assert(checkConstruct<>(ptr->second, UA_None));
128 assert((POuter.checkConstruct<std::piecewise_construct_t const&,
129 std::tuple<std::allocator_arg_t, SAInner&>&&,
137 test_no_inner_alloc();
138 test_with_inner_alloc();