diff options
Diffstat (limited to 'src/common/bit_field.h')
| -rw-r--r-- | src/common/bit_field.h | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/common/bit_field.h b/src/common/bit_field.h index 7e1df62b1..e4e58ea45 100644 --- a/src/common/bit_field.h +++ b/src/common/bit_field.h | |||
| @@ -141,10 +141,6 @@ public: | |||
| 141 | constexpr BitField(BitField&&) noexcept = default; | 141 | constexpr BitField(BitField&&) noexcept = default; |
| 142 | constexpr BitField& operator=(BitField&&) noexcept = default; | 142 | constexpr BitField& operator=(BitField&&) noexcept = default; |
| 143 | 143 | ||
| 144 | [[nodiscard]] constexpr operator T() const { | ||
| 145 | return Value(); | ||
| 146 | } | ||
| 147 | |||
| 148 | constexpr void Assign(const T& value) { | 144 | constexpr void Assign(const T& value) { |
| 149 | #ifdef _MSC_VER | 145 | #ifdef _MSC_VER |
| 150 | storage = static_cast<StorageType>((storage & ~mask) | FormatValue(value)); | 146 | storage = static_cast<StorageType>((storage & ~mask) | FormatValue(value)); |
| @@ -162,6 +158,17 @@ public: | |||
| 162 | return ExtractValue(storage); | 158 | return ExtractValue(storage); |
| 163 | } | 159 | } |
| 164 | 160 | ||
| 161 | template <typename ConvertedToType> | ||
| 162 | [[nodiscard]] constexpr ConvertedToType As() const { | ||
| 163 | static_assert(!std::is_same_v<T, ConvertedToType>, | ||
| 164 | "Unnecessary cast. Use Value() instead."); | ||
| 165 | return static_cast<ConvertedToType>(Value()); | ||
| 166 | } | ||
| 167 | |||
| 168 | [[nodiscard]] constexpr operator T() const { | ||
| 169 | return Value(); | ||
| 170 | } | ||
| 171 | |||
| 165 | [[nodiscard]] constexpr explicit operator bool() const { | 172 | [[nodiscard]] constexpr explicit operator bool() const { |
| 166 | return Value() != 0; | 173 | return Value() != 0; |
| 167 | } | 174 | } |