11#ifndef MAX22200_DETAIL_HPP
12#define MAX22200_DETAIL_HPP
19namespace max22200::detail {
34template <
typename Port,
typename Sig>
35 requires std::is_class_v<Port> && std::is_function_v<Sig>
39template <
typename Port,
typename R,
typename... Args>
40 requires std::is_class_v<Port>
41struct ExactHook<Port, R(Args...) noexcept> {
43 static void Take(R (Port::*hook)(Args...) noexcept) noexcept;
45 static void Take(R (Port::*hook)(Args...) const noexcept) noexcept;
50concept ClassType = std::is_class_v<T>;
55inline constexpr bool kAlwaysFalse =
false;
59concept Enumeration = std::is_enum_v<E>;
65template <Enumeration E>
66[[nodiscard]]
constexpr std::underlying_type_t<E> ToUnderlying(E e)
noexcept {
67 return static_cast<std::underlying_type_t<E>
>(e);
74template <Enumeration E>
81template <Enumeration E>
82[[nodiscard]]
constexpr bool IsEnumerator(E e)
noexcept {
83 return static_cast<uint32_t
>(ToUnderlying(e)) <=
84 static_cast<uint32_t
>(ToUnderlying(EnumLast<E>::kValue));
92template <
typename Reg, u
int32_t Shift, u
int32_t W
idth>
93 requires std::unsigned_integral<Reg> && (Width > 0U) && (Width < 32U) &&
94 ((Shift + Width) <=
static_cast<uint32_t
>(std::numeric_limits<Reg>::digits))
97 static constexpr uint32_t kMax = (uint32_t{1} << Width) - 1U;
99 static constexpr Reg kMask =
static_cast<Reg
>(kMax << Shift);
102 [[nodiscard]]
static constexpr Reg Insert(Reg reg, uint32_t value)
noexcept {
103 return static_cast<Reg
>((
static_cast<uint32_t
>(reg) & ~
static_cast<uint32_t
>(kMask)) |
104 ((value & kMax) << Shift));
107 [[nodiscard]]
static constexpr uint32_t Extract(Reg reg)
noexcept {
108 return (
static_cast<uint32_t
>(reg) >> Shift) & kMax;
116inline void LiteralOutOfRange() noexcept {}
124consteval uint8_t
operator""_u8(
unsigned long long v)
noexcept {
128 return static_cast<uint8_t
>(v);
137consteval uint32_t
operator""_u32(
unsigned long long v)
noexcept {
138 if (v > 0xFFFF'FFFFULL) {
141 return static_cast<uint32_t
>(v);