From 3c017bfa105c792416f0374c9f8e740905825ae0 Mon Sep 17 00:00:00 2001 From: Alexander Ryabykin Date: Sat, 2 Jul 2016 15:24:10 +0300 Subject: [PATCH] constexpr operators --- include/gsl.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/include/gsl.h b/include/gsl.h index ad064ba..8db781b 100644 --- a/include/gsl.h +++ b/include/gsl.h @@ -101,8 +101,8 @@ public: not_null(std::nullptr_t) = delete; not_null(int) = delete; not_null& operator=(std::nullptr_t) = delete; - not_null& operator=(int) = delete; - + not_null& operator=(int) = delete; + T get() const { #ifdef _MSC_VER __assume(ptr_ != nullptr); @@ -110,11 +110,16 @@ public: return ptr_; } // the assume() should help the optimizer - operator T() const { return get(); } + operator T() const { return get(); } T operator->() const { return get(); } - bool operator==(const T& rhs) const { return ptr_ == rhs; } - bool operator!=(const T& rhs) const { return !(*this == rhs); } + bool operator==(const T& rhs) const { return ptr_ == rhs; } + bool operator!=(const T& rhs) const { return !(*this == rhs); } + + constexpr bool operator==(std::nullptr_t) const { return false; } + constexpr bool operator!=(std::nullptr_t) const { return true; } + + constexpr operator bool() const { return true; } private: T ptr_;