aboutsummaryrefslogtreecommitdiff
path: root/include/wanda/optional.hpp
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2022-09-16 21:36:12 +0200
committerFelix Morgner <felix.morgner@gmail.com>2022-09-16 21:36:12 +0200
commit64922e213ac731279cf3341253e67509adb2dfc8 (patch)
treeddcf4fd5b05ac426ecf032e43e8662c2f9ce0f57 /include/wanda/optional.hpp
parentd22bc7b557d36da41fe88d3188a7cd335c3ccaa0 (diff)
downloadwanda-64922e213ac731279cf3341253e67509adb2dfc8.tar.xz
wanda-64922e213ac731279cf3341253e67509adb2dfc8.zip
wanda: restructure source directory
Diffstat (limited to 'include/wanda/optional.hpp')
-rw-r--r--include/wanda/optional.hpp65
1 files changed, 0 insertions, 65 deletions
diff --git a/include/wanda/optional.hpp b/include/wanda/optional.hpp
deleted file mode 100644
index da3774c..0000000
--- a/include/wanda/optional.hpp
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * @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
-{
- /**
- * @brief A type to represent a computation that could fail
- */
- struct failable
- {
- /**
- * @brief A factory to create a successful computation
- */
- constexpr static auto success() { return failable{false}; }
-
- /**
- * @brief A factory to create a failed computation
- */
- constexpr static auto failure() { return failable{true}; }
-
- /**
- * @brief Execute the given handler if the computation failed
- */
- template<typename Handler>
- constexpr void operator||(Handler handler) const
- {
- if (m_failed)
- {
- handler();
- }
- }
-
- private:
- constexpr explicit failable(bool failed)
- : m_failed{failed} {};
- bool const m_failed;
- };
-
- /**
- * @brief Unwrap the given optional object, if present, and pass it to the handler
- *
- * @return A successful computation iff. the object was present, a failed computation otherwise.
- */
- 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