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 #include <type_traits> 21 22 #include "test_macros.h" 23 24 template <class T> 25 struct A 26 { 27 private: 28 struct nat {}; 29 public: 30 typedef T element_type; 31 element_type* t_; 32 33 A(element_type* t) : t_(t) {} 34 35 static A pointer_to(typename std::conditional<std::is_void<element_type>::value, 36 nat, element_type>::type& et) 37 {return A(&et);} 38 }; 39 40 int main(int, char**) 41 { 42 { 43 int i = 0; 44 static_assert((std::is_same<A<int>, decltype(std::pointer_traits<A<int> >::pointer_to(i))>::value), ""); 45 A<int> a = std::pointer_traits<A<int> >::pointer_to(i); 46 assert(a.t_ == &i); 47 } 48 { 49 (std::pointer_traits<A<void> >::element_type)0; 50 } 51 52 return 0; 53 } 54