ovr_sdk

view LibOVR/Src/Kernel/OVR_Nullptr.h @ 0:1b39a1b46319

initial 0.4.4
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 14 Jan 2015 06:51:16 +0200
parents
children
line source
1 /************************************************************************************
3 PublicHeader: OVR_Kernel.h
4 Filename : OVR_Nullptr.h
5 Content : Implements C++11 nullptr for the case that the compiler doesn't.
6 Created : June 19, 2014
7 Notes :
9 Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
11 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
12 you may not use the Oculus VR Rift SDK except in compliance with the License,
13 which is provided at the time of installation or download, or which
14 otherwise accompanies this software in either electronic or hard copy form.
16 You may obtain a copy of the License at
18 http://www.oculusvr.com/licenses/LICENSE-3.2
20 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
21 distributed under the License is distributed on an "AS IS" BASIS,
22 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 See the License for the specific language governing permissions and
24 limitations under the License.
26 ************************************************************************************/
28 #ifndef OVR_Nullptr_h
29 #define OVR_Nullptr_h
31 #pragma once
33 #include "OVR_Types.h"
36 //-----------------------------------------------------------------------------------
37 // ***** OVR_HAVE_std_nullptr_t
38 //
39 // Identifies if <cstddef.h> includes std::nullptr_t.
40 //
41 #if !defined(OVR_HAVE_std_nullptr_t) && defined(OVR_CPP11_ENABLED)
42 #if defined(OVR_STDLIB_LIBCPP)
43 #define OVR_HAVE_std_nullptr_t 1
44 #elif defined(OVR_STDLIB_LIBSTDCPP)
45 #if (__GLIBCXX__ >= 20110325) && (__GLIBCXX__ != 20110428) && (__GLIBCXX__ != 20120702)
46 #define OVR_HAVE_std_nullptr_t 1
47 #endif
48 #elif defined(_MSC_VER) && (_MSC_VER >= 1600) // VS2010+
49 #define OVR_HAVE_std_nullptr_t 1
50 #elif defined(__clang__)
51 #define OVR_HAVE_std_nullptr_t 1
52 #elif defined(OVR_CPP_GNUC) && (OVR_CC_VERSION >= 406) // GCC 4.6+
53 #define OVR_HAVE_std_nullptr_t 1
54 #endif
55 #endif
58 //-----------------------------------------------------------------------------------
59 // ***** nullptr / std::nullptr_t
60 //
61 // Declares and defines nullptr and related types.
62 //
63 #if defined(OVR_CPP_NO_NULLPTR)
64 namespace std
65 {
66 class nullptr_t
67 {
68 public:
69 template <typename T>
70 operator T*() const
71 { return 0; }
73 template <typename C, typename T>
74 operator T C::*() const
75 { return 0; }
77 #if OVR_CPP_NO_EXPLICIT_CONVERSION_OPERATORS
78 typedef void* (nullptr_t::*bool_)() const; // 4.12,p1. We can't portably use operator bool(){ return false; } because bool
79 operator bool_() const // is convertable to int which breaks other required functionality.
80 { return false; }
81 #else
82 operator bool() const
83 { return false; }
84 #endif
86 private:
87 void operator&() const; // 5.2.10,p9
88 };
90 inline nullptr_t nullptr_get()
91 {
92 nullptr_t n = { };
93 return n;
94 }
96 #if !defined(nullptr)
97 #define nullptr nullptr_get()
98 #endif
100 } // namespace std
103 // 5.9,p2 p4
104 // 13.6, p13
105 template <typename T>
106 inline bool operator==(T* pT, const std::nullptr_t)
107 { return pT == 0; }
109 template <typename T>
110 inline bool operator==(const std::nullptr_t, T* pT)
111 { return pT == 0; }
113 template <typename T, typename U>
114 inline bool operator==(const std::nullptr_t, T U::* pU)
115 { return pU == 0; }
117 template <typename T, typename U>
118 inline bool operator==(T U::* pTU, const std::nullptr_t)
119 { return pTU == 0; }
121 inline bool operator==(const std::nullptr_t, const std::nullptr_t)
122 { return true; }
124 inline bool operator!=(const std::nullptr_t, const std::nullptr_t)
125 { return false; }
127 inline bool operator<(const std::nullptr_t, const std::nullptr_t)
128 { return false; }
130 inline bool operator<=(const std::nullptr_t, const std::nullptr_t)
131 { return true; }
133 inline bool operator>(const std::nullptr_t, const std::nullptr_t)
134 { return false; }
136 inline bool operator>=(const std::nullptr_t, const std::nullptr_t)
137 { return true; }
139 using std::nullptr_t;
140 using std::nullptr_get;
142 // Some compilers natively support C++11 nullptr but the standard library being used
143 // doesn't declare std::nullptr_t, in which case we provide one ourselves.
144 #elif !defined(OVR_HAVE_std_nullptr_t) && !defined(OVR_CPP_NO_DECLTYPE)
145 namespace std { typedef decltype(nullptr) nullptr_t; }
146 #endif
149 #endif