• riodoro1@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    4 days 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.