1
0
Fork 0

Codechange: make strongtype constructor explicit

pull/13224/head
Rubidium 2024-12-31 18:18:48 +01:00 committed by rubidium42
parent 98e980c478
commit a22e357911
3 changed files with 7 additions and 4 deletions

View File

@ -127,8 +127,8 @@ namespace StrongType {
friend constexpr bool operator >=(const TType &lhs, TCompatibleType rhs) { return lhs.value >= static_cast<TBaseType>(rhs); }
friend constexpr bool operator >(const TType &lhs, TCompatibleType rhs) { return lhs.value > static_cast<TBaseType>(rhs); }
friend constexpr TType operator +(const TType &lhs, TCompatibleType rhs) { return { static_cast<TBaseType>(lhs.value + rhs) }; }
friend constexpr TType operator -(const TType &lhs, TCompatibleType rhs) { return { static_cast<TBaseType>(lhs.value - rhs) }; }
friend constexpr TType operator +(const TType &lhs, TCompatibleType rhs) { return TType{ static_cast<TBaseType>(lhs.value + rhs) }; }
friend constexpr TType operator -(const TType &lhs, TCompatibleType rhs) { return TType{ static_cast<TBaseType>(lhs.value - rhs) }; }
};
};
@ -154,7 +154,7 @@ namespace StrongType {
constexpr Typedef(const Typedef &) = default;
constexpr Typedef(Typedef &&) = default;
constexpr Typedef(const TBaseType &value) : value(value) {}
explicit constexpr Typedef(const TBaseType &value) : value(value) {}
constexpr Typedef &operator =(const Typedef &rhs) { this->value = rhs.value; return *this; }
constexpr Typedef &operator =(Typedef &&rhs) { this->value = std::move(rhs.value); return *this; }

View File

@ -442,6 +442,9 @@ inline TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
return TileDiffXY(tidc.x, tidc.y);
}
/* Helper functions to provide explicit +=/-= operators for TileIndex and TileIndexDiff. */
constexpr TileIndex &operator+=(TileIndex &tile, TileIndexDiff offset) { tile = tile + TileIndex(offset); return tile; }
constexpr TileIndex &operator-=(TileIndex &tile, TileIndexDiff offset) { tile = tile - TileIndex(offset); return tile; }
/**
* Adds a given offset to a tile.

View File

@ -76,7 +76,7 @@ void UpdateHousesAndTowns()
}
/* Check for cases when a NewGRF has set a wrong house substitute type. */
for (const auto t : Map::Iterate()) {
for (const TileIndex &t : Map::Iterate()) {
if (!IsTileType(t, MP_HOUSE)) continue;
HouseID house_type = GetCleanHouseType(t);