mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-01-10 23:44:29 +00:00
improve enum_value for dense enums
This commit is contained in:
parent
77918a74c5
commit
92dfab4ac4
1 changed files with 6 additions and 1 deletions
|
|
@ -33,6 +33,7 @@
|
|||
#define NEARGYE_MAGIC_ENUM_HPP
|
||||
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <iosfwd>
|
||||
#include <limits>
|
||||
|
|
@ -397,7 +398,11 @@ struct enum_traits<E, std::enable_if_t<detail::is_enum_v<E>>> {
|
|||
}
|
||||
|
||||
[[nodiscard]] static constexpr E value(std::size_t index) noexcept {
|
||||
return values[index];
|
||||
if constexpr (detail::size_v<E> != detail::count_v<E>) {
|
||||
return assert(index < count), values[index];
|
||||
} else {
|
||||
return assert(index < count), static_cast<E>(detail::min_v<E> + index);
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] static constexpr std::string_view name(E value) noexcept {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue