diff options
author | Adrian Kummerländer | 2014-02-06 20:53:38 +0100 |
---|---|---|
committer | Adrian Kummerländer | 2014-02-06 20:53:38 +0100 |
commit | 74935056c496814a3c9d1380437812536b159203 (patch) | |
tree | 9417e7604740cc53fc26c3b74604d901ffdb94b0 /src/utility.h | |
parent | 13f079c5150d86bb87b71094e545e720e245658d (diff) | |
download | Trie-74935056c496814a3c9d1380437812536b159203.tar Trie-74935056c496814a3c9d1380437812536b159203.tar.gz Trie-74935056c496814a3c9d1380437812536b159203.tar.bz2 Trie-74935056c496814a3c9d1380437812536b159203.tar.lz Trie-74935056c496814a3c9d1380437812536b159203.tar.xz Trie-74935056c496814a3c9d1380437812536b159203.tar.zst Trie-74935056c496814a3c9d1380437812536b159203.zip |
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
Diffstat (limited to 'src/utility.h')
-rw-r--r-- | src/utility.h | 32 |
1 files changed, 19 insertions, 13 deletions
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>::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<bool, pointer> value_; - const std::pair<bool, Value> value_; }; } |