pointer_to.pass.cpp 1.2 KB

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