__nullptr 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP_NULLPTR
  10. #define _LIBCPP_NULLPTR
  11. #include <__config>
  12. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  13. #pragma GCC system_header
  14. #endif
  15. #ifdef _LIBCPP_HAS_NO_NULLPTR
  16. _LIBCPP_BEGIN_NAMESPACE_STD
  17. struct _LIBCPP_TEMPLATE_VIS nullptr_t
  18. {
  19. void* __lx;
  20. struct __nat {int __for_bool_;};
  21. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t() : __lx(0) {}
  22. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t(int __nat::*) : __lx(0) {}
  23. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR operator int __nat::*() const {return 0;}
  24. template <class _Tp>
  25. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
  26. operator _Tp* () const {return 0;}
  27. template <class _Tp, class _Up>
  28. _LIBCPP_INLINE_VISIBILITY
  29. operator _Tp _Up::* () const {return 0;}
  30. friend _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator==(nullptr_t, nullptr_t) {return true;}
  31. friend _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator!=(nullptr_t, nullptr_t) {return false;}
  32. };
  33. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t __get_nullptr_t() {return nullptr_t(0);}
  34. #define nullptr _VSTD::__get_nullptr_t()
  35. _LIBCPP_END_NAMESPACE_STD
  36. #else // _LIBCPP_HAS_NO_NULLPTR
  37. namespace std
  38. {
  39. typedef decltype(nullptr) nullptr_t;
  40. } // namespace std
  41. #endif // _LIBCPP_HAS_NO_NULLPTR
  42. #endif // _LIBCPP_NULLPTR