Created
February 1, 2015 20:08
-
-
Save Subv/20ef8e1da31f3417e3a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/common/bit_field.h b/src/common/bit_field.h | |
index 8eab054..ac8fb9c 100644 | |
--- a/src/common/bit_field.h | |
+++ b/src/common/bit_field.h | |
@@ -110,9 +110,11 @@ | |
* symptoms. | |
*/ | |
#pragma pack(1) | |
-template<std::size_t position, std::size_t bits, typename T> | |
+template<std::size_t position, std::size_t bits, typename T, typename Rep> | |
struct BitField | |
{ | |
+ static_assert(sizeof(Rep) * CHAR_BITS > bits, "Can't hold the bits"); | |
+ | |
private: | |
// This constructor might be considered ambiguous: | |
// Would it initialize the storage or just the bitfield? | |
@@ -151,6 +153,11 @@ public: | |
return Value(); | |
} | |
+ __forceinline operator Rep() const | |
+ { | |
+ return static_cast<Rep>(Value()); | |
+ } | |
+ | |
__forceinline void Assign(const T& value) { | |
storage = (storage & ~GetMask()) | (((StorageType)value << position) & GetMask()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment