std::optional refactor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <tuple>
#include <optional>
class ObjSelection
{
public:
bool IsValid() const { return true; }
};
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;
}
std::tuple<bool, bool, bool, int> CheckSelectionVer2(const ObjSelection &objList)
{
if (!objList.IsValid())
return {false, false, false, 0};
// local variables:
int numCivilUnits = 0;
int numCombat = 0;
int numAnimating = 0;
// scan...
return {true, numCivilUnits > 0, numCombat > 0, numAnimating };
}
struct SelectionData
{
bool anyCivilUnits { false };
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX