mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use std::visit for GetActiveCargoLabel.
parent
25c5a64d39
commit
f9b5f78b8a
|
@ -8971,16 +8971,20 @@ static CargoLabel GetActiveCargoLabel(const std::initializer_list<CargoLabel> &l
|
||||||
*/
|
*/
|
||||||
static CargoLabel GetActiveCargoLabel(const std::variant<CargoLabel, MixedCargoType> &label)
|
static CargoLabel GetActiveCargoLabel(const std::variant<CargoLabel, MixedCargoType> &label)
|
||||||
{
|
{
|
||||||
if (std::holds_alternative<CargoLabel>(label)) return std::get<CargoLabel>(label);
|
struct visitor {
|
||||||
if (std::holds_alternative<MixedCargoType>(label)) {
|
CargoLabel operator()(const CargoLabel &label) { return label; }
|
||||||
switch (std::get<MixedCargoType>(label)) {
|
CargoLabel operator()(const MixedCargoType &mixed)
|
||||||
case MCT_LIVESTOCK_FRUIT: return GetActiveCargoLabel({CT_LIVESTOCK, CT_FRUIT});
|
{
|
||||||
case MCT_GRAIN_WHEAT_MAIZE: return GetActiveCargoLabel({CT_GRAIN, CT_WHEAT, CT_MAIZE});
|
switch (mixed) {
|
||||||
case MCT_VALUABLES_GOLD_DIAMONDS: return GetActiveCargoLabel({CT_VALUABLES, CT_GOLD, CT_DIAMONDS});
|
case MCT_LIVESTOCK_FRUIT: return GetActiveCargoLabel({CT_LIVESTOCK, CT_FRUIT});
|
||||||
default: NOT_REACHED();
|
case MCT_GRAIN_WHEAT_MAIZE: return GetActiveCargoLabel({CT_GRAIN, CT_WHEAT, CT_MAIZE});
|
||||||
|
case MCT_VALUABLES_GOLD_DIAMONDS: return GetActiveCargoLabel({CT_VALUABLES, CT_GOLD, CT_DIAMONDS});
|
||||||
|
default: NOT_REACHED();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
NOT_REACHED();
|
|
||||||
|
return std::visit(visitor{}, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue