diff --git a/source/mijin/container/optional.hpp b/source/mijin/container/optional.hpp index da39933..c3bd31d 100644 --- a/source/mijin/container/optional.hpp +++ b/source/mijin/container/optional.hpp @@ -157,8 +157,21 @@ public: [[nodiscard]] constexpr bool empty() const noexcept { return storage_.empty(); } inline void reset() noexcept; + + template + auto then(TCallable&& onSuccess, TErrorCallable&& onError = 0) + { + return thenImpl(*this, std::forward(onSuccess), std::forward(onError)); + } + + template + auto then(TCallable&& onSuccess, TErrorCallable&& onError = 0) const + { + return thenImpl(*this, std::forward(onSuccess), std::forward(onError)); + } +private: template - auto then(this TSelf&& self, TCallable&& onSuccess, TErrorCallable&& onError = 0) + static auto thenImpl(TSelf&& self, TCallable&& onSuccess, TErrorCallable&& onError = 0) { using result_t = std::invoke_result_t>;