ovr_sdk

annotate LibOVR/Src/Kernel/OVR_Nullptr.h @ 3:f12a8f74fe1f

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