1#ifndef XRPL_BASICS_SAFE_CAST_H_INCLUDED
2#define XRPL_BASICS_SAFE_CAST_H_INCLUDED
12template <
class Src,
class Dest>
16 ?
sizeof(Dest) >
sizeof(Src)
17 : sizeof(Dest) >= sizeof(Src));
19template <
class Dest,
class Src>
26 "Cannot cast signed to unsigned");
27 constexpr unsigned not_same =
30 sizeof(Dest) >=
sizeof(Src) + not_same,
31 "Destination is too small to hold all values of source");
32 return static_cast<Dest
>(s);
35template <
class Dest,
class Src>
40 return static_cast<Dest
>(safe_cast<std::underlying_type_t<Dest>>(s));
43template <
class Dest,
class Src>
55template <
class Dest,
class Src>
62 "Only unsafe if casting signed to unsigned or "
63 "destination is too small");
64 return static_cast<Dest
>(s);
67template <
class Dest,
class Src>
72 return static_cast<Dest
>(unsafe_cast<std::underlying_type_t<Dest>>(s));
75template <
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 > safe_cast(Src s) noexcept
constexpr std::enable_if_t< std::is_integral_v< Dest > &&std::is_integral_v< Src >, Dest > unsafe_cast(Src s) noexcept