• 6 Posts
  • 432 Comments
Joined 1 year ago
cake
Cake day: June 13th, 2023

help-circle
  • riodoro1@lemmy.worldtoC++@programming.devP2996R4 - Reflection for C++26
    link
    fedilink
    arrow-up
    3
    arrow-down
    1
    ·
    edit-2
    21 hours 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.