MCP9700 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
mcp9700_detail.hpp
Go to the documentation of this file.
1
13#ifndef MCP9700_DETAIL_HPP
14#define MCP9700_DETAIL_HPP
15
16#include <concepts>
17#include <cstdint>
18#include <type_traits>
19
20namespace mcp9700::detail {
21
27void LiteralOutOfRange() noexcept;
28
36consteval std::uint8_t operator""_u8(unsigned long long v) noexcept {
37 if (v > 0xFFULL) {
38 LiteralOutOfRange();
39 }
40 return static_cast<std::uint8_t>(v);
41}
42
50consteval std::uint32_t operator""_u32(unsigned long long v) noexcept {
51 if (v > 0xFFFF'FFFFULL) {
52 LiteralOutOfRange();
53 }
54 return static_cast<std::uint32_t>(v);
55}
56
72template <typename Port, typename Sig>
73 requires std::is_class_v<Port> && std::is_function_v<Sig>
74struct ExactHook;
75
77template <typename Port, typename R, typename... Args>
78 requires std::is_class_v<Port>
79struct ExactHook<Port, R(Args...) noexcept> {
81 static void Take(R (Port::*hook)(Args...) noexcept) noexcept;
83 static void Take(R (Port::*hook)(Args...) const noexcept) noexcept;
84};
85
88template <typename T>
89concept ClassType = std::is_class_v<T>;
90
93template <ClassType>
94inline constexpr bool kAlwaysFalse = false;
95
98template <typename E>
99concept Enumeration = std::is_enum_v<E>;
100
105template <Enumeration E>
106[[nodiscard]] constexpr std::underlying_type_t<E> ToUnderlying(E e) noexcept {
107 return static_cast<std::underlying_type_t<E>>(e);
108}
109
115template <Enumeration E>
116struct EnumLast;
117
123template <Enumeration E>
124[[nodiscard]] constexpr bool IsEnumerator(E e) noexcept {
125 return static_cast<uint32_t>(ToUnderlying(e)) <=
126 static_cast<uint32_t>(ToUnderlying(EnumLast<E>::kValue));
127}
128
129} // namespace mcp9700::detail
130
131#endif // MCP9700_DETAIL_HPP