| 1219 | // No bounds checking is performed: the behavior is undefined if index >= number of enum values. |
| 1220 | template <typename E, detail::enum_subtype S = detail::subtype_v<E>> |
| 1221 | [[nodiscard]] constexpr auto enum_value(std::size_t index) noexcept -> detail::enable_if_t<E, std::decay_t<E>> { |
| 1222 | using D = std::decay_t<E>; |
| 1223 | static_assert(detail::is_reflected_v<D, S>, "magic_enum requires enum implementation and valid max and min."); |
| 1224 | |
| 1225 | if constexpr (detail::is_sparse_v<D, S>) { |
| 1226 | return MAGIC_ENUM_ASSERT(index < detail::count_v<D, S>), detail::values_v<D, S>[index]; |
| 1227 | } else { |
| 1228 | constexpr auto min = (S == detail::enum_subtype::flags) ? detail::log2(detail::min_v<D, S>) : detail::min_v<D, S>; |
| 1229 | |
| 1230 | return MAGIC_ENUM_ASSERT(index < detail::count_v<D, S>), detail::value<D, min, S>(index); |
| 1231 | } |
| 1232 | } |
| 1233 | |
| 1234 | // Returns enum value at specified index. |
| 1235 | template <typename E, std::size_t I, detail::enum_subtype S = detail::subtype_v<E>> |