11template <
class Src,
class Dest>
15 : sizeof(Dest) >= sizeof(Src));
17template <
class Dest,
class Src>
23 static_assert(
sizeof(Dest) >=
sizeof(Src) + not_same,
"Destination is too small to hold all values of source");
24 return static_cast<Dest
>(s);
27template <
class Dest,
class Src>
31 return static_cast<Dest
>(safe_cast<std::underlying_type_t<Dest>>(s));
34template <
class Dest,
class Src>
45template <
class Dest,
class Src>
51 "Only unsafe if casting signed to unsigned or "
52 "destination is too small");
53 return static_cast<Dest
>(s);
56template <
class Dest,
class Src>
60 return static_cast<Dest
>(unsafe_cast<std::underlying_type_t<Dest>>(s));
63template <
class Dest,
class Src>
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr std::enable_if_t< std::is_integral_v< Dest > &&std::is_integral_v< Src >, Dest > unsafe_cast(Src s) noexcept
constexpr std::enable_if_t< std::is_integral_v< Dest > &&std::is_integral_v< Src >, Dest > safe_cast(Src s) noexcept