The Tuple Version
The lesson elaborates how to return multiple values using tuple.
The first step is to convert the output parameters into a tuple and return it from the function.
According to F.21: To return multiple “out” values, prefer returning a tuple or struct:
Do you know?
A return value is self-documenting as an “output-only” value. Note that
C++
does have multiple return values, by the convention of using a tuple (including pair), possibly with the extra convenience of a tie at the call site.
After the change the code might look like this:
Get hands-on with 1400+ tech skills courses.