4 ms·
For 3, std::optional has the has_value() method. std::optional<int> a = foo(); if(!a.has_value()) { return; } bar(a); is pretty standard. Though, with except
by proverbialbunny 8y ago
For 3, std::optional has the has_value() method.
std::optional<int> a = foo();
if(!a.has_value()) { return; }
bar(a);
is pretty standard.
Though, with exception handling you get function chaining which can be rather nice.
- saagarjha 8y agoI'm look for something like Swift's optional chaining, á la: std::optional<std::string> a = foo(); auto size = a?.size() // size is a std::optional<int>