• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_traits = allocator_traits<rebind_alloc<T>>;
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 
main()66 int main()
67 {
68 #if TEST_STD_VER >= 11
69     static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_traits<double>, std::allocator_traits<ReboundA<double> > >::value), "");
70     static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_traits<double>, std::allocator_traits<ReboundB<double, char> > >::value), "");
71     static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_traits<double>, std::allocator_traits<C<double> > >::value), "");
72     static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_traits<double>, std::allocator_traits<D<double, char> > >::value), "");
73     static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_traits<double>, std::allocator_traits<E<double> > >::value), "");
74 #else
75     static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_traits<double>::other, std::allocator_traits<ReboundA<double> > >::value), "");
76     static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_traits<double>::other, std::allocator_traits<ReboundB<double, char> > >::value), "");
77     static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_traits<double>::other, std::allocator_traits<C<double> > >::value), "");
78     static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_traits<double>::other, std::allocator_traits<D<double, char> > >::value), "");
79     static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_traits<double>::other, std::allocator_traits<E<double> > >::value), "");
80 #endif
81 }
82