Some small changes. (#20)

This commit is contained in:
ykiko
2024-12-27 11:20:11 +08:00
committed by GitHub
parent 440303b81f
commit 97d29bb96b
14 changed files with 610 additions and 150 deletions

View File

@@ -4,6 +4,7 @@
#include <array>
#include <string>
#include <cstdint>
#include <algorithm>
#include <string_view>
#include <source_location>
@@ -240,6 +241,31 @@ private:
underlying m_Value;
};
template <typename Derived, typename underlying>
requires (!integral<underlying>)
class Enum<Derived, false, underlying> {
public:
constexpr Enum(underlying value) : m_Value(value) {
static_assert(
requires { Derived::All; },
"Derived enum must define all possible enum values.");
assert(std::ranges::any_of(Derived::All, [&](auto v) { return v == value; }) &&
"Invalid enum value.");
}
constexpr Enum(const Enum&) = default;
constexpr friend bool operator== (Enum lhs, Enum rhs) = default;
constexpr underlying value() const {
return m_Value;
}
private:
underlying m_Value;
};
template <typename T>
concept special_enum = requires {
T::is_special_enum_v;