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