1*0b57cec5SDimitry Andric// -*- C++ -*-
2*0b57cec5SDimitry Andric//===--------------------------- __nullptr --------------------------------===//
3*0b57cec5SDimitry Andric//
4*0b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5*0b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
6*0b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7*0b57cec5SDimitry Andric//
8*0b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
9*0b57cec5SDimitry Andric
10*0b57cec5SDimitry Andric#ifndef _LIBCPP_NULLPTR
11*0b57cec5SDimitry Andric#define _LIBCPP_NULLPTR
12*0b57cec5SDimitry Andric
13*0b57cec5SDimitry Andric#include <__config>
14*0b57cec5SDimitry Andric
15*0b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16*0b57cec5SDimitry Andric#pragma GCC system_header
17*0b57cec5SDimitry Andric#endif
18*0b57cec5SDimitry Andric
19*0b57cec5SDimitry Andric#ifdef _LIBCPP_HAS_NO_NULLPTR
20*0b57cec5SDimitry Andric
21*0b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
22*0b57cec5SDimitry Andric
23*0b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS nullptr_t
24*0b57cec5SDimitry Andric{
25*0b57cec5SDimitry Andric    void* __lx;
26*0b57cec5SDimitry Andric
27*0b57cec5SDimitry Andric    struct __nat {int __for_bool_;};
28*0b57cec5SDimitry Andric
29*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t() : __lx(0) {}
30*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t(int __nat::*) : __lx(0) {}
31*0b57cec5SDimitry Andric
32*0b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR operator int __nat::*() const {return 0;}
33*0b57cec5SDimitry Andric
34*0b57cec5SDimitry Andric    template <class _Tp>
35*0b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
36*0b57cec5SDimitry Andric        operator _Tp* () const {return 0;}
37*0b57cec5SDimitry Andric
38*0b57cec5SDimitry Andric    template <class _Tp, class _Up>
39*0b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
40*0b57cec5SDimitry Andric        operator _Tp _Up::* () const {return 0;}
41*0b57cec5SDimitry Andric
42*0b57cec5SDimitry Andric    friend _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator==(nullptr_t, nullptr_t) {return true;}
43*0b57cec5SDimitry Andric    friend _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator!=(nullptr_t, nullptr_t) {return false;}
44*0b57cec5SDimitry Andric};
45*0b57cec5SDimitry Andric
46*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t __get_nullptr_t() {return nullptr_t(0);}
47*0b57cec5SDimitry Andric
48*0b57cec5SDimitry Andric#define nullptr _VSTD::__get_nullptr_t()
49*0b57cec5SDimitry Andric
50*0b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
51*0b57cec5SDimitry Andric
52*0b57cec5SDimitry Andric#else  // _LIBCPP_HAS_NO_NULLPTR
53*0b57cec5SDimitry Andric
54*0b57cec5SDimitry Andricnamespace std
55*0b57cec5SDimitry Andric{
56*0b57cec5SDimitry Andric    typedef decltype(nullptr) nullptr_t;
57*0b57cec5SDimitry Andric}
58*0b57cec5SDimitry Andric
59*0b57cec5SDimitry Andric#endif // _LIBCPP_HAS_NO_NULLPTR
60*0b57cec5SDimitry Andric
61*0b57cec5SDimitry Andric#endif // _LIBCPP_NULLPTR
62