#ifndef WANDA_OPTIONAL_HPP #define WANDA_OPTIONAL_HPP #include namespace wanda::std_ext { struct failable { constexpr static auto success() { return failable{false}; } constexpr static auto failure() { return failable{true}; } template constexpr auto operator ||(Handler handler) const { if(m_failed) { handler(); } } private: constexpr explicit failable(bool failed) : m_failed{failed} { }; bool const m_failed; }; template auto with(std::optional && object, HandlerType handler) { if(object) { handler(object.value()); return failable::success(); } return failable::failure(); } } #endif