diff --git a/src/common/bit_field.h b/src/common/bit_field.h index 574e211a8..99859d0b1 100644 --- a/src/common/bit_field.h +++ b/src/common/bit_field.h @@ -125,7 +125,7 @@ private: using StorageTypeWithEndian = typename AddEndian::type; public: - BitField& operator=(const BitField&) = default; + constexpr BitField& operator=(const BitField&) = default; /// Constants to allow limited introspection of fields if needed static constexpr std::size_t position = Position; @@ -166,15 +166,15 @@ public: // so that we can use this within unions constexpr BitField() = default; - FORCE_INLINE operator T() const { + constexpr operator T() const { return Value(); } - FORCE_INLINE void Assign(const T& value) { + constexpr void Assign(const T& value) { storage = (static_cast(storage) & ~mask) | FormatValue(value); } - FORCE_INLINE T Value() const { + constexpr T Value() const { return ExtractValue(storage); } @@ -191,12 +191,9 @@ private: static_assert(position < 8 * sizeof(T), "Invalid position"); static_assert(bits <= 8 * sizeof(T), "Invalid number of bits"); static_assert(bits > 0, "Invalid number of bits"); - static_assert(std::is_pod::value, "Invalid base type"); + static_assert(std::is_trivially_copyable_v, "T must be trivially copyable in a BitField"); }; #pragma pack() -static_assert(std::is_trivially_copyable>::value, - "BitField must be trivially copyable"); - template using BitFieldBE = BitField;