Codechange: Add to_underlying() to convert enum to underlying type. (#12958)

This simplifies and replaces static_cast and C-style casts doing the same.

`std::to_underlying()` exists in C++23 but not C++20.
This commit is contained in:
Peter Nelson
2024-09-22 18:07:42 +01:00
committed by GitHub
parent 376e882a14
commit 0340e19e04
3 changed files with 16 additions and 12 deletions

View File

@@ -1200,7 +1200,7 @@ int GetEngineProperty(EngineID engine, PropertyID property, int orig_value, cons
*/
bool TestVehicleBuildProbability(Vehicle *v, EngineID engine, BuildProbabilityType type)
{
uint16_t p = GetVehicleCallback(CBID_VEHICLE_BUILD_PROBABILITY, std::underlying_type<BuildProbabilityType>::type(type), 0, engine, v);
uint16_t p = GetVehicleCallback(CBID_VEHICLE_BUILD_PROBABILITY, to_underlying(type), 0, engine, v);
if (p == CALLBACK_FAILED) return false;
const uint16_t PROBABILITY_RANGE = 100;