From 74935056c496814a3c9d1380437812536b159203 Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Thu, 6 Feb 2014 20:53:38 +0100 Subject: Converted detail::Result into general optional_ptr type * Added set member method overload for easier value modification * Idea: expand detail::optional_ptr into general optional type --- src/utility.h | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'src/utility.h') diff --git a/src/utility.h b/src/utility.h index 6342420..db33608 100644 --- a/src/utility.h +++ b/src/utility.h @@ -4,24 +4,30 @@ namespace detail { template < - typename Value + typename Type > -struct Result { - Result(): - value_(false, Value()) { } +class optional_ptr { + public: + typedef typename std::add_pointer::type pointer; + typedef Type element_type; - Result(Value value): - value_(true, value) { } + optional_ptr(): + value_(false, nullptr) { } - inline operator bool() const { - return this->value_.first; - } + optional_ptr(pointer ptr): + value_(true, ptr) { } - inline Value get() const { - return this->value_.second; - } + inline operator bool() const { + return this->value_.first; + } + + inline pointer get() const { + return this->value_.second; + } + + private: + const std::pair value_; - const std::pair value_; }; } -- cgit v1.2.3