//===----------------------------------------------------------------------===// // // 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. // //===----------------------------------------------------------------------===// // // template // class scoped_allocator_adaptor // template void construct(T* p, Args&&... args); #include #include #include #include "allocators.h" #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES struct B { static bool constructed; typedef A1 allocator_type; explicit B(std::allocator_arg_t, const allocator_type& a, int i) { assert(a.id() == 5); assert(i == 6); constructed = true; } }; bool B::constructed = false; struct C { static bool constructed; typedef std::scoped_allocator_adaptor> allocator_type; explicit C(std::allocator_arg_t, const allocator_type& a, int i) { assert(a.id() == 7); assert(i == 8); constructed = true; } }; bool C::constructed = false; struct D { static bool constructed; typedef std::scoped_allocator_adaptor> allocator_type; explicit D(int i, int j, const allocator_type& a) { assert(i == 1); assert(j == 2); assert(a.id() == 3); constructed = true; } }; bool D::constructed = false; struct E { static bool constructed; typedef std::scoped_allocator_adaptor> allocator_type; explicit E(int i, int j, const allocator_type& a) { assert(i == 1); assert(j == 2); assert(a.id() == 50); constructed = true; } }; bool E::constructed = false; struct F { static bool constructed; typedef std::scoped_allocator_adaptor> allocator_type; explicit F(int i, int j) { assert(i == 1); assert(j == 2); } explicit F(int i, int j, const allocator_type& a) { assert(i == 1); assert(j == 2); assert(a.id() == 50); constructed = true; } }; bool F::constructed = false; #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES int main() { #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES { typedef std::scoped_allocator_adaptor> A; A a; char buf[100]; typedef std::string S; S* s = (S*)buf; a.construct(s, 4, 'c'); assert(*s == "cccc"); s->~S(); } { typedef std::scoped_allocator_adaptor> A; A a(A1(5)); char buf[100]; typedef B S; S* s = (S*)buf; a.construct(s, 6); assert(S::constructed); s->~S(); } { typedef std::scoped_allocator_adaptor, A2> A; A a(A1(5), A2(7)); char buf[100]; typedef C S; S* s = (S*)buf; a.construct(s, 8); assert(S::constructed); s->~S(); } { typedef std::scoped_allocator_adaptor, A2> A; A a(A1(5), A2(3)); char buf[100]; typedef D S; S* s = (S*)buf; a.construct(s, 1, 2); assert(S::constructed); s->~S(); } { typedef std::scoped_allocator_adaptor, A2> K; typedef std::scoped_allocator_adaptor> A; A a(K(), A1(50)); char buf[100]; typedef E S; S* s = (S*)buf; A3::constructed = false; a.construct(s, 1, 2); assert(S::constructed); assert(A3::constructed); s->~S(); } { typedef std::scoped_allocator_adaptor, A2> K; typedef std::scoped_allocator_adaptor> A; A a(K(), A1(50)); char buf[100]; typedef F S; S* s = (S*)buf; A3::constructed = false; a.construct(s, 1, 2); assert(!S::constructed); assert(A3::constructed); s->~S(); } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES }