pointer_to.pass.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. // <memory>
  9. // template <class T>
  10. // struct pointer_traits<T*>
  11. // {
  12. // static pointer pointer_to(<details>); // constexpr in C++20
  13. // ...
  14. // };
  15. #include <memory>
  16. #include <cassert>
  17. #include "test_macros.h"
  18. #if TEST_STD_VER > 17
  19. constexpr
  20. #endif
  21. bool check() {
  22. {
  23. int i = 0;
  24. static_assert((std::is_same<int *, decltype(std::pointer_traits<int*>::pointer_to(i))>::value), "");
  25. int* a = std::pointer_traits<int*>::pointer_to(i);
  26. assert(a == &i);
  27. }
  28. {
  29. (std::pointer_traits<void*>::element_type)0;
  30. }
  31. return true;
  32. }
  33. int main(int, char**) {
  34. check();
  35. #if TEST_STD_VER > 17
  36. static_assert(check(), "");
  37. #endif
  38. return 0;
  39. }