1
0
Fork 0

Codechange: Use std::visit for GetActiveCargoLabel.

pull/13103/head
Peter Nelson 2024-11-19 13:56:33 +00:00 committed by Peter Nelson
parent 25c5a64d39
commit f9b5f78b8a
1 changed files with 13 additions and 9 deletions

View File

@ -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);
} }
/** /**