Home | History | Annotate | Download | only in allocator.traits.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 Alloc>
     13 // struct allocator_traits
     14 // {
     15 //     template <class Ptr>
     16 //         static void destroy(allocator_type& a, Ptr p);
     17 //     ...
     18 // };
     19 
     20 #include <memory>
     21 #include <new>
     22 #include <type_traits>
     23 #include <cassert>
     24 
     25 template <class T>
     26 struct A
     27 {
     28     typedef T value_type;
     29 
     30 };
     31 
     32 int b_destroy = 0;
     33 
     34 template <class T>
     35 struct B
     36 {
     37     typedef T value_type;
     38 
     39     template <class U>
     40     void destroy(U* p)
     41     {
     42         ++b_destroy;
     43         p->~U();
     44     }
     45 };
     46 
     47 struct A0
     48 {
     49     static int count;
     50     ~A0() {++count;}
     51 };
     52 
     53 int A0::count = 0;
     54 
     55 int main()
     56 {
     57     {
     58         A0::count = 0;
     59         A<int> a;
     60         std::aligned_storage<sizeof(A0)>::type a0;
     61         std::allocator_traits<A<int> >::construct(a, (A0*)&a0);
     62         assert(A0::count == 0);
     63         std::allocator_traits<A<int> >::destroy(a, (A0*)&a0);
     64         assert(A0::count == 1);
     65     }
     66 #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
     67     {
     68         A0::count = 0;
     69         b_destroy = 0;
     70         B<int> b;
     71         std::aligned_storage<sizeof(A0)>::type a0;
     72         std::allocator_traits<B<int> >::construct(b, (A0*)&a0);
     73         assert(A0::count == 0);
     74         assert(b_destroy == 0);
     75         std::allocator_traits<B<int> >::destroy(b, (A0*)&a0);
     76         assert(A0::count == 1);
     77         assert(b_destroy == 1);
     78     }
     79 #endif  // _LIBCPP_HAS_NO_ADVANCED_SFINAE
     80 }
     81