From 22e46de327e490034ff7732804543b13916908e8 Mon Sep 17 00:00:00 2001 From: Evgeniy Alekseev Date: Sat, 28 Oct 2017 12:09:22 +0300 Subject: [PATCH] move Result::match inside class --- result.hpp | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/result.hpp b/result.hpp index ae470a5..c9ada74 100644 --- a/result.hpp +++ b/result.hpp @@ -164,6 +164,32 @@ public: return Content::Empty; }; }; + /** + * @brief match result function + * @tparam UnaryFunctionValue + * function type which will be called if result contains value + * @tparam UnaryFunctionError + * function type which will be called if result contains error + * @param apply_value + * function which will be called if result contains value + * @param apply_error + * function which will be called if result contains error + */ + template + void match(UnaryFunctionValue apply_value, + UnaryFunctionError apply_error) const + { + switch (type()) { + case Content::Value: + apply_value(get()); + break; + case Content::Error: + apply_error(error()); + break; + case Content::Empty: + break; + } + }; }; // additional functions @@ -189,16 +215,7 @@ template &result, UnaryFunctionValue apply_value, UnaryFunctionError apply_error) { - switch (result.type()) { - case Content::Value: - apply_value(result.get()); - break; - case Content::Error: - apply_error(result.error()); - break; - case Content::Empty: - break; - } + return result.match(apply_value, apply_error); }; };