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