1- // Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
1+ // Copyright (C) 2005 - 2025 Settlers Freaks (sf-team at siedler25.org)
22//
33// SPDX-License-Identifier: GPL-2.0-or-later
44
@@ -20,7 +20,7 @@ template<typename T>
2020struct Point // -V690
2121{
2222 using ElementType = T;
23- static_assert (std::is_arithmetic <ElementType>::value , " Requires an arithmetic type" );
23+ static_assert (std::is_arithmetic_v <ElementType>, " Requires an arithmetic type" );
2424
2525 static constexpr auto MinElementValue = std::numeric_limits<T>::min();
2626 static constexpr auto MaxElementValue = std::numeric_limits<T>::max();
@@ -35,15 +35,15 @@ struct Point //-V690
3535 T x, y;
3636 constexpr Point () noexcept : x(getInvalidValue()), y(getInvalidValue()) {}
3737 constexpr Point (const T x, const T y) noexcept : x(x), y(y) {}
38- template <typename U, std::enable_if_t <!(std::is_integral <T>::value && std::is_floating_point <U>::value ), int > = 0 >
38+ template <typename U, std::enable_if_t <!(std::is_integral_v <T> && std::is_floating_point_v <U>), int > = 0 >
3939 constexpr explicit Point (const Point<U>& pt) noexcept : x(static_cast <T>(pt.x)), y(static_cast <T>(pt.y))
4040 {}
4141 // / Convert floating-point to integer by truncating
42- template <typename U, std::enable_if_t <std::is_integral <T>::value && std::is_floating_point <U>::value , int > = 0 >
42+ template <typename U, std::enable_if_t <std::is_integral_v <T> && std::is_floating_point_v <U>, int > = 0 >
4343 constexpr explicit Point (Truncate_t, const Point<U>& pt) noexcept : x(static_cast <T>(pt.x)), y(static_cast <T>(pt.y))
4444 {}
4545 // / Convert floating-point to integer with rounding (default behavior)
46- template <typename U, std::enable_if_t <std::is_integral <T>::value && std::is_floating_point <U>::value , int > = 0 >
46+ template <typename U, std::enable_if_t <std::is_integral_v <T> && std::is_floating_point_v <U>, int > = 0 >
4747 constexpr explicit Point (const Point<U>& pt) noexcept : x(helpers::iround<T>(pt.x)), y(helpers::iround<T>(pt.y))
4848 {}
4949 constexpr Point (const Point&) = default;
@@ -99,7 +99,7 @@ struct type_identity
9999// / Convert the type T to a signed type if the condition is true (safe for float types)
100100template <bool cond, typename T>
101101using make_signed_if_t =
102- typename std::conditional_t <cond && !std::is_signed <T>::value , std::make_signed<T>, type_identity<T>>::type;
102+ typename std::conditional_t <cond && !std::is_signed_v <T>, std::make_signed<T>, type_identity<T>>::type;
103103
104104// clang-format off
105105
@@ -109,26 +109,25 @@ using make_signed_if_t =
109109template <typename T, typename U>
110110using mixed_type_t =
111111 make_signed_if_t <
112- std::is_signed <T>::value || std::is_signed <U>::value ,
112+ std::is_signed_v <T> || std::is_signed_v <U>,
113113 typename std::conditional_t <
114- std::is_floating_point <T>::value == std::is_floating_point <U>::value , // both are FP or not FP?
114+ std::is_floating_point_v <T> == std::is_floating_point_v <U>, // both are FP or not FP?
115115 std::conditional<(sizeof (T) > sizeof (U)), T, U>, // Take the larger type
116- std::conditional<std::is_floating_point <T>::value , T, U> // Take the floating point type
116+ std::conditional<std::is_floating_point_v <T>, T, U> // Take the floating point type
117117 >::type
118118 >;
119119
120120template <typename T, typename U>
121- using IsNonLossyOp = std::integral_constant< bool ,
121+ constexpr bool is_lossles_op_v =
122122 // We can do T = T <op> U (except overflow) if:
123- std::is_floating_point<T>::value || std::is_signed<T>::value || std::is_unsigned<U>::value
124- >;
123+ std::is_floating_point_v<T> || std::is_signed_v<T> || std::is_unsigned_v<U>;
125124
126125// clang-format on
127126
128127template <typename T, typename U>
129- using require_nonLossyOp = std::enable_if_t <IsNonLossyOp <T, U>::value >;
128+ using require_lossless_op = std::enable_if_t <is_lossles_op_v <T, U>>;
130129template <typename T>
131- using require_arithmetic = std::enable_if_t <std::is_arithmetic <T>::value >;
130+ using require_arithmetic = std::enable_if_t <std::is_arithmetic_v <T>>;
132131
133132} // namespace detail
134133
@@ -153,7 +152,7 @@ constexpr auto prodOfComponents(const Point<T>& pt) noexcept
153152{
154153 // Let the compiler handle conversion to at least 32 bits keeping float types
155154 using op_type = decltype (T{} * uint32_t {});
156- using ResultType = ::detail::make_signed_if_t <std::is_signed <T>::value , op_type>;
155+ using ResultType = ::detail::make_signed_if_t <std::is_signed_v <T>, op_type>;
157156 return static_cast <ResultType>(pt.x * pt.y );
158157}
159158
@@ -198,7 +197,7 @@ RTTR_GEN_ARITH(/)
198197
199198// Scaling operators
200199
201- template <typename T, typename U, class = detail::require_nonLossyOp <T, U>>
200+ template <typename T, typename U, class = detail::require_lossless_op <T, U>>
202201constexpr Point<T>& operator *=(Point<T>& lhs, U factor) noexcept
203202{
204203 return lhs *= Point<T>::all (factor);
@@ -216,7 +215,7 @@ constexpr auto operator*(const T left, const Point<U>& factor) noexcept
216215 return factor * left;
217216}
218217
219- template <typename T, typename U, class = detail::require_nonLossyOp <T, U>>
218+ template <typename T, typename U, class = detail::require_lossless_op <T, U>>
220219constexpr Point<T>& operator /=(Point<T>& lhs, U div) noexcept
221220{
222221 return lhs /= Point<T>::all (div);
0 commit comments