NTC_THERMISTOR Driver 0.1.0
API reference
Loading...
Searching...
No Matches
ntc_thermistor_detail.hpp
Go to the documentation of this file.
1
13#ifndef NTC_THERMISTOR_DETAIL_HPP
14#define NTC_THERMISTOR_DETAIL_HPP
15
16#include <cstdint>
17#include <type_traits>
18
19namespace ntc_thermistor::detail {
20
26void LiteralOutOfRange() noexcept;
27
35consteval std::uint8_t operator""_u8(unsigned long long v) noexcept {
36 if (v > 0xFFULL) {
37 LiteralOutOfRange();
38 }
39 return static_cast<std::uint8_t>(v);
40}
41
48consteval std::uint16_t operator""_u16(unsigned long long v) noexcept {
49 if (v > 0xFFFFULL) {
50 LiteralOutOfRange();
51 }
52 return static_cast<std::uint16_t>(v);
53}
54
62consteval std::uint32_t operator""_u32(unsigned long long v) noexcept {
63 if (v > 0xFFFF'FFFFULL) {
64 LiteralOutOfRange();
65 }
66 return static_cast<std::uint32_t>(v);
67}
68
84template <typename Port, typename Sig>
85 requires std::is_class_v<Port> && std::is_function_v<Sig>
86struct ExactHook;
87
89template <typename Port, typename R, typename... Args>
90 requires std::is_class_v<Port>
91struct ExactHook<Port, R(Args...) noexcept> {
93 static void Take(R (Port::*hook)(Args...) noexcept) noexcept;
95 static void Take(R (Port::*hook)(Args...) const noexcept) noexcept;
96};
97
100template <typename T>
101concept ClassType = std::is_class_v<T>;
102
105template <ClassType>
106inline constexpr bool kAlwaysFalse = false;
107
110template <typename E>
111concept Enumeration = std::is_enum_v<E>;
112
117template <Enumeration E>
118[[nodiscard]] constexpr std::underlying_type_t<E> ToUnderlying(E e) noexcept {
119 return static_cast<std::underlying_type_t<E>>(e);
120}
121
127template <Enumeration E>
128struct EnumLast;
129
135template <Enumeration E>
136[[nodiscard]] constexpr bool IsEnumerator(E e) noexcept {
137 return static_cast<uint32_t>(ToUnderlying(e)) <=
138 static_cast<uint32_t>(ToUnderlying(EnumLast<E>::kValue));
139}
140
141} // namespace ntc_thermistor::detail
142
143#endif // NTC_THERMISTOR_DETAIL_HPP