https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122828
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2025-11-25
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The example is:
#include <print>
#include <meta>
template<typename E, bool Enumerable = std::meta::is_enumerable_type(^^E)>
requires std::is_enum_v<E>
constexpr std::string_view enum_to_string(E value) {
if constexpr (Enumerable)
template for (constexpr auto e :
std::define_static_array(std::meta::enumerators_of(^^E)))
if (value == [:e:])
return std::meta::identifier_of(e);
return "<unnamed>";
}
int main() {
enum Color : int;
static_assert(enum_to_string(Color(0)) == "<unnamed>");
std::println("Color 0: {}", enum_to_string(Color(0))); // prints '<unnamed>'
enum Color : int { red, green, blue };
static_assert(enum_to_string(Color::red) == "red");
static_assert(enum_to_string(Color(42)) == "<unnamed>");
std::println("Color 0: {}", enum_to_string(Color(0))); // prints 'red'
}