//===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03 // // template // class scoped_allocator_adaptor // template // void scoped_allocator_adaptor::construct(pair*, // piecewise_construct_t, tuple, tuple) #include #include #include #include #include #include #include "uses_alloc_types.hpp" #include "controlled_allocators.hpp" void test_no_inner_alloc() { using VoidAlloc = CountingAllocator; AllocController P; { using T = UsesAllocatorV1; using U = UsesAllocatorV2; using Pair = std::pair; int x = 42; const int y = 101; using Alloc = CountingAllocator; using SA = std::scoped_allocator_adaptor; static_assert(std::uses_allocator >::value, ""); Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); assert(ptr != nullptr); Alloc CA(P); SA A(CA); A.construct(ptr, std::piecewise_construct, std::forward_as_tuple(x), std::forward_as_tuple(std::move(y))); assert(checkConstruct(ptr->first, UA_AllocArg, CA)); assert(checkConstruct(ptr->second, UA_AllocLast, CA)); assert((P.checkConstruct&&, std::tuple&& >(CA, ptr))); A.destroy(ptr); std::free(ptr); } P.reset(); { using T = UsesAllocatorV3; using U = NotUsesAllocator; using Pair = std::pair; int x = 42; const int y = 101; using Alloc = CountingAllocator; using SA = std::scoped_allocator_adaptor; static_assert(std::uses_allocator >::value, ""); Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); assert(ptr != nullptr); Alloc CA(P); SA A(CA); A.construct(ptr, std::piecewise_construct, std::forward_as_tuple(std::move(x)), std::forward_as_tuple(y)); assert(checkConstruct(ptr->first, UA_AllocArg, CA)); assert(checkConstruct(ptr->second, UA_None)); assert((P.checkConstruct&&, std::tuple&& >(CA, ptr))); A.destroy(ptr); std::free(ptr); } } void test_with_inner_alloc() { using VoidAlloc2 = CountingAllocator; AllocController POuter; AllocController PInner; { using T = UsesAllocatorV1; using U = UsesAllocatorV2; using Pair = std::pair; int x = 42; int y = 101; using Outer = CountingAllocator; using Inner = CountingAllocator; using SA = std::scoped_allocator_adaptor; using SAInner = std::scoped_allocator_adaptor; static_assert(!std::uses_allocator::value, ""); static_assert(std::uses_allocator::value, ""); Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); assert(ptr != nullptr); Outer O(POuter); Inner I(PInner); SA A(O, I); A.construct(ptr, std::piecewise_construct, std::forward_as_tuple(x), std::forward_as_tuple(std::move(y))); assert(checkConstruct(ptr->first, UA_AllocArg, I)); assert(checkConstruct(ptr->second, UA_AllocLast)); assert((POuter.checkConstruct&&, std::tuple&& >(O, ptr))); A.destroy(ptr); std::free(ptr); } PInner.reset(); POuter.reset(); { using T = UsesAllocatorV3; using U = NotUsesAllocator; using Pair = std::pair; int x = 42; const int y = 101; using Outer = CountingAllocator; using Inner = CountingAllocator; using SA = std::scoped_allocator_adaptor; using SAInner = std::scoped_allocator_adaptor; static_assert(!std::uses_allocator::value, ""); static_assert(std::uses_allocator::value, ""); Pair * ptr = (Pair*)std::malloc(sizeof(Pair)); assert(ptr != nullptr); Outer O(POuter); Inner I(PInner); SA A(O, I); A.construct(ptr, std::piecewise_construct, std::forward_as_tuple(std::move(x)), std::forward_as_tuple(std::move(y))); assert(checkConstruct(ptr->first, UA_AllocArg, I)); assert(checkConstruct(ptr->second, UA_None)); assert((POuter.checkConstruct&&, std::tuple&& >(O, ptr))); A.destroy(ptr); std::free(ptr); } } int main() { test_no_inner_alloc(); test_with_inner_alloc(); }