Core/Flags: Make aware of enumeration max value

Preventing it to enable bits that have no corresponding enum value
This commit is contained in:
Lynix
2016-12-12 15:10:37 +01:00
parent e9061a6cf8
commit 876fec6f5e
3 changed files with 11 additions and 4 deletions

View File

@@ -17,6 +17,7 @@ namespace Nz
struct EnumAsFlags
{
static constexpr bool value = false;
static constexpr int max = 0;
};
template<typename E>
@@ -47,7 +48,10 @@ namespace Nz
private:
UInt32 m_value;
static constexpr UInt32 ValueMask = ((UInt32(1) << (EnumAsFlags<E>::max + 1)) - 1);
private:
BitField m_value;
};
template<typename E> constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator~(E lhs);