The Use Case
The lesson provides the implementation of a particular use case of std::variant and std::optional
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:
Press + to interact
class ObjSelection{public:bool IsValid() const { return true; }// more code...};bool CheckSelectionVer1(const ObjSelection &objList, bool *pOutAnyCivilUnits, bool *pOutAnyCombatUnits, int *pOutNumAnimating){if (!objList.IsValid())return false;// local variables:int numCivilUnits = 0;int numCombat = 0;int numAnimating = 0;// scan...// set values:if (pOutAnyCivilUnits)*pOutAnyCivilUnits = numCivilUnits > 0;if (pOutAnyCombatUnits)*pOutAnyCombatUnits = numCombat > 0;if (pOutNumAnimating)*pOutNumAnimating = numAnimating;return true;}
As you can see above, the function uses a lot of output parameters (in the ...