diff --git a/src/lib/support/SafeInt.h b/src/lib/support/SafeInt.h index 2835ef05534155..ecf6d8721dcb1d 100644 --- a/src/lib/support/SafeInt.h +++ b/src/lib/support/SafeInt.h @@ -37,10 +37,11 @@ namespace chip { template ::value, int> = 0> bool CanCastTo(U arg) { + using namespace std; // U might be a reference to an integer type, if we're assigning from // something passed by reference. - typedef typename std::remove_reference::type V; // V for "value" - static_assert(std::is_integral::value, "Must be assigning from an integral type"); + typedef typename remove_reference::type V; // V for "value" + static_assert(is_integral::value, "Must be assigning from an integral type"); // We want to check that "arg" can fit inside T but without doing any tests // that are always true or always false due to the types involved, which @@ -63,44 +64,44 @@ bool CanCastTo(U arg) // of T and V is signed and the other is unsigned: there might not be a // single integer type that can represent _both_ the value of arg and the // minimal/maximal value. - if (std::numeric_limits::is_signed && std::numeric_limits::is_signed) + if (numeric_limits::is_signed && numeric_limits::is_signed) { - if (static_cast(std::numeric_limits::max()) <= static_cast(std::numeric_limits::max()) && - static_cast(std::numeric_limits::min()) >= static_cast(std::numeric_limits::min())) + if (static_cast(numeric_limits::max()) <= static_cast(numeric_limits::max()) && + static_cast(numeric_limits::min()) >= static_cast(numeric_limits::min())) { // Any checks on arg would be trivially true; don't even do them, to // avoid warnings. return true; } - return static_cast(std::numeric_limits::min()) <= static_cast(arg) && - static_cast(arg) <= static_cast(std::numeric_limits::max()); + return static_cast(numeric_limits::min()) <= static_cast(arg) && + static_cast(arg) <= static_cast(numeric_limits::max()); } - if (!std::numeric_limits::is_signed && !std::numeric_limits::is_signed) + if (!numeric_limits::is_signed && !numeric_limits::is_signed) { - if (static_cast(std::numeric_limits::max()) <= static_cast(std::numeric_limits::max())) + if (static_cast(numeric_limits::max()) <= static_cast(numeric_limits::max())) { // Any checks on arg would be trivially true; don't even do them, to // avoid warnings. return true; } - return static_cast(arg) <= static_cast(std::numeric_limits::max()); + return static_cast(arg) <= static_cast(numeric_limits::max()); } - if (std::numeric_limits::is_signed) + if (numeric_limits::is_signed) { - static_assert(std::numeric_limits::max() >= 0, "What weird type is this?"); - if (static_cast(std::numeric_limits::max()) <= static_cast(std::numeric_limits::max())) + static_assert(numeric_limits::max() >= 0, "What weird type is this?"); + if (static_cast(numeric_limits::max()) <= static_cast(numeric_limits::max())) { return true; } - return static_cast(arg) <= static_cast(std::numeric_limits::max()); + return static_cast(arg) <= static_cast(numeric_limits::max()); } - return 0 <= arg && static_cast(arg) <= static_cast(std::numeric_limits::max()); + return 0 <= arg && static_cast(arg) <= static_cast(numeric_limits::max()); } template ::value, int> = 0> @@ -126,9 +127,10 @@ bool CanCastTo(U arg) template typename std::enable_if::value, typename std::make_signed::type>::type CastToSigned(T arg) { - typedef typename std::make_signed::type signed_type; + using namespace std; + typedef typename make_signed::type signed_type; - if (arg <= static_cast(std::numeric_limits::max())) + if (arg <= static_cast(numeric_limits::max())) { return static_cast(arg); } @@ -140,7 +142,7 @@ typename std::enable_if::value, typename std::make_signed // // then noting that both (numeric_limits::max() - arg) and its negation // are guaranteed to fit in signed_type. - signed_type diff = static_cast(std::numeric_limits::max() - arg); + signed_type diff = static_cast(numeric_limits::max() - arg); return static_cast(-diff - 1); } diff --git a/src/lib/support/TypeTraits.h b/src/lib/support/TypeTraits.h index 1eb8015409c512..4d326027a17753 100644 --- a/src/lib/support/TypeTraits.h +++ b/src/lib/support/TypeTraits.h @@ -34,11 +34,7 @@ namespace chip { #if __cplusplus >= 202300L -template -constexpr auto to_underlying(T e) -{ - return std::to_underlying(e); -} +using to_underlying = std::to_underlying; #else /**