From 13f079c5150d86bb87b71094e545e720e245658d Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Thu, 6 Feb 2014 20:26:45 +0100 Subject: Introduced simple result wrapper template * offers bool() operator for easy assignment checks inside conditional statements --- src/utility.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/utility.h (limited to 'src/utility.h') diff --git a/src/utility.h b/src/utility.h new file mode 100644 index 0000000..6342420 --- /dev/null +++ b/src/utility.h @@ -0,0 +1,29 @@ +#ifndef TRIE_SRC_UTILITY_H_ +#define TRIE_SRC_UTILITY_H_ + +namespace detail { + +template < + typename Value +> +struct Result { + Result(): + value_(false, Value()) { } + + Result(Value value): + value_(true, value) { } + + inline operator bool() const { + return this->value_.first; + } + + inline Value get() const { + return this->value_.second; + } + + const std::pair value_; +}; + +} + +#endif // TRIE_SRC_UTILITY_H_ -- cgit v1.2.3