C++17 introduces a concept called std::optional. The class template std::optional manages optional contained value, a value that may or may not be present. It is commonly used in the return values of the functions that may fail.
First function returns an optional string, that is the function may return a string or may not return anything. Hence, it is optional.
Second function returns the string if the variable b is true else it returns a nullopt.
std::optional < std::string biss(bool b)
{
if (b)
{
return "Hello Biss";
}
return {};
}
auto biss2(bool b)
{
return b ? std::optional<std::string>{
"Hello Biss"
} std::nullopt;
}