Hi,
What do you think of the usefulness of two such functions? Do they belong in the standard library?
template <typename T>
requires std::is_integral_v<T>
constexpr auto as_signed(T v) noexcept
{
return static_cast<std::make_signed_t<T>>(v);
}
template <typename T>
requires std::is_integral_v<T>
constexpr auto as_unsigned(T v) noexcept
{
return static_cast<std::make_unsigned_t<T>>(v);
}
The
thing is that the std::container::size() functions return an unsigned
type but we often deal with signed types along with them and the
compilers complain about comparison between these types when warnings
are enabled. Such functions are useful in these situations, in my
experience.