MCPcopy Create free account
hub / github.com/Neargye/magic_enum / enum_value

Function enum_value

include/magic_enum/magic_enum.hpp:1221–1232  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1219// No bounds checking is performed: the behavior is undefined if index >= number of enum values.
1220template <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.
1235template <typename E, std::size_t I, detail::enum_subtype S = detail::subtype_v<E>>

Callers

nothing calls this directly

Calls 1

log2Function · 0.85

Tested by

no test coverage detected