blob: 95415a6325a318066009bf3efeea093de359f00b [file] [log] [blame]
Richard Smith72d75772015-10-08 20:34:11 +00001// -*- 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
11#ifndef _LIBCPP_NULLPTR
12#define _LIBCPP_NULLPTR
13
14#include <__config>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#pragma GCC system_header
18#endif
19
20#ifdef _LIBCPP_HAS_NO_NULLPTR
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24struct _LIBCPP_TYPE_VIS_ONLY nullptr_t
25{
26 void* __lx;
27
28 struct __nat {int __for_bool_;};
29
30 _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t() : __lx(0) {}
31 _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t(int __nat::*) : __lx(0) {}
32
33 _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR operator int __nat::*() const {return 0;}
34
35 template <class _Tp>
36 _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR
37 operator _Tp* () const {return 0;}
38
39 template <class _Tp, class _Up>
40 _LIBCPP_ALWAYS_INLINE
41 operator _Tp _Up::* () const {return 0;}
42
43 friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator==(nullptr_t, nullptr_t) {return true;}
44 friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator!=(nullptr_t, nullptr_t) {return false;}
45 friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator<(nullptr_t, nullptr_t) {return false;}
46 friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator<=(nullptr_t, nullptr_t) {return true;}
47 friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator>(nullptr_t, nullptr_t) {return false;}
48 friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator>=(nullptr_t, nullptr_t) {return true;}
49};
50
51inline _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t __get_nullptr_t() {return nullptr_t(0);}
52
53#define nullptr _VSTD::__get_nullptr_t()
54
55_LIBCPP_END_NAMESPACE_STD
56
57#else // _LIBCPP_HAS_NO_NULLPTR
58
59namespace std
60{
61 typedef decltype(nullptr) nullptr_t;
62}
63
64#endif // _LIBCPP_HAS_NO_NULLPTR
65
66#endif // _LIBCPP_NULLPTR