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 // <memory>
     11 
     12 // template <class OuterAlloc, class... InnerAllocs>
     13 //   class scoped_allocator_adaptor
     14 
     15 // pointer allocate(size_type n, const_void_pointer hint);
     16 
     17 #include <scoped_allocator>
     18 #include <cassert>
     19 
     20 #include "allocators.h"
     21 
     22 int main()
     23 {
     24 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     25 
     26     {
     27         typedef std::scoped_allocator_adaptor<A1<int>> A;
     28         A a;
     29         A1<int>::allocate_called = false;
     30         assert(a.allocate(10, (const void*)0) == (int*)10);
     31         assert(A1<int>::allocate_called == true);
     32     }
     33     {
     34         typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A;
     35         A a;
     36         A1<int>::allocate_called = false;
     37         assert(a.allocate(10, (const void*)10) == (int*)10);
     38         assert(A1<int>::allocate_called == true);
     39     }
     40     {
     41         typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A;
     42         A a;
     43         A1<int>::allocate_called = false;
     44         assert(a.allocate(10, (const void*)20) == (int*)10);
     45         assert(A1<int>::allocate_called == true);
     46     }
     47 
     48     {
     49         typedef std::scoped_allocator_adaptor<A2<int>> A;
     50         A a;
     51         A2<int>::allocate_called = false;
     52         assert(a.allocate(10, (const void*)0) == (int*)0);
     53         assert(A2<int>::allocate_called == true);
     54     }
     55     {
     56         typedef std::scoped_allocator_adaptor<A2<int>, A2<int>> A;
     57         A a;
     58         A2<int>::allocate_called = false;
     59         assert(a.allocate(10, (const void*)10) == (int*)10);
     60         assert(A2<int>::allocate_called == true);
     61     }
     62     {
     63         typedef std::scoped_allocator_adaptor<A2<int>, A2<int>, A3<int>> A;
     64         A a;
     65         A2<int>::allocate_called = false;
     66         assert(a.allocate(10, (const void*)20) == (int*)20);
     67         assert(A2<int>::allocate_called == true);
     68     }
     69 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     70 }
     71