We have discussed happy path cases a lot, which are when the data is valid for our data transformations. What do we do for edge cases and errors? Sure, in exceptional cases, we can throw exceptions or return error cases, but what about situations when we need to return an error message?
The functional way is to return data structures in these cases. After all, we need to return an output value even when the input isn't valid. But we hit a challenge—the type we need to return in the case of an error is an error type, while the type we need to return in the case of valid data is some more valid data.
Fortunately, we have two structures that support us in these cases—std::optional and std::variant. Let's take an example of a list of people, some of whom are valid and some of whom are invalid:
vector<Person> people...