mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-01-09 23:34:23 +00:00
change std::size_t to std::uintmax_t (#141)
This commit is contained in:
parent
9268bb3042
commit
29285919fd
1 changed files with 5 additions and 5 deletions
|
|
@ -914,7 +914,7 @@ template <typename E, typename BinaryPredicate = std::equal_to<char>>
|
|||
namespace fusion_detail {
|
||||
|
||||
template <typename E>
|
||||
constexpr std::optional<std::size_t> fuse_one_enum(std::optional<std::size_t> hash, E value) noexcept {
|
||||
constexpr std::optional<std::uintmax_t> fuse_one_enum(std::optional<std::uintmax_t> hash, E value) noexcept {
|
||||
if (hash.has_value()) {
|
||||
if (const auto index = enum_index(value); index.has_value()) {
|
||||
// Add 1 to prevent matching 2D fusions with 3D fusions etc.
|
||||
|
|
@ -925,12 +925,12 @@ constexpr std::optional<std::size_t> fuse_one_enum(std::optional<std::size_t> ha
|
|||
}
|
||||
|
||||
template <typename E>
|
||||
constexpr std::optional<std::size_t> fuse_enum(E value) noexcept {
|
||||
constexpr std::optional<std::uintmax_t> fuse_enum(E value) noexcept {
|
||||
return fuse_one_enum(0, value);
|
||||
}
|
||||
|
||||
template <typename E, typename... Es>
|
||||
constexpr std::optional<std::size_t> fuse_enum(E head, Es... tail) noexcept {
|
||||
constexpr std::optional<std::uintmax_t> fuse_enum(E head, Es... tail) noexcept {
|
||||
return fuse_one_enum(fuse_enum(tail...), head);
|
||||
}
|
||||
|
||||
|
|
@ -938,9 +938,9 @@ constexpr std::optional<std::size_t> fuse_enum(E head, Es... tail) noexcept {
|
|||
|
||||
// Returns a bijective mix of several enum values. This can be used to emulate 2D switch/case statements.
|
||||
template <typename... Es>
|
||||
[[nodiscard]] constexpr auto enum_fuse(Es... values) -> std::enable_if_t<(std::is_enum_v<std::decay_t<Es>> && ...), std::optional<std::size_t>> {
|
||||
[[nodiscard]] constexpr auto enum_fuse(Es... values) -> std::enable_if_t<(std::is_enum_v<std::decay_t<Es>> && ...), std::optional<std::uintmax_t>> {
|
||||
static_assert(sizeof...(Es) >= 2, "magic_enum::enum_fuse requires at least 2 enums");
|
||||
static_assert((detail::log2(enum_count<Es>() + 1) + ...) <= (sizeof(std::size_t) * 8), "magic_enum::enum_fuse does not work for large enums");
|
||||
static_assert((detail::log2(enum_count<Es>() + 1) + ...) <= (sizeof(std::uintmax_t) * 8), "magic_enum::enum_fuse does not work for large enums");
|
||||
const auto fuse = fusion_detail::fuse_enum(values...);
|
||||
return assert(fuse.has_value()), fuse;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue