mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-01-09 23:34:23 +00:00
add compile time get value
This commit is contained in:
parent
38f86e4d09
commit
0325167113
1 changed files with 20 additions and 0 deletions
|
|
@ -692,6 +692,16 @@ template <typename E>
|
|||
}
|
||||
}
|
||||
|
||||
// Returns enum value at specified index.
|
||||
template <typename E, std::size_t I>
|
||||
[[nodiscard]] constexpr auto enum_value() noexcept -> detail::enable_if_enum_t<E, std::decay_t<E>> {
|
||||
using D = std::decay_t<E>;
|
||||
static_assert(detail::count_v<D> > 0, "magic_enum requires enum implementation and valid max and min.");
|
||||
static_assert(I < detail::count_v<D>, "magic_enum::enum_value out of range.");
|
||||
|
||||
return detail::values_v<D>[I];
|
||||
}
|
||||
|
||||
// Returns std::array with enum values, sorted by enum value.
|
||||
template <typename E>
|
||||
[[nodiscard]] constexpr auto enum_values() noexcept -> detail::enable_if_enum_t<E, detail::values_t<E>> {
|
||||
|
|
@ -925,6 +935,16 @@ template <typename E>
|
|||
}
|
||||
}
|
||||
|
||||
// Returns enum-flags value at specified index.
|
||||
template <typename E, std::size_t I>
|
||||
[[nodiscard]] constexpr auto enum_value() noexcept -> detail::enable_if_enum_t<E, std::decay_t<E>> {
|
||||
using D = std::decay_t<E>;
|
||||
static_assert(detail::count_v<D> > 0, "magic_enum::flags requires enum implementation and valid max and min.");
|
||||
static_assert(I < detail::count_v<D>, "magic_enum::flags::enum_value out of range.");
|
||||
|
||||
return detail::values_v<D, true>[I];
|
||||
}
|
||||
|
||||
// Returns std::array with enum-flags values, sorted by enum-flags value.
|
||||
template <typename E>
|
||||
[[nodiscard]] constexpr auto enum_values() noexcept -> detail::enable_if_enum_t<E, detail::values_t<E, true>> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue