This week I learned 47
This week I learned that you can emulate Rust’s if let Some(e) ...
syntax
in C++.
std::optional
has pointer semantics – meaning it has an operator bool
overload. You can use this to limit its scope to a conditional statement just
like if let Some(e)
if (auto opt = ...) {
/*
* opt.has_value() is true! safe to access the underlying value with `value()`
*/
Foo(std::move(opt.value()))
} else {
/* opt.has_value() is false! */
}