#pragma once #include #include template concept is_enum = std::is_enum_v; namespace detail { template constexpr void static_for(F && f, std::index_sequence) { (std::forward(f)(std::integral_constant(I)>()) , ...); } } /** * Iterate over enum values in compile-time (compile-time switch/case, loop unrolling). * * @example static_for([](auto enum_value) { return template_func(); } * ^ enum_value can be used as a template parameter */ template constexpr void static_for(F && f) { constexpr size_t count = magic_enum::enum_count(); detail::static_for(std::forward(f), std::make_index_sequence()); } /// Enable printing enum values as strings via fmt + magic_enum template struct fmt::formatter : fmt::formatter { constexpr auto format(T value, auto& format_context) { return formatter::format(magic_enum::enum_name(value), format_context); } };