llmx-rtaco 0.0.1
RTNL-only netlink control-plane library for Linux (C++23).
Loading...
Searching...
No Matches
nl_utils.hxx
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4
5namespace llmx {
6namespace rtaco {
7
25template<typename _Tp>
26struct enable_bitmask_operators : std::false_type {};
27
28template<typename _Tp>
30
31template<typename E>
33constexpr E operator|(E lhs, E rhs) {
34 using T = std::underlying_type_t<E>;
35 return static_cast<E>(static_cast<T>(lhs) | static_cast<T>(rhs));
36}
37
38template<typename E>
40constexpr E operator&(E lhs, E rhs) {
41 using T = std::underlying_type_t<E>;
42 return static_cast<E>(static_cast<T>(lhs) & static_cast<T>(rhs));
43}
44
45template<typename E>
47constexpr E operator^(E lhs, E rhs) {
48 using T = std::underlying_type_t<E>;
49 return static_cast<E>(static_cast<T>(lhs) ^ static_cast<T>(rhs));
50}
51
52template<typename E>
54constexpr E operator~(E val) {
55 using T = std::underlying_type_t<E>;
56 return static_cast<E>(~static_cast<T>(val));
57}
58
59template<typename E>
61constexpr E& operator|=(E& lhs, E rhs) {
62 lhs = lhs | rhs;
63 return lhs;
64}
65
66template<typename E>
68constexpr E& operator&=(E& lhs, E rhs) {
69 lhs = lhs & rhs;
70 return lhs;
71}
72
73template<typename E>
75constexpr E& operator^=(E& lhs, E rhs) {
76 lhs = lhs ^ rhs;
77 return lhs;
78}
79
80template<typename E, std::integral U>
82constexpr E operator<<(E lhs, U shift) {
83 using T = std::underlying_type_t<E>;
84 return static_cast<E>(static_cast<T>(lhs) << shift);
85}
86
87template<typename E, std::integral U>
89constexpr E operator>>(E lhs, U shift) {
90 using T = std::underlying_type_t<E>;
91 return static_cast<E>(static_cast<T>(lhs) >> shift);
92}
93
94} // namespace rtaco
95} // namespace llmx
Definition nl_common.hxx:21
constexpr E operator~(E val)
Definition nl_utils.hxx:54
constexpr E & operator^=(E &lhs, E rhs)
Definition nl_utils.hxx:75
constexpr E & operator|=(E &lhs, E rhs)
Definition nl_utils.hxx:61
constexpr E operator|(E lhs, E rhs)
Definition nl_utils.hxx:33
constexpr bool enable_bitmask_operators_v
Definition nl_utils.hxx:29
constexpr E & operator&=(E &lhs, E rhs)
Definition nl_utils.hxx:68
constexpr E operator<<(E lhs, U shift)
Definition nl_utils.hxx:82
constexpr E operator^(E lhs, E rhs)
Definition nl_utils.hxx:47
constexpr E operator>>(E lhs, U shift)
Definition nl_utils.hxx:89
constexpr E operator&(E lhs, E rhs)
Definition nl_utils.hxx:40
Definition nl_common.hxx:20
Enable bitwise operators for an enum class.
Definition nl_utils.hxx:26