1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is dual licensed under the MIT and the University of Illinois Open 6// Source Licenses. 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_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{ 66#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 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), ""); 72#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES 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), ""); 78#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES 79} 80