By using this site, you agree to this use. See details.
Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
In the previous exercise we used
std::optional to indicate failure.
But how about a more detailed error message?
Enter template class
We could use
std::variant to either hold a valid value or a detailed error.
differentiate to have return type
std::variant<double, std::string> and
once again make the tests pass.
The variant should either be a valid value or an error string.