48 static_assert(std::is_integral_v<From>,
"From has to be an integral type.");
49 static_assert(std::is_integral_v<To>,
"To has to be an integral type.");
53 std::is_signed_v<From> || std::numeric_limits<From>::min() == 0,
54 "The type From has to include the number 0."
57 std::is_signed_v<To> || std::numeric_limits<To>::min() == 0,
58 "The type To has to include the number 0."
62 if constexpr (std::is_signed_v<From> && std::is_signed_v<To>) {
64 std::numeric_limits<From>::digits <= std::numeric_limits<intmax_t>::digits,
65 "From has more bits than intmax_t."
68 std::numeric_limits<To>::digits <= std::numeric_limits<intmax_t>::digits,
69 "To has more bits than intmax_t."
73 std::numeric_limits<From>::digits <= std::numeric_limits<uintmax_t>::digits,
74 "From has more bits than uintmax_t."
77 std::numeric_limits<To>::digits <= std::numeric_limits<uintmax_t>::digits,
78 "To has more bits than uintmax_t."
83 if constexpr (std::is_unsigned_v<From> && std::is_unsigned_v<To>) {
84 return static_cast<uintmax_t>(value) <=
static_cast<uintmax_t>(std::numeric_limits<To>::max());
85 }
else if constexpr (std::is_signed_v<From> && std::is_signed_v<To>) {
86 return static_cast<intmax_t>(value) >=
static_cast<intmax_t>(std::numeric_limits<To>::min())
87 &&
static_cast<intmax_t>(value) <=
static_cast<intmax_t>(std::numeric_limits<To>::max());
88 }
else if constexpr (std::is_signed_v<From> && std::is_unsigned_v<To>) {
92 return static_cast<uintmax_t>(value) <=
static_cast<uintmax_t>(std::numeric_limits<To>::max());
94 }
else if constexpr (std::is_unsigned_v<From> && std::is_signed_v<To>) {
95 return static_cast<uintmax_t>(value) <=
static_cast<uintmax_t>(std::numeric_limits<To>::max());
constexpr To throwing_cast(From value)
Casts an integer value to the integer type To. If the value is outside To's range,...
Definition checking_casts.hpp:135
constexpr To asserting_cast(From value) KAMPING_NOEXCEPT
Casts an integer value to the integer type To. If the value is outside To's range,...
Definition checking_casts.hpp:115
constexpr bool in_range(From value) noexcept
Checks if an integer value can be safely casted into an integer type To, that is, it lies in the rang...
Definition checking_casts.hpp:47