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 // scoped_allocator_adaptor select_on_container_copy_construction() const;
     18 
     19 #include <scoped_allocator>
     20 #include <cassert>
     21 
     22 #include "allocators.h"
     23 
     24 int main()
     25 {
     26     {
     27         typedef std::scoped_allocator_adaptor<A1<int>> A;
     28         A a1(A1<int>(3));
     29         assert(a1.outer_allocator().id() == 3);
     30         A a2 = std::allocator_traits<A>::select_on_container_copy_construction(a1);
     31         assert(a2.outer_allocator().id() == 3);
     32     }
     33 
     34     {
     35         typedef std::scoped_allocator_adaptor<A3<int>> A;
     36         A a1(A3<int>(3));
     37         assert(a1.outer_allocator().id() == 3);
     38         A a2 = std::allocator_traits<A>::select_on_container_copy_construction(a1);
     39         assert(a2.outer_allocator().id() == -1);
     40     }
     41 
     42     {
     43         typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A;
     44         A a1(A1<int>(1), A2<int>(2), A3<int>(3));
     45         assert(a1.outer_allocator().id() == 1);
     46         assert(a1.inner_allocator().outer_allocator().id() == 2);
     47         assert(a1.inner_allocator().inner_allocator().outer_allocator().id() == 3);
     48         A a2 = std::allocator_traits<A>::select_on_container_copy_construction(a1);
     49         assert(a2.outer_allocator().id() == 1);
     50         assert(a2.inner_allocator().outer_allocator().id() == 2);
     51         assert(a2.inner_allocator().inner_allocator().outer_allocator().id() == -1);
     52     }
     53 
     54 }
     55