3 ms·
> as you could do in a lisp (or Rust [or Swift, or…]) There's also a GCC extension for this! https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html https://gc
by matthews2 4y ago
> as you could do in a lisp (or Rust [or Swift, or…])
There's also a GCC extension for this! https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
I'm using this for something a bit like Rust's unwrap (but uglier):
#define UNWRAP(expr) \
{{ \
auto result_ = (expr); \
if (!result_.present()) panic(); \
result_.disown(); \
}}
optional<int> foo();
void bar() {
int val = UNWRAP(foo);
}