mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 12:42:34 +01:00
Improve bx::saturateCast. (#357)
This commit is contained in:
committed by
GitHub
parent
a9f99c627e
commit
a69b0a72f7
@@ -227,7 +227,7 @@ namespace bx
|
|||||||
/// Performs `static_cast` of value `_from`, and if value doesn't fit result type `Ty` it clamps
|
/// Performs `static_cast` of value `_from`, and if value doesn't fit result type `Ty` it clamps
|
||||||
/// the value to `Ty` min/max.
|
/// the value to `Ty` min/max.
|
||||||
template<typename Ty, typename FromT>
|
template<typename Ty, typename FromT>
|
||||||
constexpr Ty saturateCast(const FromT& _from);
|
constexpr Ty saturateCast(FromT _from);
|
||||||
|
|
||||||
/// Performs `static_cast` of value `_from`, and returns true if the value `_from` is
|
/// Performs `static_cast` of value `_from`, and returns true if the value `_from` is
|
||||||
/// representable as `Ty`.
|
/// representable as `Ty`.
|
||||||
|
|||||||
@@ -174,9 +174,9 @@ namespace bx
|
|||||||
template<typename Ty, typename FromT>
|
template<typename Ty, typename FromT>
|
||||||
requires (isInteger< Ty>() || isFloatingPoint< Ty>() )
|
requires (isInteger< Ty>() || isFloatingPoint< Ty>() )
|
||||||
&& (isInteger<FromT>() || isFloatingPoint<FromT>() )
|
&& (isInteger<FromT>() || isFloatingPoint<FromT>() )
|
||||||
inline constexpr Ty saturateCast(const FromT& _from)
|
inline constexpr Ty saturateCast(FromT _from)
|
||||||
{
|
{
|
||||||
if constexpr (isSame<Ty, FromT>() )
|
if constexpr (isSame<RemoveCvType<Ty>, RemoveCvType<FromT> >() )
|
||||||
{
|
{
|
||||||
return _from;
|
return _from;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user