Codechange: Add base() method to StrongType to allow access to the base type without casting. (#11445)

This removes the ability to explicitly cast to the base type, but the requirement
to use .base() means the conversion is still explicit.
This commit is contained in:
Peter Nelson
2023-11-06 20:29:35 +00:00
committed by GitHub
parent 737775f834
commit ab535c0a86
73 changed files with 174 additions and 173 deletions

View File

@@ -63,7 +63,7 @@ std::string ValueStr(SignalType t)
std::string TileStr(TileIndex tile)
{
std::stringstream ss;
ss << "0x" << std::setfill('0') << std::setw(4) << std::hex << static_cast<uint32_t>(tile); // 0x%04X
ss << "0x" << std::setfill('0') << std::setw(4) << std::hex << tile.base(); // 0x%04X
ss << " (" << TileX(tile) << ", " << TileY(tile) << ")";
return ss.str();
}

View File

@@ -53,7 +53,7 @@ public:
if constexpr (std::is_enum_v<T>) {
this->Write(static_cast<std::underlying_type_t<const T>>(data));
} else if constexpr (std::is_base_of_v<StrongTypedefBase, T>) {
this->Write(static_cast<typename T::BaseType>(data));
this->Write(data.base());
} else {
this->Write(data);
}