diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2014-10-09 19:54:23 -0700 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2014-10-13 13:20:28 -0700 |
commit | a5e0fe8204a8b3299507a645f3479e9ead6c6110 (patch) | |
tree | fdb6b0afd0ea0138dd4f7f8f671c23bf6bb4f2eb /src/compat/option.hpp | |
parent | 0d9f2d217265e826a4843b3873824216344f1b24 (diff) | |
download | tmwa-a5e0fe8204a8b3299507a645f3479e9ead6c6110.tar.gz tmwa-a5e0fe8204a8b3299507a645f3479e9ead6c6110.tar.bz2 tmwa-a5e0fe8204a8b3299507a645f3479e9ead6c6110.tar.xz tmwa-a5e0fe8204a8b3299507a645f3479e9ead6c6110.zip |
Add OPTION_IS_SOME branching macro
Diffstat (limited to 'src/compat/option.hpp')
-rw-r--r-- | src/compat/option.hpp | 12 |
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; |