(I've not found much by searching for return statement, return deduce, and similar, with tags c++optional.)
Why does this work
#include <optional>
auto const f = [](bool b) {
return b ? std::optional<int>(3) : std::nullopt;
};
while this doesn't?
#include <optional>
auto const f = [](bool b) {
if (b) {
return std::optional<int>(3);
} else {
return std::nullopt;
}
};
Why can't the compiler deduce the type from the first return and see it's compatiple with the second return?