Core/Flags: Allow explicit operator conversion to any integer type of the same size (or greater size) than the internal size
This commit is contained in:
@@ -39,17 +39,17 @@ namespace Nz
|
||||
|
||||
static constexpr std::size_t MaxValue = static_cast<std::size_t>(EnumAsFlags<E>::max);
|
||||
|
||||
using BitField16 = typename std::conditional<(MaxValue > 8), UInt16, UInt8>::type;
|
||||
using BitField32 = typename std::conditional<(MaxValue > 16), UInt32, BitField16>::type;
|
||||
using BitField16 = std::conditional_t<(MaxValue > 8), UInt16, UInt8>;
|
||||
using BitField32 = std::conditional_t<(MaxValue > 16), UInt32, BitField16>;
|
||||
|
||||
public:
|
||||
using BitField = typename std::conditional<(MaxValue > 32), UInt64, BitField32>::type;
|
||||
using BitField = std::conditional_t<(MaxValue > 32), UInt64, BitField32>;
|
||||
|
||||
constexpr Flags(BitField value = 0);
|
||||
constexpr Flags(E enumVal);
|
||||
|
||||
explicit constexpr operator bool() const;
|
||||
explicit constexpr operator BitField() const;
|
||||
template<typename T, typename = std::enable_if_t<std::is_integral<T>::value && sizeof(T) >= sizeof(BitField)>> explicit constexpr operator T() const;
|
||||
|
||||
constexpr Flags operator~() const;
|
||||
constexpr Flags operator&(const Flags& rhs) const;
|
||||
|
||||
@@ -52,13 +52,14 @@ namespace Nz
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts to a bitfield
|
||||
* \return Enabled flags as a bitfield.
|
||||
* \brief Converts to an integer
|
||||
* \return Enabled flags as a integer
|
||||
*
|
||||
* This will convert to a bitfield value.
|
||||
* This will only works if the integer type is large enough to store all flags states
|
||||
*/
|
||||
template<typename E>
|
||||
constexpr Flags<E>::operator BitField() const
|
||||
template<typename T, typename>
|
||||
constexpr Flags<E>::operator T() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user