4 ms·
Oh, things are obvious in C++, huh? Is the result of this function copied when it returns? auto f1() { if (check_something()) { std::opt
by boring_twenties 3y ago
Oh, things are obvious in C++, huh?
Is the result of this function copied when it returns?
auto f1() {
if (check_something()) {
std::optional<foo> result(std::in_place, arg1, arg2...);
if (result->check_something_else()) { /\* do something unrelated */ }
return result;
} else {
return std::optional<foo>(std::nullopt);
}
}
How about this one?
auto f2() {
std::optional<foo> result(std::nullopt);
if (check_something()) {
result.emplace(arg1, arg2...);
if (result->check_something_else()) { /\* do something unrelated \*/ }
}
return result;
}