From a59cd8b2c0ed6a48c84227100b05ee216f493b15 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Thu, 2 Jan 2025 19:19:34 +0100 Subject: [PATCH] Codefix: narrowing warnings with MSVC when base type is smaller than int --- src/core/strong_typedef_type.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/strong_typedef_type.hpp b/src/core/strong_typedef_type.hpp index c53d136a22..2b929430b6 100644 --- a/src/core/strong_typedef_type.hpp +++ b/src/core/strong_typedef_type.hpp @@ -58,12 +58,12 @@ namespace StrongType { friend constexpr TType operator --(TType &lhs, int) { TType res = lhs; lhs.value--; return res; } friend constexpr TType &operator +=(TType &lhs, const TType &rhs) { lhs.value += rhs.value; return lhs; } - friend constexpr TType operator +(const TType &lhs, const TType &rhs) { return TType{ lhs.value + rhs.value }; } - friend constexpr TType operator +(const TType &lhs, const TBaseType &rhs) { return TType{ lhs.value + rhs }; } + friend constexpr TType operator +(const TType &lhs, const TType &rhs) { return TType(lhs.value + rhs.value); } + friend constexpr TType operator +(const TType &lhs, const TBaseType &rhs) { return TType(lhs.value + rhs); } friend constexpr TType &operator -=(TType &lhs, const TType &rhs) { lhs.value -= rhs.value; return lhs; } - friend constexpr TType operator -(const TType &lhs, const TType &rhs) { return TType{ lhs.value - rhs.value }; } - friend constexpr TType operator -(const TType &lhs, const TBaseType &rhs) { return TType{ lhs.value - rhs }; } + friend constexpr TType operator -(const TType &lhs, const TType &rhs) { return TType(lhs.value - rhs.value); } + friend constexpr TType operator -(const TType &lhs, const TBaseType &rhs) { return TType(lhs.value - rhs); } /* For most new types, the rest of the operators make no sense. For example, * what does it actually mean to multiply a Year with a value. Or to do a @@ -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 TType{ 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(lhs.value + rhs); } + friend constexpr TType operator -(const TType &lhs, TCompatibleType rhs) { return TType(lhs.value - rhs); } }; };