1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // <memory> 10 11 // template <class Ptr> 12 // struct pointer_traits 13 // { 14 // static pointer pointer_to(<details>); 15 // ... 16 // }; 17 18 #include <memory> 19 #include <cassert> 20 21 template <class T> 22 struct A 23 { 24 private: 25 struct nat {}; 26 public: 27 typedef T element_type; 28 element_type* t_; 29 30 A(element_type* t) : t_(t) {} 31 32 static A pointer_to(typename std::conditional<std::is_void<element_type>::value, 33 nat, element_type>::type& et) 34 {return A(&et);} 35 }; 36 37 int main() 38 { 39 { 40 int i = 0; 41 static_assert((std::is_same<A<int>, decltype(std::pointer_traits<A<int> >::pointer_to(i))>::value), ""); 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