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 Ptr> |
| 13 | // struct pointer_traits |
| 14 | // { |
| 15 | // template <class U> using rebind = <details>; |
| 16 | // ... |
| 17 | // }; |
| 18 | |
| 19 | #include <memory> |
| 20 | #include <type_traits> |
| 21 | |
| 22 | template <class T> |
| 23 | struct A |
| 24 | { |
| 25 | }; |
| 26 | |
| 27 | template <class T> struct B1 {}; |
| 28 | |
| 29 | template <class T> |
| 30 | struct B |
| 31 | { |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 32 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 33 | template <class U> using rebind = B1<U>; |
| 34 | #else |
| 35 | template <class U> struct rebind {typedef B1<U> other;}; |
| 36 | #endif |
| 37 | }; |
| 38 | |
| 39 | template <class T, class U> |
| 40 | struct C |
| 41 | { |
| 42 | }; |
| 43 | |
| 44 | template <class T, class U> struct D1 {}; |
| 45 | |
| 46 | template <class T, class U> |
| 47 | struct D |
| 48 | { |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 49 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 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 | |
| 56 | int main() |
| 57 | { |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 58 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 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), ""); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 63 | #else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 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), ""); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 68 | #endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 69 | } |