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::difference_type
     16 //           | pointer_traits<pointer>::difference_type         difference_type;
     17 //     ...
     18 // };
     19 
     20 #include <memory>
     21 #include <type_traits>
     22 
     23 #include "test_macros.h"
     24 
     25 template <class T>
     26 struct A
     27 {
     28     typedef T value_type;
     29     typedef short difference_type;
     30 };
     31 
     32 template <class T>
     33 struct B
     34 {
     35     typedef T value_type;
     36 };
     37 
     38 template <class T>
     39 struct C
     40 {
     41     typedef T value_type;
     42     struct pointer {};
     43     struct const_pointer {};
     44     struct void_pointer {};
     45     struct const_void_pointer {};
     46 };
     47 
     48 
     49 template <class T>
     50 struct D
     51 {
     52     typedef T value_type;
     53 private:
     54     typedef void difference_type;
     55 };
     56 
     57 namespace std
     58 {
     59 
     60 template <>
     61 struct pointer_traits<C<char>::pointer>
     62 {
     63     typedef C<char>::pointer pointer;
     64     typedef char             element_type;
     65     typedef signed char      difference_type;
     66 };
     67 
     68 }
     69 
     70 int main()
     71 {
     72     static_assert((std::is_same<std::allocator_traits<A<char> >::difference_type, short>::value), "");
     73     static_assert((std::is_same<std::allocator_traits<B<char> >::difference_type, std::ptrdiff_t>::value), "");
     74     static_assert((std::is_same<std::allocator_traits<C<char> >::difference_type, signed char>::value), "");
     75 #if TEST_STD_VER >= 11
     76     static_assert((std::is_same<std::allocator_traits<D<char> >::difference_type, std::ptrdiff_t>::value), "");
     77 #endif
     78 }
     79