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