AS5047U Driver 0.1.0
API reference
Loading...
Searching...
No Matches
as5047u_detail.hpp
Go to the documentation of this file.
1
11#ifndef AS5047U_DETAIL_HPP
12#define AS5047U_DETAIL_HPP
13
14#include <concepts>
15#include <cstdint>
16#include <type_traits>
17
18namespace as5047u::detail {
19
33template <typename Port, typename Sig>
34 requires std::is_class_v<Port> && std::is_function_v<Sig>
35struct ExactHook;
36
38template <typename Port, typename R, typename... Args>
39 requires std::is_class_v<Port>
40struct ExactHook<Port, R(Args...) noexcept> {
42 static void Take(R (Port::*hook)(Args...) noexcept) noexcept;
44 static void Take(R (Port::*hook)(Args...) const noexcept) noexcept;
45};
46
48template <typename T>
49concept ClassType = std::is_class_v<T>;
50
53template <ClassType>
54inline constexpr bool kAlwaysFalse = false;
55
57template <typename E>
58concept Enumeration = std::is_enum_v<E>;
59
64template <Enumeration E>
65[[nodiscard]] constexpr std::underlying_type_t<E> ToUnderlying(E e) noexcept {
66 return static_cast<std::underlying_type_t<E>>(e);
67}
68
73template <Enumeration E>
74struct EnumLast;
75
80template <Enumeration E>
81[[nodiscard]] constexpr bool IsEnumerator(E e) noexcept {
82 return static_cast<uint32_t>(ToUnderlying(e)) <=
83 static_cast<uint32_t>(ToUnderlying(EnumLast<E>::kValue));
84}
85
88inline void LiteralOutOfRange() noexcept {}
89
96consteval uint8_t operator""_u8(unsigned long long value) noexcept {
97 if (value > 0xFFU) {
98 LiteralOutOfRange();
99 }
100 return static_cast<uint8_t>(value);
101}
102
108consteval uint16_t operator""_u16(unsigned long long value) noexcept {
109 if (value > 0xFFFFU) {
110 LiteralOutOfRange();
111 }
112 return static_cast<uint16_t>(value);
113}
114
121consteval uint32_t operator""_u32(unsigned long long value) noexcept {
122 if (value > 0xFFFF'FFFFU) {
123 LiteralOutOfRange();
124 }
125 return static_cast<uint32_t>(value);
126}
127
128} // namespace as5047u::detail
129
130#endif // AS5047U_DETAIL_HPP