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