Skip to content

feat(reflection): add public rfl::type_name<T>() and rfl::type_name_v<T> - #236

Open
clockblocker wants to merge 1 commit into
mainfrom
queue/feat-public-type-name
Open

clockblocker wants to merge 1 commit into
mainfrom
queue/feat-public-type-name

Conversation

@clockblocker

@clockblocker clockblocker commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

AI-authored below this line.

Addresses munich-data-engineering/reflect-cpp#451 · Related munich-data-engineering/reflect-cpp#465

Problem

reflect-cpp only exposed rfl::type_name_t<T>(), which instantiates rfl::Literal and allocates a std::string via .str().

Callers needing a zero-allocation constexpr std::string_view type name either reach into rfl::internal:: or reimplement compiler-specific parsing.

#include <rfl/type_name.hpp>

struct SampleStruct { int a; double b; };

constexpr std::string_view v = rfl::type_name_v<SampleStruct>;
constexpr std::string_view f = rfl::type_name<SampleStruct>();
static_assert(f == v && f.find("SampleStruct") != std::string_view::npos);

Summary

  • Adds <rfl/type_name.hpp> with rfl::type_name<T>() and rfl::type_name_v<T> returning a zero-allocation constexpr std::string_view.
  • Avoids rfl::Literal instantiation and builds on upstream PR #804.

OSS consumers

Consumer Location Pain point solved
NVIDIA/cuda-quantum Target/Reflection.h#L27-L31 Calls private rfl::internal::get_type_name_str_view<T>() with a workaround comment.
munich-data-engineering/sqlgen internal/get_type_name.hpp#L13-L44 Maintains its own copy of get_type_name_str_view for a public string_view name.
games-on-whales/wolf api/api.cpp#L26 Calls rfl::type_name_t<T>().str() where a zero-allocation string_view suffices.
For Agents

Exposes `rfl::type_name<T>()` and `rfl::type_name_v<T>` via a thin,
self-contained public header (`<rfl/type_name.hpp>`, mirroring `<rfl/num_fields.hpp>`
from munich-data-engineering#451/munich-data-engineering#465) returning a compile-time `std::string_view` directly from
`rfl::internal::get_type_name_str_view<T>()` without instantiating
`rfl::Literal` or `rfl::internal::StringLiteral`.

Parent: depends on `fix(reflection): fix dangling string_view in rfl::internal::get_type_name_str_view`
(open upstream PR munich-data-engineering#804).

Judge polish applied:
- Drops redundant `rfl::num_fields_v<T>` (`rfl::num_fields<T>` is already a
  public variable template since munich-data-engineering#465).
- Uses munich-data-engineering#804's `internal::get_type_name_str_view<T>()` directly to avoid
  `StringLiteral<N>` / `make_index_sequence<N>` bloat.

Precedent: munich-data-engineering#451
Downstream receipts:
- NVIDIA/cuda-quantum calls private `rfl::internal::get_type_name_str_view<T>()`
  with comment "Unfortunately, this has to use a private API of reflect-cpp":
  https://github.com/NVIDIA/cuda-quantum/blob/81ef20d9d4a1e0912a6dbc68637ece017e8fd324/cudaq/lib/Target/Reflection.h#L27-L31
- munich-data-engineering/sqlgen hand-rolled `sqlgen::internal::get_type_name_str_view`:
  https://github.com/munich-data-engineering/sqlgen/blob/265b0a174b661c5905b874f97b064aecb4cded70/include/sqlgen/internal/get_type_name.hpp#L13-L44
- games-on-whales/wolf instantiates `rfl::type_name_t<...>().str()`:
  https://github.com/games-on-whales/wolf/blob/ac2461f68feda41fdc7a7c8e812b9ab4b80520b7/src/moonlight-server/api/api.cpp#L26
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