The Use Case
Explore how to refactor code by replacing output parameters with tuples, structs, std optional, and std variant in C++17. Understand how these features improve function design, reduce duplication, and enhance error handling to write clearer and more maintainable code.
We'll cover the following...
We'll cover the following...
Consider a function that takes the current mouse selection for a game. The function scans the selected range and computes several outputs:
- the number of animating objects
- if there are any civil units in the selection
- if there are any combat units in the selection
The existing code looks like this:
As you can see above, the function uses a lot of output parameters (in the ...