Changeset - r27716:bb439c873c3a
[Not reviewed]
master
0 1 0
Patric Stout - 11 months ago 2023-07-12 13:54:44
truebrain@openttd.org
Codechange: hint in all branches of ClampTo to resolve compile-time (#11130)
1 file changed with 2 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/core/math_func.hpp
Show inline comments
 
@@ -165,18 +165,18 @@ static inline uint ClampU(const uint a, 
 
template <typename To, typename From>
 
constexpr To ClampTo(From value)
 
{
 
	static_assert(std::numeric_limits<To>::is_integer, "Do not clamp from non-integer values");
 
	static_assert(std::numeric_limits<From>::is_integer, "Do not clamp to non-integer values");
 

	
 
	if (sizeof(To) >= sizeof(From) && std::numeric_limits<To>::is_signed == std::numeric_limits<From>::is_signed) {
 
	if constexpr (sizeof(To) >= sizeof(From) && std::numeric_limits<To>::is_signed == std::numeric_limits<From>::is_signed) {
 
		/* Same signedness and To type is larger or equal than From type, no clamping is required. */
 
		return static_cast<To>(value);
 
	}
 

	
 
	if (sizeof(To) > sizeof(From) && std::numeric_limits<To>::is_signed) {
 
	if constexpr (sizeof(To) > sizeof(From) && std::numeric_limits<To>::is_signed) {
 
		/* Signed destination and a larger To type, no clamping is required. */
 
		return static_cast<To>(value);
 
	}
 

	
 
	/* Get the bigger of the two types based on essentially the number of bits. */
 
	using BiggerType = typename std::conditional<sizeof(From) >= sizeof(To), From, To>::type;
0 comments (0 inline, 0 general)