File tree Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright (c) 2021, Thomas Sommer
2
+ * Copyright (c) 2021-2022 , Thomas Sommer
3
3
*
4
4
* This file is part of the modm project.
5
5
*
@@ -32,6 +32,7 @@ struct uint_t
32
32
(Bits <= 64 ), uint64_t >>>>;
33
33
};
34
34
35
+ // / ETL also got such a trait: https://www.etlcpp.com/smallest.html
35
36
template <int Bits>
36
37
using least_uint = typename modm::uint_t <Bits>::least;
37
38
@@ -68,5 +69,25 @@ struct fits_any {
68
69
template <typename ... Ts>
69
70
using fits_any_t = typename fits_any<Ts...>::type;
70
71
72
+ // / @ingroup modm_math_utils
73
+
74
+ // / Generates a bitmask with N bits set
75
+ // / @author Thomas Sommer
76
+ template <unsigned int N>
77
+ struct bitmask {
78
+ using value_type = uint_t <N>::least;
79
+ static constexpr value_type value = std::pow(2 , N) - 1 ;
80
+
81
+ constexpr operator value_type () const noexcept
82
+ {
83
+ return value;
84
+ }
85
+ };
86
+
87
+ template <unsigned int N>
88
+ using bitmask_t = typename bitmask<N>::value_type;
89
+
90
+ template <unsigned int N>
91
+ static constexpr bitmask_t <N> bitmask_v = bitmask<N>::value;
71
92
// / @}
72
- }
93
+ } // namespace modm
You can’t perform that action at this time.
0 commit comments