Home | History | Annotate | Download | only in allocator.traits.types
      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 //     typedef Alloc::void_pointer
     16 //           | pointer_traits<pointer>::rebind<void>
     17 //                                          void_pointer;
     18 //     ...
     19 // };
     20 
     21 #include <memory>
     22 #include <type_traits>
     23 #include "test_macros.h"
     24 
     25 template <class T>
     26 struct Ptr {};
     27 
     28 template <class T>
     29 struct A
     30 {
     31     typedef T value_type;
     32     typedef Ptr<T> pointer;
     33 };
     34 
     35 template <class T>
     36 struct B
     37 {
     38     typedef T value_type;
     39 };
     40 
     41 template <class T>
     42 struct CPtr {};
     43 
     44 template <class T>
     45 struct C
     46 {
     47     typedef T value_type;
     48     typedef CPtr<void> void_pointer;
     49 };
     50 
     51 
     52 template <class T>
     53 struct D
     54 {
     55     typedef T value_type;
     56 private:
     57     typedef void void_pointer;
     58 };
     59 
     60 int main()
     61 {
     62     static_assert((std::is_same<std::allocator_traits<A<char> >::void_pointer, Ptr<void> >::value), "");
     63     static_assert((std::is_same<std::allocator_traits<B<char> >::void_pointer, void*>::value), "");
     64     static_assert((std::is_same<std::allocator_traits<C<char> >::void_pointer, CPtr<void> >::value), "");
     65 #if TEST_STD_VER >= 11
     66     static_assert((std::is_same<std::allocator_traits<D<char> >::void_pointer, void*>::value), "");
     67 #endif
     68 }
     69