aboutsummaryrefslogtreecommitdiff
path: root/src/optional.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/optional.hpp')
-rw-r--r--src/optional.hpp43
1 files changed, 27 insertions, 16 deletions
diff --git a/src/optional.hpp b/src/optional.hpp
index c178d59..5e1c630 100644
--- a/src/optional.hpp
+++ b/src/optional.hpp
@@ -1,36 +1,47 @@
+/**
+ * @file optional.hpp
+ * @author Felix Morgner (felix.morgner@gmail.com)
+ * @since 1.0.0
+ */
+
#ifndef WANDA_OPTIONAL_HPP
#define WANDA_OPTIONAL_HPP
#include <optional>
-namespace wanda::std_ext {
-
-struct failable {
+namespace wanda::std_ext
+{
+struct failable
+{
constexpr static auto success() { return failable{false}; }
constexpr static auto failure() { return failable{true}; }
- template<typename Handler>
- constexpr auto operator ||(Handler handler) const {
- if(m_failed) {
+ template <typename Handler>
+ constexpr auto operator||(Handler handler) const
+ {
+ if (m_failed)
+ {
handler();
}
}
-private:
- constexpr explicit failable(bool failed) : m_failed{failed} { };
+ private:
+ constexpr explicit failable(bool failed) : m_failed{failed} {};
bool const m_failed;
};
-template<typename ObjectType, typename HandlerType>
-auto with(std::optional<ObjectType> && object, HandlerType handler) {
- if(object) {
- handler(object.value());
- return failable::success();
- }
- return failable::failure();
+template <typename ObjectType, typename HandlerType>
+auto with(std::optional<ObjectType> &&object, HandlerType handler)
+{
+ if (object)
+ {
+ handler(object.value());
+ return failable::success();
+ }
+ return failable::failure();
}
-}
+} // namespace wanda::std_ext
#endif \ No newline at end of file