rebind_traits.pass.cpp revision bc8d3f97eb5c958007f2713238472e0c1c8fe02c
1//===----------------------------------------------------------------------===//
2//
3// ��������������������The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. 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
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{
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
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
79}
80