Richard Smith | ae71165 | 2015-10-08 20:34:11 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===--------------------------- __nullptr --------------------------------===// |
| 3 | // |
Chandler Carruth | d201210 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Richard Smith | ae71165 | 2015-10-08 20:34:11 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_NULLPTR |
| 11 | #define _LIBCPP_NULLPTR |
| 12 | |
| 13 | #include <__config> |
| 14 | |
| 15 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 16 | #pragma GCC system_header |
| 17 | #endif |
| 18 | |
| 19 | #ifdef _LIBCPP_HAS_NO_NULLPTR |
| 20 | |
| 21 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 22 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 23 | struct _LIBCPP_TEMPLATE_VIS nullptr_t |
Richard Smith | ae71165 | 2015-10-08 20:34:11 +0000 | [diff] [blame] | 24 | { |
| 25 | void* __lx; |
| 26 | |
| 27 | struct __nat {int __for_bool_;}; |
| 28 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 29 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t() : __lx(0) {} |
| 30 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t(int __nat::*) : __lx(0) {} |
Richard Smith | ae71165 | 2015-10-08 20:34:11 +0000 | [diff] [blame] | 31 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 32 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR operator int __nat::*() const {return 0;} |
Richard Smith | ae71165 | 2015-10-08 20:34:11 +0000 | [diff] [blame] | 33 | |
| 34 | template <class _Tp> |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 35 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Richard Smith | ae71165 | 2015-10-08 20:34:11 +0000 | [diff] [blame] | 36 | operator _Tp* () const {return 0;} |
| 37 | |
| 38 | template <class _Tp, class _Up> |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 39 | _LIBCPP_INLINE_VISIBILITY |
Richard Smith | ae71165 | 2015-10-08 20:34:11 +0000 | [diff] [blame] | 40 | operator _Tp _Up::* () const {return 0;} |
| 41 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 42 | friend _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator==(nullptr_t, nullptr_t) {return true;} |
| 43 | friend _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator!=(nullptr_t, nullptr_t) {return false;} |
Richard Smith | ae71165 | 2015-10-08 20:34:11 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 46 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t __get_nullptr_t() {return nullptr_t(0);} |
Richard Smith | ae71165 | 2015-10-08 20:34:11 +0000 | [diff] [blame] | 47 | |
| 48 | #define nullptr _VSTD::__get_nullptr_t() |
| 49 | |
| 50 | _LIBCPP_END_NAMESPACE_STD |
| 51 | |
| 52 | #else // _LIBCPP_HAS_NO_NULLPTR |
| 53 | |
| 54 | namespace std |
| 55 | { |
| 56 | typedef decltype(nullptr) nullptr_t; |
| 57 | } |
| 58 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 59 | #endif // _LIBCPP_HAS_NO_NULLPTR |
Richard Smith | ae71165 | 2015-10-08 20:34:11 +0000 | [diff] [blame] | 60 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 61 | #endif // _LIBCPP_NULLPTR |