Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 7 | // |
| 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 | |
| 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 | |
| 64 | int main() |
| 65 | { |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 66 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 67 | 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 Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 72 | #else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 73 | 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 Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 78 | #endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 79 | } |