From a27aa45e6a5a0b82430fc3d7df671b8be86d6d61 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 23 Jun 2020 05:27:38 -0400 Subject: [PATCH] bitfield: Make interface fully constexpr Given C++17 is being used, the entire interface is capable of being constexpr. --- src/common/bitfield.h | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/common/bitfield.h b/src/common/bitfield.h index 377b9c3e7..1c803c9a4 100644 --- a/src/common/bitfield.h +++ b/src/common/bitfield.h @@ -21,97 +21,97 @@ struct BitField return ((static_cast(~0)) >> (8 * sizeof(BackingDataType) - BitCount)) << BitIndex; } - ALWAYS_INLINE operator DataType() const { return GetValue(); } + ALWAYS_INLINE constexpr operator DataType() const { return GetValue(); } - ALWAYS_INLINE BitField& operator=(DataType value) + ALWAYS_INLINE constexpr BitField& operator=(DataType value) { SetValue(value); return *this; } - ALWAYS_INLINE DataType operator++() + ALWAYS_INLINE constexpr DataType operator++() { DataType value = GetValue() + 1; SetValue(value); return GetValue(); } - ALWAYS_INLINE DataType operator++(int) + ALWAYS_INLINE constexpr DataType operator++(int) { DataType value = GetValue(); SetValue(value + 1); return value; } - ALWAYS_INLINE DataType operator--() + ALWAYS_INLINE constexpr DataType operator--() { DataType value = GetValue() - 1; SetValue(value); return GetValue(); } - ALWAYS_INLINE DataType operator--(int) + ALWAYS_INLINE constexpr DataType operator--(int) { DataType value = GetValue(); SetValue(value - 1); return value; } - ALWAYS_INLINE BitField& operator+=(DataType rhs) + ALWAYS_INLINE constexpr BitField& operator+=(DataType rhs) { SetValue(GetValue() + rhs); return *this; } - ALWAYS_INLINE BitField& operator-=(DataType rhs) + ALWAYS_INLINE constexpr BitField& operator-=(DataType rhs) { SetValue(GetValue() - rhs); return *this; } - ALWAYS_INLINE BitField& operator*=(DataType rhs) + ALWAYS_INLINE constexpr BitField& operator*=(DataType rhs) { SetValue(GetValue() * rhs); return *this; } - ALWAYS_INLINE BitField& operator/=(DataType rhs) + ALWAYS_INLINE constexpr BitField& operator/=(DataType rhs) { SetValue(GetValue() / rhs); return *this; } - ALWAYS_INLINE BitField& operator&=(DataType rhs) + ALWAYS_INLINE constexpr BitField& operator&=(DataType rhs) { SetValue(GetValue() & rhs); return *this; } - ALWAYS_INLINE BitField& operator|=(DataType rhs) + ALWAYS_INLINE constexpr BitField& operator|=(DataType rhs) { SetValue(GetValue() | rhs); return *this; } - ALWAYS_INLINE BitField& operator^=(DataType rhs) + ALWAYS_INLINE constexpr BitField& operator^=(DataType rhs) { SetValue(GetValue() ^ rhs); return *this; } - ALWAYS_INLINE BitField& operator<<=(DataType rhs) + ALWAYS_INLINE constexpr BitField& operator<<=(DataType rhs) { SetValue(GetValue() << rhs); return *this; } - ALWAYS_INLINE BitField& operator>>=(DataType rhs) + ALWAYS_INLINE constexpr BitField& operator>>=(DataType rhs) { SetValue(GetValue() >> rhs); return *this; } - ALWAYS_INLINE DataType GetValue() const + ALWAYS_INLINE constexpr DataType GetValue() const { if constexpr (std::is_same_v) { @@ -128,7 +128,7 @@ struct BitField } } - ALWAYS_INLINE void SetValue(DataType value) + ALWAYS_INLINE constexpr void SetValue(DataType value) { data = (data & ~GetMask()) | ((static_cast(value) << BitIndex) & GetMask()); }