7#if defined(__cpp_lib_byteswap) && __cpp_lib_byteswap >= 202110L
10#if defined(__cpp_lib_forward_like)
17 template <
class T,
class...
TYPES>
18 constexpr inline bool is_any_of_v = std::disjunction_v<std::is_same<T, TYPES>...>;
23 using with_reference =
_Ty&;
30 concept dereferenceable =
requires(T &
t) {
31 { *
t } -> detail::can_reference;
34#if defined(__cpp_lib_forward_like)
35 using std::forward_like;
37 template <
class Ty,
class Uty>
38 [[
nodiscard]] [[msvc::intrinsic]]
constexpr auto&& forward_like(
Uty&&
Ux)
noexcept
40 static_assert(detail::can_reference<Ty>,
"forward_like's first template argument must be a referenceable type.");
42 using UnrefT = std::remove_reference_t<Ty>;
43 using UnrefU = std::remove_reference_t<Uty>;
44 if constexpr (std::is_const_v<UnrefT>) {
45 if constexpr (std::is_lvalue_reference_v<Ty>) {
46 return static_cast<const UnrefU&
>(
Ux);
49 return static_cast<const UnrefU&&
>(
Ux);
53 if constexpr (std::is_lvalue_reference_v<Ty>) {
63#if __cpp_lib_byteswap < 202110L
65 inline constexpr bool always_false =
false;
67 [[
nodiscard]]
constexpr unsigned short byteswap_ushort(
const unsigned short val)
noexcept {
68 return static_cast<unsigned short>((
val << 8) | (
val >> 8));
71 [[
nodiscard]]
constexpr unsigned long byteswap_ulong(
const unsigned long val)
noexcept {
72 return (
val << 24) | ((
val << 8) & 0x00FF'0000) | ((
val >> 8) & 0x0000'FF00) | (
val >> 24);
75 [[
nodiscard]]
constexpr unsigned long long byteswap_uint64(
const unsigned long long val)
noexcept {
76 return (
val << 56) | ((
val << 40) & 0x00FF'0000'0000'0000) | ((
val << 24) & 0x0000'FF00'0000'0000)
77 | ((
val << 8) & 0x0000'00FF'0000'0000) | ((
val >> 8) & 0x0000'0000'FF00'0000)
78 | ((
val >> 24) & 0x0000'0000'00FF'0000) | ((
val >> 40) & 0x0000'0000'0000'FF00) | (
val >> 56);
81 template <
class T, std::enable_if_t<std::is_
integral_v<T>,
int> = 0>
84 if constexpr (
sizeof(T) == 1)
86 else if constexpr (
sizeof(T) == 2)
87 return static_cast<T
>(byteswap_ushort(
static_cast<unsigned short>(
val)));
88 else if constexpr (
sizeof(T) == 4)
89 return static_cast<T
>(byteswap_ulong(
static_cast<unsigned long>(
val)));
90 else if constexpr (
sizeof(T) == 8)
91 return static_cast<T
>(byteswap_uint64(
static_cast<unsigned long long>(
val)));
constexpr auto bit_count
Equal to the number of bits in the type.
The below code is based on Sun's libm library code, which is licensed under the following license:
Primary namespace for everything in this library.