mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
57 lines
1.1 KiB
C++
57 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include <type_traits>
|
|
|
|
namespace chatterino {
|
|
namespace util {
|
|
|
|
// = std::enable_if<std::is_enum<T>::value>::type
|
|
|
|
template <typename T, typename Q = typename std::underlying_type<T>::type>
|
|
class FlagsEnum
|
|
{
|
|
public:
|
|
FlagsEnum()
|
|
: value((T)0)
|
|
{
|
|
}
|
|
|
|
FlagsEnum(T _value)
|
|
: value(_value)
|
|
{
|
|
}
|
|
|
|
inline T operator~() const
|
|
{
|
|
return (T) ~(Q)this->value;
|
|
}
|
|
inline T operator|(Q a) const
|
|
{
|
|
return (T)((Q)a | (Q)this->value);
|
|
}
|
|
inline T operator&(Q a) const
|
|
{
|
|
return (T)((Q)a & (Q)this->value);
|
|
}
|
|
inline T operator^(Q a) const
|
|
{
|
|
return (T)((Q)a ^ (Q)this->value);
|
|
}
|
|
inline T &operator|=(const Q &a)
|
|
{
|
|
return (T &)((Q &)this->value |= (Q)a);
|
|
}
|
|
inline T &operator&=(const Q &a)
|
|
{
|
|
return (T &)((Q &)this->value &= (Q)a);
|
|
}
|
|
inline T &operator^=(const Q &a)
|
|
{
|
|
return (T &)((Q &)this->value ^= (Q)a);
|
|
}
|
|
|
|
T value;
|
|
};
|
|
} // namespace util
|
|
} // namespace chatterino
|