From add2cfcb96d75cd16f7b0bf554bb30d97e720111 Mon Sep 17 00:00:00 2001 From: Wunkolo Date: Wed, 23 Feb 2022 10:08:32 -0800 Subject: [PATCH] bit_util: Add `bit` utility function Extracts a singular bit, as a bool, from the specified compile-time index. --- src/common/bit_util.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/common/bit_util.h b/src/common/bit_util.h index f50d3308a9..f37538e06c 100644 --- a/src/common/bit_util.h +++ b/src/common/bit_util.h @@ -57,4 +57,11 @@ requires std::is_integral_v return static_cast(1ULL << ((8U * sizeof(T)) - std::countl_zero(value - 1U))); } +template +requires std::is_integral_v +[[nodiscard]] constexpr bool Bit(const T value) { + static_assert(bit_index < BitSize(), "bit_index must be smaller than size of T"); + return ((value >> bit_index) & T(1)) == T(1); +} + } // namespace Common