summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util/coretmpl.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/util/coretmpl.h')
-rw-r--r--src/lib/util/coretmpl.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/lib/util/coretmpl.h b/src/lib/util/coretmpl.h
index 8d317db7596..08c3a6b8678 100644
--- a/src/lib/util/coretmpl.h
+++ b/src/lib/util/coretmpl.h
@@ -32,6 +32,14 @@
#include <utility>
#include <vector>
+// Generate a N-bit mask at compile time. N better be constant.
+// Works even for signed types
+
+template<typename T> constexpr T make_bitmask(unsigned int N)
+{
+ return T((N < (8 * sizeof(T)) ? (std::make_unsigned_t<T>(1) << N) : std::make_unsigned_t<T>(0)) - 1);
+}
+
// ======================> simple_list