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 //     template <class T> using rebind_alloc  = Alloc::rebind<U>::other | Alloc<T, Args...>;
     16 //     ...
     17 // };
     18 
     19 #include <memory>
     20 #include <type_traits>
     21 
     22 #include "test_macros.h"
     23 
     24 template <class T>
     25 struct ReboundA {};
     26 
     27 template <class T>
     28 struct A
     29 {
     30     typedef T value_type;
     31 
     32     template <class U> struct rebind {typedef ReboundA<U> other;};
     33 };
     34 
     35 template <class T, class U>
     36 struct ReboundB {};
     37 
     38 template <class T, class U>
     39 struct B
     40 {
     41     typedef T value_type;
     42 
     43     template <class V> struct rebind {typedef ReboundB<V, U> other;};
     44 };
     45 
     46 template <class T>
     47 struct C
     48 {
     49     typedef T value_type;
     50 };
     51 
     52 template <class T, class U>
     53 struct D
     54 {
     55     typedef T value_type;
     56 };
     57 
     58 template <class T>
     59 struct E
     60 {
     61     typedef T value_type;
     62 
     63     template <class U> struct rebind {typedef ReboundA<U> otter;};
     64 };
     65 
     66 template <class T>
     67 struct F {
     68     typedef T value_type;
     69 private:
     70     template <class>
     71     struct rebind { typedef void other; };
     72 };
     73 
     74 template <class T>
     75 struct G {
     76     typedef T value_type;
     77     template <class>
     78     struct rebind {
     79     private:
     80         typedef void other;
     81     };
     82 };
     83 
     84 int main()
     85 {
     86 #if TEST_STD_VER >= 11
     87     static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_alloc<double>, ReboundA<double> >::value), "");
     88     static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_alloc<double>, ReboundB<double, char> >::value), "");
     89     static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_alloc<double>, C<double> >::value), "");
     90     static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_alloc<double>, D<double, char> >::value), "");
     91     static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_alloc<double>, E<double> >::value), "");
     92     static_assert((std::is_same<std::allocator_traits<F<char> >::rebind_alloc<double>, F<double> >::value), "");
     93     static_assert((std::is_same<std::allocator_traits<G<char> >::rebind_alloc<double>, G<double> >::value), "");
     94 #else
     95     static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_alloc<double>::other, ReboundA<double> >::value), "");
     96     static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_alloc<double>::other, ReboundB<double, char> >::value), "");
     97     static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_alloc<double>::other, C<double> >::value), "");
     98     static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_alloc<double>::other, D<double, char> >::value), "");
     99     static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_alloc<double>::other, E<double> >::value), "");
    100 #endif
    101 }
    102