diff options
Diffstat (limited to 'src/lib/util/coretmpl.h')
| -rw-r--r-- | src/lib/util/coretmpl.h | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/src/lib/util/coretmpl.h b/src/lib/util/coretmpl.h index 18b64e7c0ff..9d033f72d26 100644 --- a/src/lib/util/coretmpl.h +++ b/src/lib/util/coretmpl.h @@ -610,20 +610,6 @@ template <typename T, typename U, typename V> constexpr T BIT(T x, U n, V w) } -/// \brief Extract and right-align a single bit field -/// -/// This overload is used to terminate a recursive template -/// implementation. It is functionally equivalent to the BIT -/// function for extracting a single bit. -/// -/// \param [in] val The integer to extract the bit from. -/// \param [in] b The bit to extract, where zero is the least -/// significant bit of the input. -/// \return The specified bit of the input extracted to the least -/// significant position. -template <typename T, typename U> constexpr T bitswap(T val, U b) noexcept { return BIT(val, b) << 0U; } - - /// \brief Extract bits in arbitrary order /// /// Extracts bits from an integer. Specify the bits in the order they @@ -641,7 +627,10 @@ template <typename T, typename U> constexpr T bitswap(T val, U b) noexcept { ret /// \return The extracted bits packed into a right-aligned field. template <typename T, typename U, typename... V> constexpr T bitswap(T val, U b, V... c) noexcept { - return (BIT(val, b) << sizeof...(c)) | bitswap(val, c...); + if constexpr (sizeof...(c) > 0U) + return (BIT(val, b) << sizeof...(c)) | bitswap(val, c...); + else + return BIT(val, b); } |
