__nullptr 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // -*- C++ -*-
  2. //===--------------------------- __nullptr --------------------------------===//
  3. //
  4. // The LLVM Compiler Infrastructure
  5. //
  6. // This file is dual licensed under the MIT and the University of Illinois Open
  7. // Source Licenses. See LICENSE.TXT for details.
  8. //
  9. //===----------------------------------------------------------------------===//
  10. #ifndef _LIBCPP_NULLPTR
  11. #define _LIBCPP_NULLPTR
  12. #include <__config>
  13. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  14. #pragma GCC system_header
  15. #endif
  16. #ifdef _LIBCPP_HAS_NO_NULLPTR
  17. _LIBCPP_BEGIN_NAMESPACE_STD
  18. struct _LIBCPP_TYPE_VIS_ONLY nullptr_t
  19. {
  20. void* __lx;
  21. struct __nat {int __for_bool_;};
  22. _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t() : __lx(0) {}
  23. _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t(int __nat::*) : __lx(0) {}
  24. _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR operator int __nat::*() const {return 0;}
  25. template <class _Tp>
  26. _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR
  27. operator _Tp* () const {return 0;}
  28. template <class _Tp, class _Up>
  29. _LIBCPP_ALWAYS_INLINE
  30. operator _Tp _Up::* () const {return 0;}
  31. friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator==(nullptr_t, nullptr_t) {return true;}
  32. friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator!=(nullptr_t, nullptr_t) {return false;}
  33. friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator<(nullptr_t, nullptr_t) {return false;}
  34. friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator<=(nullptr_t, nullptr_t) {return true;}
  35. friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator>(nullptr_t, nullptr_t) {return false;}
  36. friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator>=(nullptr_t, nullptr_t) {return true;}
  37. };
  38. inline _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t __get_nullptr_t() {return nullptr_t(0);}
  39. #define nullptr _VSTD::__get_nullptr_t()
  40. _LIBCPP_END_NAMESPACE_STD
  41. #else // _LIBCPP_HAS_NO_NULLPTR
  42. namespace std
  43. {
  44. typedef decltype(nullptr) nullptr_t;
  45. }
  46. #endif // _LIBCPP_HAS_NO_NULLPTR
  47. #endif // _LIBCPP_NULLPTR