• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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 {
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 
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 {
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 
main()56 int 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  // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
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  // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
69 }
70