22
22
/* !
23
23
\mainpage Typesafe Integers and Bit Fields (enums)
24
24
25
+ [](https://github.com/stlab/enum-ops)
27
+
25
28
\section Description Description
26
29
27
30
\c enum_ops provides optional typesafe bitset and arithmetic operations for enumeration
59
62
60
63
/* *************************************************************************************************/
61
64
65
+ // / The stlab namespace.
62
66
namespace stlab {
63
67
64
68
/* *************************************************************************************************/
65
69
66
- // / Overload this for your enum to return std::true_type and enable bitwise operators.
70
+ // / Overload this for your enum in the enum namespace to return std::true_type and enable bitwise
71
+ // / operators.
67
72
auto stlab_enable_bitmask_enum (...) -> std::false_type;
68
- // / Overload this for your enum to return std::true_type and enable arithmetic operators.
73
+ // / Overload this for your enum in the enum namespace to return std::true_type and enable arithmetic
74
+ // / operators.
69
75
auto stlab_enable_arithmetic_enum (...) -> std::false_type;
70
76
71
77
/* *************************************************************************************************/
72
78
79
+ // / The implementation namespace.
73
80
namespace implementation {
74
81
75
82
/* *************************************************************************************************/
@@ -127,6 +134,7 @@ template <class T>
127
134
constexpr auto operator &(T lhs, T rhs)
128
135
-> std::enable_if_t <stlab::implementation::has_enabled_bitmask<T>, T> {
129
136
using underlying = std::underlying_type_t <T>;
137
+ // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
130
138
return static_cast <T>(static_cast <underlying>(lhs) & static_cast <underlying>(rhs));
131
139
}
132
140
@@ -135,6 +143,7 @@ template <class T>
135
143
constexpr auto operator ~(T a)
136
144
-> std::enable_if_t <stlab::implementation::has_enabled_bitmask<T>, T> {
137
145
using underlying = std::underlying_type_t <T>;
146
+ // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
138
147
return static_cast <T>(~static_cast <underlying>(a));
139
148
}
140
149
@@ -143,6 +152,7 @@ template <class T>
143
152
constexpr auto operator |(T lhs, T rhs)
144
153
-> std::enable_if_t <stlab::implementation::has_enabled_bitmask<T>, T> {
145
154
using underlying = std::underlying_type_t <T>;
155
+ // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
146
156
return static_cast <T>(static_cast <underlying>(lhs) | static_cast <underlying>(rhs));
147
157
}
148
158
@@ -151,6 +161,7 @@ template <class T>
151
161
constexpr auto operator ^(T lhs, T rhs)
152
162
-> std::enable_if_t <stlab::implementation::has_enabled_bitmask<T>, T> {
153
163
using underlying = std::underlying_type_t <T>;
164
+ // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
154
165
return static_cast <T>(static_cast <underlying>(lhs) ^ static_cast <underlying>(rhs));
155
166
}
156
167
@@ -159,17 +170,17 @@ template <class T>
159
170
constexpr auto operator <<(T lhs, std::size_t rhs)
160
171
-> std::enable_if_t <stlab::implementation::has_enabled_bitmask<T>, T> {
161
172
using underlying = std::make_unsigned_t <std::underlying_type_t <T>>;
162
- auto result = static_cast <underlying>(lhs) << static_cast <underlying>(rhs);
163
- return static_cast <T>(result );
173
+ // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
174
+ return static_cast <T>(static_cast <underlying>(lhs) << static_cast <underlying>(rhs) );
164
175
}
165
176
166
177
template <class T >
167
178
// / Right shift for bitmask-enabled enums.
168
179
constexpr auto operator >>(T lhs, std::size_t rhs)
169
180
-> std::enable_if_t <stlab::implementation::has_enabled_bitmask<T>, T> {
170
181
using underlying = std::make_unsigned_t <std::underlying_type_t <T>>;
171
- auto result = static_cast <underlying>(lhs) >> static_cast <underlying>(rhs);
172
- return static_cast <T>(result );
182
+ // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
183
+ return static_cast <T>(static_cast <underlying>(lhs) >> static_cast <underlying>(rhs) );
173
184
}
174
185
175
186
template <class T >
@@ -214,6 +225,7 @@ constexpr auto operator-(T lhs, U rhs)
214
225
stlab::implementation::is_convertible_to_underlying<U, T>::value,
215
226
T> {
216
227
using underlying = std::underlying_type_t <T>;
228
+ // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
217
229
return static_cast <T>(static_cast <underlying>(lhs) - static_cast <underlying>(rhs));
218
230
}
219
231
@@ -224,6 +236,7 @@ template <class T>
224
236
constexpr auto operator +(T a)
225
237
-> std::enable_if_t <stlab::implementation::has_enabled_arithmetic<T>, T> {
226
238
using underlying = std::underlying_type_t <T>;
239
+ // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
227
240
return static_cast <T>(+static_cast <underlying>(a));
228
241
}
229
242
@@ -232,6 +245,7 @@ template <class T>
232
245
constexpr auto operator -(T a)
233
246
-> std::enable_if_t <stlab::implementation::has_enabled_arithmetic<T>, T> {
234
247
using underlying = std::underlying_type_t <T>;
248
+ // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
235
249
return static_cast <T>(-static_cast <underlying>(a));
236
250
}
237
251
@@ -240,6 +254,7 @@ template <class T>
240
254
constexpr auto operator +(T lhs, T rhs)
241
255
-> std::enable_if_t <stlab::implementation::has_enabled_arithmetic<T>, T> {
242
256
using underlying = std::underlying_type_t <T>;
257
+ // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
243
258
return static_cast <T>(static_cast <underlying>(lhs) + static_cast <underlying>(rhs));
244
259
}
245
260
@@ -248,6 +263,7 @@ template <class T>
248
263
constexpr auto operator -(T lhs, T rhs)
249
264
-> std::enable_if_t <stlab::implementation::has_enabled_arithmetic<T>, T> {
250
265
using underlying = std::underlying_type_t <T>;
266
+ // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
251
267
return static_cast <T>(static_cast <underlying>(lhs) - static_cast <underlying>(rhs));
252
268
}
253
269
@@ -258,6 +274,7 @@ constexpr auto operator*(T lhs, U rhs)
258
274
stlab::implementation::is_convertible_to_underlying<U, T>::value,
259
275
T> {
260
276
using underlying = std::underlying_type_t <T>;
277
+ // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
261
278
return static_cast <T>(static_cast <underlying>(lhs) * rhs);
262
279
}
263
280
@@ -268,6 +285,7 @@ constexpr auto operator*(U lhs, T rhs)
268
285
stlab::implementation::is_convertible_to_underlying<U, T>::value,
269
286
T> {
270
287
using underlying = std::underlying_type_t <T>;
288
+ // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
271
289
return static_cast <T>(lhs * static_cast <underlying>(rhs));
272
290
}
273
291
@@ -278,6 +296,7 @@ constexpr auto operator/(T lhs, U rhs)
278
296
stlab::implementation::is_convertible_to_underlying<U, T>::value,
279
297
T> {
280
298
using underlying = std::underlying_type_t <T>;
299
+ // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
281
300
return static_cast <T>(static_cast <underlying>(lhs) / rhs);
282
301
}
283
302
@@ -288,6 +307,7 @@ constexpr auto operator%(T lhs, U rhs)
288
307
stlab::implementation::is_convertible_to_underlying<U, T>::value,
289
308
T> {
290
309
using underlying = std::underlying_type_t <T>;
310
+ // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
291
311
return static_cast <T>(static_cast <underlying>(lhs) % rhs);
292
312
}
293
313
0 commit comments