3 ms·
You can even just use `do { … } while (false)` without comments, but neither is an expression. Neither produce a value. The do expression would have similar enc
by eyelidlessness 4y ago
You can even just use `do { … } while (false)` without comments, but neither is an expression. Neither produce a value. The do expression would have similar encapsulation but allow assigning a derived value to a lhs binding, as you could do in a lisp (or Rust [or Swift, or…]).
- 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); }