blob: 50611b99da9a8bf2dfd59c02a526be31b8d15d4b [file] [log] [blame]
Howard Hinnantc52f43e2010-08-22 00:59:46 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc52f43e2010-08-22 00:59:46 +00007//
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
22template <class T>
23struct ReboundA {};
24
25template <class T>
26struct A
27{
28 typedef T value_type;
29
30 template <class U> struct rebind {typedef ReboundA<U> other;};
31};
32
33template <class T, class U>
34struct ReboundB {};
35
36template <class T, class U>
37struct B
38{
39 typedef T value_type;
40
41 template <class V> struct rebind {typedef ReboundB<V, U> other;};
42};
43
44template <class T>
45struct C
46{
47 typedef T value_type;
48};
49
50template <class T, class U>
51struct D
52{
53 typedef T value_type;
54};
55
56template <class T>
57struct E
58{
59 typedef T value_type;
60
61 template <class U> struct rebind {typedef ReboundA<U> otter;};
62};
63
64int main()
65{
Dan Albert1d4a1ed2016-05-25 22:36:09 -070066#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnantc52f43e2010-08-22 00:59:46 +000067 static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_alloc<double>, ReboundA<double> >::value), "");
68 static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_alloc<double>, ReboundB<double, char> >::value), "");
69 static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_alloc<double>, C<double> >::value), "");
70 static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_alloc<double>, D<double, char> >::value), "");
71 static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_alloc<double>, E<double> >::value), "");
Dan Albert1d4a1ed2016-05-25 22:36:09 -070072#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnantc52f43e2010-08-22 00:59:46 +000073 static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_alloc<double>::other, ReboundA<double> >::value), "");
74 static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_alloc<double>::other, ReboundB<double, char> >::value), "");
75 static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_alloc<double>::other, C<double> >::value), "");
76 static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_alloc<double>::other, D<double, char> >::value), "");
77 static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_alloc<double>::other, E<double> >::value), "");
Dan Albert1d4a1ed2016-05-25 22:36:09 -070078#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnantc52f43e2010-08-22 00:59:46 +000079}