summaryrefslogtreecommitdiffhomepage
path: root/ovr_sdk_win_23.0.0/LibOVRKernel/Src/Kernel/OVR_Nullptr.h
blob: 9a6494f9404ab96b4f0c7cf6995c886adcfcc9cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/************************************************************************************

Filename    :   OVR_Nullptr.h
Content     :   Implements C++11 nullptr for the case that the compiler doesn't.
Created     :   June 19, 2014
Notes       :

Copyright   :   Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.

Licensed under the Oculus Master SDK License Version 1.0 (the "License");
you may not use the Oculus VR Rift SDK except in compliance with the License,
which is provided at the time of installation or download, or which
otherwise accompanies this software in either electronic or hard copy form.

You may obtain a copy of the License at

https://developer.oculus.com/licenses/oculusmastersdk-1.0

Unless required by applicable law or agreed to in writing, the Oculus VR SDK
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

************************************************************************************/

#ifndef OVR_Nullptr_h
#define OVR_Nullptr_h

#pragma once

#include "OVR_Types.h"

//-----------------------------------------------------------------------------------
// ***** OVR_HAVE_std_nullptr_t
//
// Identifies if <cstddef.h> includes std::nullptr_t.
//
#if !defined(OVR_HAVE_std_nullptr_t) && defined(OVR_CPP11_ENABLED)
#if defined(OVR_STDLIB_LIBCPP)
#define OVR_HAVE_std_nullptr_t 1
#elif defined(OVR_STDLIB_LIBSTDCPP)
#if (__GLIBCXX__ >= 20110325) && (__GLIBCXX__ != 20110428) && (__GLIBCXX__ != 20120702)
#define OVR_HAVE_std_nullptr_t 1
#endif
#elif defined(_MSC_VER) && (_MSC_VER >= 1600) // VS2010+
#define OVR_HAVE_std_nullptr_t 1
#elif defined(__clang__)
#define OVR_HAVE_std_nullptr_t 1
#elif defined(OVR_CPP_GNUC) && (OVR_CC_VERSION >= 406) // GCC 4.6+
#define OVR_HAVE_std_nullptr_t 1
#endif
#endif

//-----------------------------------------------------------------------------------
// ***** nullptr / std::nullptr_t
//
// Declares and defines nullptr and related types.
//
#if defined(OVR_CPP_NO_NULLPTR)
namespace std {
class nullptr_t {
 public:
  template <typename T>
  operator T*() const {
    return 0;
  }

  template <typename C, typename T>
  operator T C::*() const {
    return 0;
  }

#if OVR_CPP_NO_EXPLICIT_CONVERSION_OPERATORS
  typedef void* (nullptr_t::*bool_)()
      const; // 4.12,p1. We can't portably use operator bool(){ return false; } because bool
  operator bool_() const // is convertable to int which breaks other required functionality.
  {
    return false;
  }
#else
  operator bool() const {
    return false;
  }
#endif

 private:
  void operator&() const; // 5.2.10,p9
};

inline nullptr_t nullptr_get() {
  nullptr_t n = {};
  return n;
}

#if !defined(nullptr)
#define nullptr nullptr_get()
#endif

} // namespace std

// 5.9,p2 p4
// 13.6, p13
template <typename T>
inline bool operator==(T* pT, const std::nullptr_t) {
  return pT == 0;
}

template <typename T>
inline bool operator==(const std::nullptr_t, T* pT) {
  return pT == 0;
}

template <typename T, typename U>
inline bool operator==(const std::nullptr_t, T U::*pU) {
  return pU == 0;
}

template <typename T, typename U>
inline bool operator==(T U::*pTU, const std::nullptr_t) {
  return pTU == 0;
}

inline bool operator==(const std::nullptr_t, const std::nullptr_t) {
  return true;
}

inline bool operator!=(const std::nullptr_t, const std::nullptr_t) {
  return false;
}

inline bool operator<(const std::nullptr_t, const std::nullptr_t) {
  return false;
}

inline bool operator<=(const std::nullptr_t, const std::nullptr_t) {
  return true;
}

inline bool operator>(const std::nullptr_t, const std::nullptr_t) {
  return false;
}

inline bool operator>=(const std::nullptr_t, const std::nullptr_t) {
  return true;
}

using std::nullptr_get;
using std::nullptr_t;

// Some compilers natively support C++11 nullptr but the standard library being used
// doesn't declare std::nullptr_t, in which case we provide one ourselves.
#elif !defined(OVR_HAVE_std_nullptr_t) && !defined(OVR_CPP_NO_DECLTYPE)
namespace std {
typedef decltype(nullptr) nullptr_t;
}
#endif

#endif