summaryrefslogtreecommitdiff
path: root/src/compat/option.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/compat/option.hpp')
-rw-r--r--src/compat/option.hpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/compat/option.hpp b/src/compat/option.hpp
index 25c23eb..ad83395 100644
--- a/src/compat/option.hpp
+++ b/src/compat/option.hpp
@@ -24,6 +24,8 @@
#include <utility>
+#include "attr.hpp"
+
namespace tmwa
{
@@ -204,6 +206,10 @@ namespace option
{
return repr.is_some() ? repr.ptr() : def;
}
+ bool is_some() const
+ {
+ return repr.is_some();
+ }
template<class F>
auto move_map(F&& f) -> Option<decltype(std::forward<F>(f)(std::move(*repr.ptr())))>
@@ -365,9 +371,13 @@ namespace option
#define TRY_UNWRAP(opt, falsy) \
({ \
tmwa::option::RefWrapper<decltype((opt))> o = {(opt)}; \
- if (!o.maybe_ref.ptr_or(nullptr)) falsy; \
+ if (!o.maybe_ref.is_some()) falsy; \
tmwa::option::option_unwrap(std::move(o)); \
}).maybe_ref_fun()
+// immediately preceded by 'if'; not double-eval-safe
+#define OPTION_IS_SOME(var, expr) \
+ ((expr).is_some()) \
+ WITH_VAR(auto&, var, *(expr).ptr_or(nullptr))
} // namespace option
using option::Option;