• 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 //     static pointer pointer_to(<details>);
16 //     ...
17 // };
18 
19 #include <memory>
20 #include <cassert>
21 
22 template <class T>
23 struct A
24 {
25 private:
26     struct nat {};
27 public:
28     typedef T element_type;
29     element_type* t_;
30 
AA31     A(element_type* t) : t_(t) {}
32 
pointer_toA33     static A pointer_to(typename std::conditional<std::is_void<element_type>::value,
34                                            nat, element_type>::type& et)
35         {return A(&et);}
36 };
37 
main()38 int main()
39 {
40     {
41         int i = 0;
42         static_assert((std::is_same<A<int>, decltype(std::pointer_traits<A<int> >::pointer_to(i))>::value), "");
43         A<int> a = std::pointer_traits<A<int> >::pointer_to(i);
44         assert(a.t_ == &i);
45     }
46     {
47         (std::pointer_traits<A<void> >::element_type)0;
48     }
49 }
50