/** @file * @author Edouard DUPIN * @copyright 2017, Edouard DUPIN, all right reserved * @license MPL v2.0 (see license file) */ #pragma once namespace etk { class NullPtr { public: template operator T*() const { return 0; } template operator T C::*() const { return 0; } typedef void* (etk::NullPtr::*bool_)() const; template ETK_TYPE_FUNCTION_RETURN operator()(ETK_TYPE_FUNCTION_ARGS... _args) { throw; } }; inline NullPtr getNullPointer() { // etk::null exists. NullPtr n = { }; return n; } } // We does not use null ==> specific STD, can not be overload, and this permit to have a compatibility with STD #if !defined(null) #define null etk::getNullPointer() #endif template inline bool operator==(T* p, const etk::NullPtr) { return p == 0; } template inline bool operator==(const etk::NullPtr, T* p) { return p == 0; } template inline bool operator==(T U::* p, const etk::NullPtr) { return p == 0; } template inline bool operator==(const etk::NullPtr, T U::* p) { return p == 0; } inline bool operator==(const etk::NullPtr, const etk::NullPtr) { return true; } inline bool operator!=(const etk::NullPtr, const etk::NullPtr) { return false; } inline bool operator<(const etk::NullPtr, const etk::NullPtr) { return false; } inline bool operator>(const etk::NullPtr, const etk::NullPtr) { return false; } inline bool operator<=(const etk::NullPtr, const etk::NullPtr) { return true; } inline bool operator>=(const etk::NullPtr, const etk::NullPtr) { return true; }