blob: e1475116423750f36225bb431078e3cb8cdfc789 [file] [log] [blame]
Richard Smithae711652015-10-08 20:34:11 +00001// -*- C++ -*-
2//===--------------------------- __nullptr --------------------------------===//
3//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// 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 Smithae711652015-10-08 20:34:11 +00007//
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 Fiselierb5eb1bf2017-01-04 23:56:00 +000023struct _LIBCPP_TEMPLATE_VIS nullptr_t
Richard Smithae711652015-10-08 20:34:11 +000024{
25 void* __lx;
26
27 struct __nat {int __for_bool_;};
28
Louis Dionne16fe2952018-07-11 23:14:33 +000029 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t() : __lx(0) {}
30 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t(int __nat::*) : __lx(0) {}
Richard Smithae711652015-10-08 20:34:11 +000031
Louis Dionne16fe2952018-07-11 23:14:33 +000032 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR operator int __nat::*() const {return 0;}
Richard Smithae711652015-10-08 20:34:11 +000033
34 template <class _Tp>
Louis Dionne16fe2952018-07-11 23:14:33 +000035 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Richard Smithae711652015-10-08 20:34:11 +000036 operator _Tp* () const {return 0;}
37
38 template <class _Tp, class _Up>
Louis Dionne16fe2952018-07-11 23:14:33 +000039 _LIBCPP_INLINE_VISIBILITY
Richard Smithae711652015-10-08 20:34:11 +000040 operator _Tp _Up::* () const {return 0;}
41
Louis Dionne16fe2952018-07-11 23:14:33 +000042 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 Smithae711652015-10-08 20:34:11 +000044};
45
Louis Dionne16fe2952018-07-11 23:14:33 +000046inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t __get_nullptr_t() {return nullptr_t(0);}
Richard Smithae711652015-10-08 20:34:11 +000047
48#define nullptr _VSTD::__get_nullptr_t()
49
50_LIBCPP_END_NAMESPACE_STD
51
52#else // _LIBCPP_HAS_NO_NULLPTR
53
54namespace std
55{
56 typedef decltype(nullptr) nullptr_t;
57}
58
Louis Dionne2b1ceaa2021-04-20 12:03:32 -040059#endif // _LIBCPP_HAS_NO_NULLPTR
Richard Smithae711652015-10-08 20:34:11 +000060
Louis Dionne2b1ceaa2021-04-20 12:03:32 -040061#endif // _LIBCPP_NULLPTR