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 11/*
2- * Copyright (c) 2021, Thomas Sommer
2+ * Copyright (c) 2021-2022 , Thomas Sommer
33 *
44 * This file is part of the modm project.
55 *
@@ -32,6 +32,7 @@ struct uint_t
3232 (Bits <= 64 ), uint64_t >>>>;
3333};
3434
35+ // / ETL also got such a trait: https://www.etlcpp.com/smallest.html
3536template <int Bits>
3637using least_uint = typename modm::uint_t <Bits>::least;
3738
@@ -68,5 +69,25 @@ struct fits_any {
6869template <typename ... Ts>
6970using fits_any_t = typename fits_any<Ts...>::type;
7071
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;
7192// / @}
72- }
93+ } // namespace modm
You can’t perform that action at this time.
0 commit comments