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::const_pointer
     16 //           | pointer_traits<pointer>::rebind<const value_type>
     17 //     ...
     18 // };
     19 
     20 #include <memory>
     21 #include <type_traits>
     22 
     23 template <class T>
     24 struct Ptr {};
     25 
     26 template <class T>
     27 struct A
     28 {
     29     typedef T value_type;
     30     typedef Ptr<T> pointer;
     31 };
     32 
     33 template <class T>
     34 struct B
     35 {
     36     typedef T value_type;
     37 };
     38 
     39 template <class T>
     40 struct CPtr {};
     41 
     42 template <class T>
     43 struct C
     44 {
     45     typedef T value_type;
     46     typedef CPtr<T> pointer;
     47     typedef CPtr<const T> const_pointer;
     48 };
     49 
     50 int main()
     51 {
     52     static_assert((std::is_same<std::allocator_traits<A<char> >::const_pointer, Ptr<const char> >::value), "");
     53     static_assert((std::is_same<std::allocator_traits<B<char> >::const_pointer, const char*>::value), "");
     54     static_assert((std::is_same<std::allocator_traits<C<char> >::const_pointer, CPtr<const char> >::value), "");
     55 }
     56