Skip to content

feat(enums): add rfl::EnumNames<E> per-enum wire-name trait - #253

Open
clockblocker wants to merge 1 commit into
queue/feat-transform-enum-namesfrom
queue/feat-enum-names-trait
Open

clockblocker wants to merge 1 commit into
queue/feat-transform-enum-namesfrom
queue/feat-enum-names-trait

Conversation

@clockblocker

@clockblocker clockblocker commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

AI-authored below this line.

Addresses munich-data-engineering/reflect-cpp#106

Stacked on: #235 (queue/feat-transform-enum-names)

Problem

Whole-enum casing processors cannot express non-identifier wire strings like "c++20", "nvq++", or "*", nor handle C++ keyword clashes or out-of-range enumerators.

Consumers end up maintaining boilerplate rfl::Reflector switch tables just to customize a few enumerator names.

enum class OptLevel { no_opt, cxx_standard };

template <>
struct rfl::EnumNames<OptLevel> {
  static constexpr auto transform = rfl::EnumNameTransform::snake_to_kebab;
  static constexpr std::array<rfl::EnumOverride<OptLevel>, 1> overrides = {{
      {OptLevel::cxx_standard, "c++20"},
  }};
};
// no_opt -> "no-opt", cxx_standard -> "c++20" across JSON, YAML, XML, CLI, and JSON Schema
auto names = rfl::get_enum_wire_names<OptLevel>();

Summary

  • Adds rfl::EnumNames<E> with static overrides (array or span) and per-enum transforms (built-in or callable), with overrides taking precedence over call-site processors.
  • Exposes rfl::get_enum_wire_names<E>(), incurs zero overhead when unused, and returns rfl::Error if a custom transform throws.
  • Open design question: Should the trait live at rfl::EnumNames<E> (like rfl::Reflector<T>) or rfl::config::enum_names<E> (like rfl::config::enum_range<E>)?

OSS consumers

Consumer Location Pain point solved
NVIDIA/cuda-quantum QuakeReferenceSemanticsProfileYaml.h#L16-L32 Hand-writes rfl::Reflector tables for non-identifier wire names like "c++20" and "nvq++".
openmoq/moqx Action.h#L24-L102 Maintains manual enum-to-string switch tables for custom domain verbs and "*".
For Agents

Parent: `feat(enums): add rfl::TransformEnumNames processors (munich-data-engineering#731)`

Adds the opt-in `rfl::EnumNames<E>` specialization trait and
`rfl::get_enum_wire_names<E, Ps...>()` utility so enums with non-identifier
wire strings (e.g., `"c++20"`, `"nvq++"`, `"*"`), C++ keyword clashes, or
enumerators outside the default reflected range can declare custom wire names
across JSON, CLI, YAML, XML, Generic, and JSON Schema without duplicating
enumerators as `rfl::Literal<...>`:

- Supports static `overrides` (array or borrowed `overrides()` returning
  `std::span`, with `static_assert` rejecting dangling by-value containers)
  and per-enum `transform` (`EnumNameTransform` constant or custom callable).
- `overrides` takes precedence over `transform`; when only `overrides` is
  specified, non-overridden enumerators still inherit any
  `rfl::TransformEnumNames<...>` processor passed to `read`/`write`/`to_schema`.
- Zero-overhead `if constexpr` fast path when neither `EnumNames<E>` nor
  `TransformEnumNames` is active; resolved tables are cached per
  `(EnumType, EnumNameTransform)`.
- Public `rfl::get_enum_wire_names<E, Ps...>()` accepts variadic processors,
  and throwing custom `transform` callbacks are caught into `rfl::Error` across
  both `ParserEnum::read` and direct `rfl::string_to_enum`.

Open design question for upstream review: whether the trait should live at
`rfl::EnumNames<E>` (matching `rfl::Reflector<T>`) or `rfl::config::enum_names<E>`
(matching `rfl::config::enum_range<E>` / `rfl::config::enum_descriptions<E>`).

Refs: munich-data-engineering#106
(Maintainer: "something along these lines is possible")
Downstream receipts:
- NVIDIA/cuda-quantum hand-written Reflector tables for non-identifier wire
  strings (e.g., `c++20`, `nvq++`):
  https://github.com/NVIDIA/cuda-quantum/blob/81ef20d9d4a1e0912a6dbc68637ece017e8fd324/cudaq/lib/Target/Yaml/TargetConfigYamlAdapters.h#L27-L75
  https://github.com/NVIDIA/cuda-quantum/blob/81ef20d9d4a1e0912a6dbc68637ece017e8fd324/cudaq/lib/Target/Yaml/v2/QuakeReferenceSemanticsProfileYaml.h#L16-L32
- openmoq/moqx custom action wire strings (`"*"` / domain verbs) & config enums:
  https://github.com/openmoq/moqx/blob/60bab7f13925acbaf578670223e660d71e891547/src/auth/Action.h#L24-L102
  https://github.com/openmoq/moqx/blob/60bab7f13925acbaf578670223e660d71e891547/src/config/ConfigResolver.cpp#L35-L48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant