summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2017-03-23 10:53:13 -0400
committerLioncash <mathew1800@gmail.com>2017-03-23 11:45:45 -0400
commitcaef08988e5149ba397a6c956eaaec82f0acbc3f (patch)
tree9963a33838dae059e9be8bc3b4dd1b022c14475e /Source
parent4b5995a6e0617ff813296b24653565c5cf1ea3be (diff)
BitField: Make mostly constexpr capable
Makes the constructor and retrieval functions constexpr.
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/Common/BitField.h31
1 files changed, 15 insertions, 16 deletions
diff --git a/Source/Core/Common/BitField.h b/Source/Core/Common/BitField.h
index 10312f1c38..35d294d220 100644
--- a/Source/Core/Common/BitField.h
+++ b/Source/Core/Common/BitField.h
@@ -121,7 +121,7 @@ private:
public:
// Force default constructor to be created
// so that we can use this within unions
- BitField() = default;
+ constexpr BitField() = default;
// We explicitly delete the copy assignment operator here, because the
// default copy assignment would copy the full storage value, rather than
@@ -139,20 +139,8 @@ public:
return *this;
}
- __forceinline T Value() const
- {
- if (std::numeric_limits<T>::is_signed)
- {
- std::size_t shift = 8 * sizeof(T) - bits;
- return (T)((storage << (shift - position)) >> shift);
- }
- else
- {
- return (T)((storage & GetMask()) >> position);
- }
- }
-
- __forceinline operator T() const { return Value(); }
+ constexpr T Value() const { return Value(std::is_signed<T>()); }
+ constexpr operator T() const { return Value(); }
private:
// StorageType is T for non-enum types and the underlying type of T if
// T is an enumeration. Note that T is wrapped within an enable_if in the
@@ -161,10 +149,21 @@ private:
typedef typename std::conditional<std::is_enum<T>::value, std::underlying_type<T>,
std::enable_if<true, T>>::type::type StorageType;
+ constexpr T Value(std::true_type) const
+ {
+ using shift_amount = std::integral_constant<size_t, 8 * sizeof(T) - bits>;
+ return static_cast<T>((storage << (shift_amount() - position)) >> shift_amount());
+ }
+
+ constexpr T Value(std::false_type) const
+ {
+ return static_cast<T>((storage & GetMask()) >> position);
+ }
+
// Unsigned version of StorageType
typedef typename std::make_unsigned<StorageType>::type StorageTypeU;
- __forceinline StorageType GetMask() const
+ static constexpr StorageType GetMask()
{
return (((StorageTypeU)~0) >> (8 * sizeof(T) - bits)) << position;
}