mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
feat: add FlagsEnum::isEmpty
for checking if a FlagsEnum is empty (#5550)
This commit is contained in:
parent
f3cae76abf
commit
66c3bc2112
|
@ -64,6 +64,7 @@
|
||||||
- Dev: Cleanly exit on shutdown. (#5537)
|
- Dev: Cleanly exit on shutdown. (#5537)
|
||||||
- Dev: Renamed threads created by Chatterino on Linux and Windows. (#5538, #5539, #5544)
|
- Dev: Renamed threads created by Chatterino on Linux and Windows. (#5538, #5539, #5544)
|
||||||
- Dev: Refactored a few `#define`s into `const(expr)` and cleaned includes. (#5527)
|
- Dev: Refactored a few `#define`s into `const(expr)` and cleaned includes. (#5527)
|
||||||
|
- Dev: Added `FlagsEnum::isEmpty`. (#5550)
|
||||||
- Dev: Prepared for Qt 6.8 by addressing some deprecations. (#5529)
|
- Dev: Prepared for Qt 6.8 by addressing some deprecations. (#5529)
|
||||||
|
|
||||||
## 2.5.1
|
## 2.5.1
|
||||||
|
|
|
@ -132,6 +132,12 @@ public:
|
||||||
return this->hasNone(FlagsEnum{flags...});
|
return this->hasNone(FlagsEnum{flags...});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns true if the enum has no flag set (i.e. its underlying value is 0)
|
||||||
|
constexpr bool isEmpty() const noexcept
|
||||||
|
{
|
||||||
|
return static_cast<Int>(this->value_) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
constexpr T value() const noexcept
|
constexpr T value() const noexcept
|
||||||
{
|
{
|
||||||
return this->value_;
|
return this->value_;
|
||||||
|
|
|
@ -326,6 +326,23 @@ TEST(FlagsEnum, hasNone)
|
||||||
testHasNone<BasicUnscoped>();
|
testHasNone<BasicUnscoped>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename E>
|
||||||
|
consteval void testIsEmpty()
|
||||||
|
{
|
||||||
|
using FE = FlagsEnum<E>;
|
||||||
|
|
||||||
|
static_assert(FE{}.isEmpty());
|
||||||
|
static_assert(!FE{E::Foo}.isEmpty());
|
||||||
|
static_assert(FE{E::None}.isEmpty());
|
||||||
|
static_assert(!FE{E::Foo, E::Waldo}.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(FlagsEnum, isEmpty)
|
||||||
|
{
|
||||||
|
testIsEmpty<BasicScoped>();
|
||||||
|
testIsEmpty<BasicUnscoped>();
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr inline auto CONSTRUCTION_VALID = requires() { FlagsEnum<T>{}; };
|
constexpr inline auto CONSTRUCTION_VALID = requires() { FlagsEnum<T>{}; };
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue