mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-01-15 16:33:15 -03:00
Merge pull request #14232 from iwubcode/const_flags
Common: update Flags to allow const object usage
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
#include "Common/EnumUtils.h"
|
||||||
|
|
||||||
namespace Common
|
namespace Common
|
||||||
{
|
{
|
||||||
@@ -208,23 +209,20 @@ template <typename T>
|
|||||||
class FlagBit
|
class FlagBit
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FlagBit(std::underlying_type_t<T>& bits, T bit) : m_bits(bits), m_bit(bit) {}
|
FlagBit(T* bits, std::type_identity_t<T> bit) : m_bits(*bits), m_bit(bit) {}
|
||||||
explicit operator bool() const
|
explicit operator bool() const { return (m_bits & m_bit) != 0; }
|
||||||
{
|
FlagBit& operator=(const bool rhs) requires(!std::is_const_v<T>)
|
||||||
return (m_bits & static_cast<std::underlying_type_t<T>>(m_bit)) != 0;
|
|
||||||
}
|
|
||||||
FlagBit& operator=(const bool rhs)
|
|
||||||
{
|
{
|
||||||
if (rhs)
|
if (rhs)
|
||||||
m_bits |= static_cast<std::underlying_type_t<T>>(m_bit);
|
m_bits |= m_bit;
|
||||||
else
|
else
|
||||||
m_bits &= ~static_cast<std::underlying_type_t<T>>(m_bit);
|
m_bits &= ~m_bit;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::underlying_type_t<T>& m_bits;
|
T& m_bits;
|
||||||
T m_bit;
|
const T m_bit;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@@ -239,7 +237,8 @@ public:
|
|||||||
m_hex |= static_cast<std::underlying_type_t<T>>(bit);
|
m_hex |= static_cast<std::underlying_type_t<T>>(bit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FlagBit<T> operator[](T bit) { return FlagBit(m_hex, bit); }
|
auto operator[](T bit) { return FlagBit(&m_hex, Common::ToUnderlying(bit)); }
|
||||||
|
auto operator[](T bit) const { return FlagBit(&m_hex, Common::ToUnderlying(bit)); }
|
||||||
|
|
||||||
std::underlying_type_t<T> m_hex = 0;
|
std::underlying_type_t<T> m_hex = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user