//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03 // // template // class scoped_allocator_adaptor // template void construct(T* p, Args&&... args); #include #include #include #include "test_macros.h" #include "allocators.h" 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; int main(int, char**) { { 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(); } return 0; }