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()38int main() 39 { 40 { 41 int i = 0; 42 A<int> a = std::pointer_traits<A<int> >::pointer_to(i); 43 assert(a.t_ == &i); 44 } 45 { 46 (std::pointer_traits<A<void> >::element_type)0; 47 } 48 } 49