Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

API/Enums: no zero-allocation std::string_view / std::optional<E> enum lookup helpers #150

Backlog

Description

@clockblocker

Part of #138
Popularity: 1/7 corpus consumers (cuda-quantum)

Problem

In upstream reflect-cpp (v0.25.0):

  • rfl::enum_to_string(E) allocates and returns a std::string instead of returning a non-allocating std::string_view.
  • rfl::string_to_enum<E>(const std::string&) requires an owning std::string argument and returns rfl::Result<E> (with heap-allocated error strings on miss) rather than accepting std::string_view and offering a lightweight std::optional<E> lookup.

Consumers writing hot-path or FFI/Python binding casters that only need non-allocating name <-> enumerator lookups end up writing their own linear loops over rfl::get_enumerator_array<E>().

Observed Downstream Workaround

NVIDIA/cuda-quantum (90e4aa08)

  • cudaq/lib/Target/Reflection.h#L53-L68: hand-rolls enumName (std::string_view) and enumFromName (std::optional<E>) by iterating rfl::get_enumerator_array<E>():
    /// The name of the enumerator `value`.
    template <typename E>
    std::string_view enumName(E value) {
      for (auto [name, enumerator] : rfl::get_enumerator_array<E>())
        if (enumerator == value)
          return name;
      return {};
    }
    
    /// The enumerator of `E` called `name`.
    template <typename E>
    std::optional<E> enumFromName(std::string_view name) {
      for (auto [enumeratorName, enumerator] : rfl::get_enumerator_array<E>())
        if (enumeratorName == name)
          return enumerator;
      return std::nullopt;
    }

Related Fork Work

  • Fork PR Accept std::string_view in rfl::string_to_enum #76 (Accept std::string_view in rfl::string_to_enum, live upstream as #802, tracked in Map (Lane 1): Core Hygiene & Perf #85) — removes the std::string allocation on the input parameter of rfl::string_to_enum.
  • Still open for ergonomics: a non-allocating std::string_view enum-to-name helper (enum_to_string_view / constexpr lookup) and/or std::optional<E> lookup without rfl::Error string construction.

Upstream Overlap

Activity

  1. added
    enhancement
    needs-triage
    known-downstream-workarounds
    on Nov 29, 2026
  2. clockblocker commented on Nov 29, 2026

    @clockblocker
    OwnerAuthor

    Tracking & PR Cross-Reference

    Status: Mostly addressed in upstream-queue (Draft PR #191).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementknown-downstream-workaroundsneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions