123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- //===----------------------------------------------------------------------===//
- //
- // The LLVM Compiler Infrastructure
- //
- // This file is distributed under the University of Illinois Open Source
- // License. See LICENSE.TXT for details.
- //
- //===----------------------------------------------------------------------===//
- // <memory>
- // template <class OuterAlloc, class... InnerAllocs>
- // class scoped_allocator_adaptor
- // template <class T, class... Args> void construct(T* p, Args&&... args);
- #include <scoped_allocator>
- #include <cassert>
- #include <string>
- #include "../allocators.h"
- #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- struct B
- {
- static bool constructed;
- typedef A1<B> 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<A2<C>> 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<A2<D>> 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<A1<E>> 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<A2<F>> 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<A1<std::string>> 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<A1<B>> A;
- A a(A1<B>(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<A1<int>, A2<C>> A;
- A a(A1<int>(5), A2<C>(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<A1<int>, A2<D>> A;
- A a(A1<int>(5), A2<D>(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<A3<E>, A2<E>> K;
- typedef std::scoped_allocator_adaptor<K, A1<E>> A;
- A a(K(), A1<E>(50));
- char buf[100];
- typedef E S;
- S* s = (S*)buf;
- A3<E>::constructed = false;
- a.construct(s, 1, 2);
- assert(S::constructed);
- assert(A3<E>::constructed);
- s->~S();
- }
- {
- typedef std::scoped_allocator_adaptor<A3<F>, A2<F>> K;
- typedef std::scoped_allocator_adaptor<K, A1<F>> A;
- A a(K(), A1<F>(50));
- char buf[100];
- typedef F S;
- S* s = (S*)buf;
- A3<F>::constructed = false;
- a.construct(s, 1, 2);
- assert(!S::constructed);
- assert(A3<F>::constructed);
- s->~S();
- }
- #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- }
|