lysdexic@programming.devM to C++@programming.devEnglish · 5 months agoP2996R4 - Reflection for C++26isocpp.orgexternal-linkmessage-square3fedilinkarrow-up111arrow-down10
arrow-up111arrow-down1external-linkP2996R4 - Reflection for C++26isocpp.orglysdexic@programming.devM to C++@programming.devEnglish · 5 months agomessage-square3fedilink
minus-squareriodoro1@lemmy.worldlinkfedilinkarrow-up3arrow-down1·edit-25 months ago“Simple” enum to string template <typename E> requires std::is_enum_v<E> constexpr std::string enum_to_string(E value) { template for (constexpr auto e : std::meta::enumerators_of(^E)) { if (value == [:e:]) { return std::string(std::meta::name_of(e)); } } return "<unnamed>"; } They have taken us for absolute fools.
minus-squarelambalicious@lemmy.sdf.orglinkfedilinkEnglisharrow-up1·5 months ago No requires(requires(... No decltype((auto)) No noexcept(noexcept(... To be fair, it’s quite an advancement considering what I was expecting. Just about my only question is why the return is a string and not a `string_view``.
“Simple” enum to string
template <typename E> requires std::is_enum_v<E> constexpr std::string enum_to_string(E value) { template for (constexpr auto e : std::meta::enumerators_of(^E)) { if (value == [:e:]) { return std::string(std::meta::name_of(e)); } } return "<unnamed>"; }
They have taken us for absolute fools.
To be fair, it’s quite an advancement considering what I was expecting.
Just about my only question is why the return is a
string
and not a `string_view``.