Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Differential D58879 Diff 199196 test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_piecewise.pass.cpp
Changeset View
Changeset View
Standalone View
Standalone View
test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_piecewise.pass.cpp
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | AllocController P; | ||||
assert(ptr != nullptr); | assert(ptr != nullptr); | ||||
Alloc CA(P); | Alloc CA(P); | ||||
SA A(CA); | SA A(CA); | ||||
A.construct(ptr, std::piecewise_construct, | A.construct(ptr, std::piecewise_construct, | ||||
std::forward_as_tuple(x), | std::forward_as_tuple(x), | ||||
std::forward_as_tuple(std::move(y))); | std::forward_as_tuple(std::move(y))); | ||||
assert(checkConstruct<int&>(ptr->first, UA_AllocArg, CA)); | assert(checkConstruct<int&>(ptr->first, UA_AllocArg, CA)); | ||||
assert(checkConstruct<int const&&>(ptr->second, UA_AllocLast, CA)); | assert(checkConstruct<int const&&>(ptr->second, UA_AllocLast, CA)); | ||||
assert((P.checkConstruct<std::piecewise_construct_t const&, | assert((P.checkConstruct<std::piecewise_construct_t&&, | ||||
std::tuple<std::allocator_arg_t, SA&, int&>&&, | std::tuple<std::allocator_arg_t const&, SA const&, int&>&&, | ||||
std::tuple<int const&&, SA&>&& | std::tuple<int const&&, SA const&>&& | ||||
>(CA, ptr))); | >(CA, ptr))); | ||||
A.destroy(ptr); | A.destroy(ptr); | ||||
std::free(ptr); | std::free(ptr); | ||||
} | } | ||||
P.reset(); | P.reset(); | ||||
{ | { | ||||
using T = UsesAllocatorV3<VoidAlloc, 1>; | using T = UsesAllocatorV3<VoidAlloc, 1>; | ||||
using U = NotUsesAllocator<VoidAlloc, 1>; | using U = NotUsesAllocator<VoidAlloc, 1>; | ||||
using Pair = std::pair<T, U>; | using Pair = std::pair<T, U>; | ||||
int x = 42; | int x = 42; | ||||
const int y = 101; | const int y = 101; | ||||
using Alloc = CountingAllocator<Pair>; | using Alloc = CountingAllocator<Pair>; | ||||
using SA = std::scoped_allocator_adaptor<Alloc>; | using SA = std::scoped_allocator_adaptor<Alloc>; | ||||
static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, ""); | static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, ""); | ||||
Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); | Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); | ||||
assert(ptr != nullptr); | assert(ptr != nullptr); | ||||
Alloc CA(P); | Alloc CA(P); | ||||
SA A(CA); | SA A(CA); | ||||
A.construct(ptr, std::piecewise_construct, | A.construct(ptr, std::piecewise_construct, | ||||
std::forward_as_tuple(std::move(x)), | std::forward_as_tuple(std::move(x)), | ||||
std::forward_as_tuple(y)); | std::forward_as_tuple(y)); | ||||
assert(checkConstruct<int&&>(ptr->first, UA_AllocArg, CA)); | assert(checkConstruct<int&&>(ptr->first, UA_AllocArg, CA)); | ||||
assert(checkConstruct<int const&>(ptr->second, UA_None)); | assert(checkConstruct<int const&>(ptr->second, UA_None)); | ||||
assert((P.checkConstruct<std::piecewise_construct_t const&, | assert((P.checkConstruct<std::piecewise_construct_t&&, | ||||
std::tuple<std::allocator_arg_t, SA&, int&&>&&, | std::tuple<std::allocator_arg_t const&, SA const&, int&&>&&, | ||||
std::tuple<int const&>&& | std::tuple<int const&>&& | ||||
>(CA, ptr))); | >(CA, ptr))); | ||||
A.destroy(ptr); | A.destroy(ptr); | ||||
std::free(ptr); | std::free(ptr); | ||||
} | } | ||||
} | } | ||||
void test_with_inner_alloc() | void test_with_inner_alloc() | ||||
Show All 19 Lines | AllocController PInner; | ||||
Outer O(POuter); | Outer O(POuter); | ||||
Inner I(PInner); | Inner I(PInner); | ||||
SA A(O, I); | SA A(O, I); | ||||
A.construct(ptr, std::piecewise_construct, | A.construct(ptr, std::piecewise_construct, | ||||
std::forward_as_tuple(x), | std::forward_as_tuple(x), | ||||
std::forward_as_tuple(std::move(y))); | std::forward_as_tuple(std::move(y))); | ||||
assert(checkConstruct<int&>(ptr->first, UA_AllocArg, I)); | assert(checkConstruct<int&>(ptr->first, UA_AllocArg, I)); | ||||
assert(checkConstruct<int &&>(ptr->second, UA_AllocLast)); | assert(checkConstruct<int &&>(ptr->second, UA_AllocLast)); | ||||
assert((POuter.checkConstruct<std::piecewise_construct_t const&, | assert((POuter.checkConstruct<std::piecewise_construct_t&&, | ||||
std::tuple<std::allocator_arg_t, SAInner&, int&>&&, | std::tuple<std::allocator_arg_t const&, SAInner const&, int&>&&, | ||||
std::tuple<int &&, SAInner&>&& | std::tuple<int &&, SAInner const&>&& | ||||
>(O, ptr))); | >(O, ptr))); | ||||
A.destroy(ptr); | A.destroy(ptr); | ||||
std::free(ptr); | std::free(ptr); | ||||
} | } | ||||
PInner.reset(); | PInner.reset(); | ||||
POuter.reset(); | POuter.reset(); | ||||
{ | { | ||||
using T = UsesAllocatorV3<VoidAlloc2, 1>; | using T = UsesAllocatorV3<VoidAlloc2, 1>; | ||||
Show All 12 Lines | POuter.reset(); | ||||
Outer O(POuter); | Outer O(POuter); | ||||
Inner I(PInner); | Inner I(PInner); | ||||
SA A(O, I); | SA A(O, I); | ||||
A.construct(ptr, std::piecewise_construct, | A.construct(ptr, std::piecewise_construct, | ||||
std::forward_as_tuple(std::move(x)), | std::forward_as_tuple(std::move(x)), | ||||
std::forward_as_tuple(std::move(y))); | std::forward_as_tuple(std::move(y))); | ||||
assert(checkConstruct<int&&>(ptr->first, UA_AllocArg, I)); | assert(checkConstruct<int&&>(ptr->first, UA_AllocArg, I)); | ||||
assert(checkConstruct<int const&&>(ptr->second, UA_None)); | assert(checkConstruct<int const&&>(ptr->second, UA_None)); | ||||
assert((POuter.checkConstruct<std::piecewise_construct_t const&, | assert((POuter.checkConstruct<std::piecewise_construct_t&&, | ||||
std::tuple<std::allocator_arg_t, SAInner&, int&&>&&, | std::tuple<std::allocator_arg_t const&, SAInner const&, int&&>&&, | ||||
std::tuple<int const&&>&& | std::tuple<int const&&>&& | ||||
>(O, ptr))); | >(O, ptr))); | ||||
A.destroy(ptr); | A.destroy(ptr); | ||||
std::free(ptr); | std::free(ptr); | ||||
} | } | ||||
} | } | ||||
int main(int, char**) { | int main(int, char**) { | ||||
test_no_inner_alloc(); | test_no_inner_alloc(); | ||||
test_with_inner_alloc(); | test_with_inner_alloc(); | ||||
return 0; | return 0; | ||||
} | } |