Skip to content

Commit 984da28

Browse files
committed
More cleanup and structuring tests.
1 parent 808ea2f commit 984da28

File tree

5 files changed

+469
-167
lines changed

5 files changed

+469
-167
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ cpp_library_setup(
2222
NAMESPACE stlab
2323
HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/stlab/enum_ops.hpp
2424
EXAMPLES enum_ops_example enum_ops_example_fail
25-
TESTS enum_ops_all_tests
25+
TESTS enum_ops_tests
2626
DOCS_EXCLUDE_SYMBOLS "stlab::implementation"
2727
)

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# stlab::enum-ops
22

3+
[![CI][ci-badge]][ci-link]
4+
[![Documentation][docs-badge]][docs-link]
35
[![License][license-badge]][license-link]
46

57
Type-safe bitmask and arithmetic operators for enum types.
68

9+
[ci-badge]: https://github.com/stlab/enum-ops/workflows/CI/badge.svg
10+
[ci-link]: https://github.com/stlab/enum-ops/actions/workflows/ci.yml
11+
[docs-badge]: https://img.shields.io/badge/docs-github%20pages-blue
12+
[docs-link]: https://stlab.github.io/enum-ops/
713
[license-badge]: https://img.shields.io/badge/license-BSL%201.0-blue.svg
814
[license-link]: https://github.com/stlab/enum-ops/blob/main/LICENSE
915

@@ -14,7 +20,7 @@ Type-safe bitmask and arithmetic operators for enum types.
1420
- Bitmask operators: `~ | & ^ |= &= ^=`
1521
- Shift operators: `<< >> <<= >>=`
1622
- Arithmetic operators: `+ - * / % += -= *= /=` and increment/decrement
17-
- Comparisons with `nullptr` and logical `!` for convenience
23+
- Comparisons with `0` and logical `!` for convenience
1824

1925
Opt-in is done by declaring one or both of:
2026

include/stlab/enum_ops.hpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
/*!
2323
\mainpage Typesafe Integers and Bit Fields (enums)
2424
25+
[![View on
26+
GitHub](https://img.shields.io/badge/GitHub-enum--ops-181717?logo=github&style=flat)](https://github.com/stlab/enum-ops)
27+
2528
\section Description Description
2629
2730
\c enum_ops provides optional typesafe bitset and arithmetic operations for enumeration
@@ -59,17 +62,21 @@
5962

6063
/**************************************************************************************************/
6164

65+
/// The stlab namespace.
6266
namespace stlab {
6367

6468
/**************************************************************************************************/
6569

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.
6772
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.
6975
auto stlab_enable_arithmetic_enum(...) -> std::false_type;
7076

7177
/**************************************************************************************************/
7278

79+
/// The implementation namespace.
7380
namespace implementation {
7481

7582
/**************************************************************************************************/
@@ -127,6 +134,7 @@ template <class T>
127134
constexpr auto operator&(T lhs, T rhs)
128135
-> std::enable_if_t<stlab::implementation::has_enabled_bitmask<T>, T> {
129136
using underlying = std::underlying_type_t<T>;
137+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
130138
return static_cast<T>(static_cast<underlying>(lhs) & static_cast<underlying>(rhs));
131139
}
132140

@@ -135,6 +143,7 @@ template <class T>
135143
constexpr auto operator~(T a)
136144
-> std::enable_if_t<stlab::implementation::has_enabled_bitmask<T>, T> {
137145
using underlying = std::underlying_type_t<T>;
146+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
138147
return static_cast<T>(~static_cast<underlying>(a));
139148
}
140149

@@ -143,6 +152,7 @@ template <class T>
143152
constexpr auto operator|(T lhs, T rhs)
144153
-> std::enable_if_t<stlab::implementation::has_enabled_bitmask<T>, T> {
145154
using underlying = std::underlying_type_t<T>;
155+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
146156
return static_cast<T>(static_cast<underlying>(lhs) | static_cast<underlying>(rhs));
147157
}
148158

@@ -151,6 +161,7 @@ template <class T>
151161
constexpr auto operator^(T lhs, T rhs)
152162
-> std::enable_if_t<stlab::implementation::has_enabled_bitmask<T>, T> {
153163
using underlying = std::underlying_type_t<T>;
164+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
154165
return static_cast<T>(static_cast<underlying>(lhs) ^ static_cast<underlying>(rhs));
155166
}
156167

@@ -159,17 +170,17 @@ template <class T>
159170
constexpr auto operator<<(T lhs, std::size_t rhs)
160171
-> std::enable_if_t<stlab::implementation::has_enabled_bitmask<T>, T> {
161172
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));
164175
}
165176

166177
template <class T>
167178
/// Right shift for bitmask-enabled enums.
168179
constexpr auto operator>>(T lhs, std::size_t rhs)
169180
-> std::enable_if_t<stlab::implementation::has_enabled_bitmask<T>, T> {
170181
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));
173184
}
174185

175186
template <class T>
@@ -214,6 +225,7 @@ constexpr auto operator-(T lhs, U rhs)
214225
stlab::implementation::is_convertible_to_underlying<U, T>::value,
215226
T> {
216227
using underlying = std::underlying_type_t<T>;
228+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
217229
return static_cast<T>(static_cast<underlying>(lhs) - static_cast<underlying>(rhs));
218230
}
219231

@@ -224,6 +236,7 @@ template <class T>
224236
constexpr auto operator+(T a)
225237
-> std::enable_if_t<stlab::implementation::has_enabled_arithmetic<T>, T> {
226238
using underlying = std::underlying_type_t<T>;
239+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
227240
return static_cast<T>(+static_cast<underlying>(a));
228241
}
229242

@@ -232,6 +245,7 @@ template <class T>
232245
constexpr auto operator-(T a)
233246
-> std::enable_if_t<stlab::implementation::has_enabled_arithmetic<T>, T> {
234247
using underlying = std::underlying_type_t<T>;
248+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
235249
return static_cast<T>(-static_cast<underlying>(a));
236250
}
237251

@@ -240,6 +254,7 @@ template <class T>
240254
constexpr auto operator+(T lhs, T rhs)
241255
-> std::enable_if_t<stlab::implementation::has_enabled_arithmetic<T>, T> {
242256
using underlying = std::underlying_type_t<T>;
257+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
243258
return static_cast<T>(static_cast<underlying>(lhs) + static_cast<underlying>(rhs));
244259
}
245260

@@ -248,6 +263,7 @@ template <class T>
248263
constexpr auto operator-(T lhs, T rhs)
249264
-> std::enable_if_t<stlab::implementation::has_enabled_arithmetic<T>, T> {
250265
using underlying = std::underlying_type_t<T>;
266+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
251267
return static_cast<T>(static_cast<underlying>(lhs) - static_cast<underlying>(rhs));
252268
}
253269

@@ -258,6 +274,7 @@ constexpr auto operator*(T lhs, U rhs)
258274
stlab::implementation::is_convertible_to_underlying<U, T>::value,
259275
T> {
260276
using underlying = std::underlying_type_t<T>;
277+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
261278
return static_cast<T>(static_cast<underlying>(lhs) * rhs);
262279
}
263280

@@ -268,6 +285,7 @@ constexpr auto operator*(U lhs, T rhs)
268285
stlab::implementation::is_convertible_to_underlying<U, T>::value,
269286
T> {
270287
using underlying = std::underlying_type_t<T>;
288+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
271289
return static_cast<T>(lhs * static_cast<underlying>(rhs));
272290
}
273291

@@ -278,6 +296,7 @@ constexpr auto operator/(T lhs, U rhs)
278296
stlab::implementation::is_convertible_to_underlying<U, T>::value,
279297
T> {
280298
using underlying = std::underlying_type_t<T>;
299+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
281300
return static_cast<T>(static_cast<underlying>(lhs) / rhs);
282301
}
283302

@@ -288,6 +307,7 @@ constexpr auto operator%(T lhs, U rhs)
288307
stlab::implementation::is_convertible_to_underlying<U, T>::value,
289308
T> {
290309
using underlying = std::underlying_type_t<T>;
310+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
291311
return static_cast<T>(static_cast<underlying>(lhs) % rhs);
292312
}
293313

tests/enum_ops_all_tests.cpp

Lines changed: 0 additions & 159 deletions
This file was deleted.

0 commit comments

Comments
 (0)