Home | History | Annotate | Download | only in allocator.adaptor.members
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // UNSUPPORTED: c++98, c++03
     11 
     12 // <memory>
     13 
     14 // template <class OuterAlloc, class... InnerAllocs>
     15 //   class scoped_allocator_adaptor
     16 
     17 // template <class T> void destroy(T* p);
     18 
     19 #include <scoped_allocator>
     20 #include <cassert>
     21 #include <string>
     22 
     23 #include "allocators.h"
     24 
     25 struct B
     26 {
     27     static bool constructed;
     28 
     29     B() {constructed = true;}
     30     ~B() {constructed = false;}
     31 };
     32 
     33 bool B::constructed = false;
     34 
     35 int main()
     36 {
     37     {
     38         typedef std::scoped_allocator_adaptor<A1<B>> A;
     39         A a;
     40         char buf[100];
     41         typedef B S;
     42         S* s = (S*)buf;
     43         assert(!S::constructed);
     44         a.construct(s);
     45         assert(S::constructed);
     46         a.destroy(s);
     47         assert(!S::constructed);
     48     }
     49 
     50     {
     51         typedef std::scoped_allocator_adaptor<A3<B>, A1<B>> A;
     52         A a;
     53         char buf[100];
     54         typedef B S;
     55         S* s = (S*)buf;
     56         assert(!S::constructed);
     57         assert(!A3<S>::constructed);
     58         assert(!A3<S>::destroy_called);
     59         a.construct(s);
     60         assert(S::constructed);
     61         assert(A3<S>::constructed);
     62         assert(!A3<S>::destroy_called);
     63         a.destroy(s);
     64         assert(!S::constructed);
     65         assert(A3<S>::constructed);
     66         assert(A3<S>::destroy_called);
     67     }
     68 
     69 }
     70