rebind.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 Ptr> 13// struct pointer_traits 14// { 15// template <class U> using rebind = <details>; 16// ... 17// }; 18 19#include <memory> 20#include <type_traits> 21 22template <class T> 23struct A 24{ 25}; 26 27template <class T> struct B1 {}; 28 29template <class T> 30struct B 31{ 32#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 33 template <class U> using rebind = B1<U>; 34#else 35 template <class U> struct rebind {typedef B1<U> other;}; 36#endif 37}; 38 39template <class T, class U> 40struct C 41{ 42}; 43 44template <class T, class U> struct D1 {}; 45 46template <class T, class U> 47struct D 48{ 49#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 50 template <class V> using rebind = D1<V, U>; 51#else 52 template <class V> struct rebind {typedef D1<V, U> other;}; 53#endif 54}; 55 56int main() 57{ 58#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 59 static_assert((std::is_same<std::pointer_traits<A<int*> >::rebind<double*>, A<double*> >::value), ""); 60 static_assert((std::is_same<std::pointer_traits<B<int> >::rebind<double>, B1<double> >::value), ""); 61 static_assert((std::is_same<std::pointer_traits<C<char, int> >::rebind<double>, C<double, int> >::value), ""); 62 static_assert((std::is_same<std::pointer_traits<D<char, int> >::rebind<double>, D1<double, int> >::value), ""); 63#else 64 static_assert((std::is_same<std::pointer_traits<A<int*> >::rebind<double*>::other, A<double*> >::value), ""); 65 static_assert((std::is_same<std::pointer_traits<B<int> >::rebind<double>::other, B1<double> >::value), ""); 66 static_assert((std::is_same<std::pointer_traits<C<char, int> >::rebind<double>::other, C<double, int> >::value), ""); 67 static_assert((std::is_same<std::pointer_traits<D<char, int> >::rebind<double>::other, D1<double, int> >::value), ""); 68#endif 69} 70