diff --git a/src/core/strong_typedef_type.hpp b/src/core/strong_typedef_type.hpp index e1baeee311..4493545358 100644 --- a/src/core/strong_typedef_type.hpp +++ b/src/core/strong_typedef_type.hpp @@ -127,8 +127,8 @@ namespace StrongType { friend constexpr bool operator >=(const TType &lhs, TCompatibleType rhs) { return lhs.value >= static_cast(rhs); } friend constexpr bool operator >(const TType &lhs, TCompatibleType rhs) { return lhs.value > static_cast(rhs); } - friend constexpr TType operator +(const TType &lhs, TCompatibleType rhs) { return { static_cast(lhs.value + rhs) }; } - friend constexpr TType operator -(const TType &lhs, TCompatibleType rhs) { return { static_cast(lhs.value - rhs) }; } + friend constexpr TType operator +(const TType &lhs, TCompatibleType rhs) { return TType{ static_cast(lhs.value + rhs) }; } + friend constexpr TType operator -(const TType &lhs, TCompatibleType rhs) { return TType{ static_cast(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; } diff --git a/src/map_func.h b/src/map_func.h index cde6d7628e..3c94925831 100644 --- a/src/map_func.h +++ b/src/map_func.h @@ -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. diff --git a/src/saveload/town_sl.cpp b/src/saveload/town_sl.cpp index 9299330cc4..32f2cd8520 100644 --- a/src/saveload/town_sl.cpp +++ b/src/saveload/town_sl.cpp @@ -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);