1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // <memory>
10
11 // template <class Alloc>
12 // struct allocator_traits
13 // {
14 // template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>;
15 // ...
16 // };
17
18 #include <memory>
19 #include <type_traits>
20
21 #include "test_macros.h"
22
23 template <class T>
24 struct ReboundA {};
25
26 template <class T>
27 struct A
28 {
29 typedef T value_type;
30
31 template <class U> struct rebind {typedef ReboundA<U> other;};
32 };
33
34 template <class T, class U>
35 struct ReboundB {};
36
37 template <class T, class U>
38 struct B
39 {
40 typedef T value_type;
41
42 template <class V> struct rebind {typedef ReboundB<V, U> other;};
43 };
44
45 template <class T>
46 struct C
47 {
48 typedef T value_type;
49 };
50
51 template <class T, class U>
52 struct D
53 {
54 typedef T value_type;
55 };
56
57 template <class T>
58 struct E
59 {
60 typedef T value_type;
61
62 template <class U> struct rebind {typedef ReboundA<U> otter;};
63 };
64
65 template <class T>
66 struct F {
67 typedef T value_type;
68 private:
69 template <class>
70 struct rebind { typedef void other; };
71 };
72
73 template <class T>
74 struct G {
75 typedef T value_type;
76 template <class>
77 struct rebind {
78 private:
79 typedef void other;
80 };
81 };
82
main(int,char **)83 int main(int, char**)
84 {
85 #if TEST_STD_VER >= 11
86 static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_alloc<double>, ReboundA<double> >::value), "");
87 static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_alloc<double>, ReboundB<double, char> >::value), "");
88 static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_alloc<double>, C<double> >::value), "");
89 static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_alloc<double>, D<double, char> >::value), "");
90 static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_alloc<double>, E<double> >::value), "");
91 static_assert((std::is_same<std::allocator_traits<F<char> >::rebind_alloc<double>, F<double> >::value), "");
92 static_assert((std::is_same<std::allocator_traits<G<char> >::rebind_alloc<double>, G<double> >::value), "");
93 #else
94 static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_alloc<double>::other, ReboundA<double> >::value), "");
95 static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_alloc<double>::other, ReboundB<double, char> >::value), "");
96 static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_alloc<double>::other, C<double> >::value), "");
97 static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_alloc<double>::other, D<double, char> >::value), "");
98 static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_alloc<double>::other, E<double> >::value), "");
99 #endif
100
101 return 0;
102 }
103