• 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 template <class T>
23 struct ReboundA {};
24 
25 template <class T>
26 struct A
27 {
28     typedef T value_type;
29 
30     template <class U> struct rebind {typedef ReboundA<U> other;};
31 };
32 
33 template <class T, class U>
34 struct ReboundB {};
35 
36 template <class T, class U>
37 struct B
38 {
39     typedef T value_type;
40 
41     template <class V> struct rebind {typedef ReboundB<V, U> other;};
42 };
43 
44 template <class T>
45 struct C
46 {
47     typedef T value_type;
48 };
49 
50 template <class T, class U>
51 struct D
52 {
53     typedef T value_type;
54 };
55 
56 template <class T>
57 struct E
58 {
59     typedef T value_type;
60 
61     template <class U> struct rebind {typedef ReboundA<U> otter;};
62 };
63 
main()64 int main()
65 {
66 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
67     static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_traits<double>, std::allocator_traits<ReboundA<double> > >::value), "");
68     static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_traits<double>, std::allocator_traits<ReboundB<double, char> > >::value), "");
69     static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_traits<double>, std::allocator_traits<C<double> > >::value), "");
70     static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_traits<double>, std::allocator_traits<D<double, char> > >::value), "");
71     static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_traits<double>, std::allocator_traits<E<double> > >::value), "");
72 #else  // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
73     static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_traits<double>::other, std::allocator_traits<ReboundA<double> > >::value), "");
74     static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_traits<double>::other, std::allocator_traits<ReboundB<double, char> > >::value), "");
75     static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_traits<double>::other, std::allocator_traits<C<double> > >::value), "");
76     static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_traits<double>::other, std::allocator_traits<D<double, char> > >::value), "");
77     static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_traits<double>::other, std::allocator_traits<E<double> > >::value), "");
78 #endif  // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
79 }
80