Skip to content

Add public rfl::type_name<T>() / type_name_v<T> and rfl::num_fields_v<T> - #127

Closed
clockblocker wants to merge 1 commit into
mainfrom
feat-type-name-and-num-fields
Closed

clockblocker wants to merge 1 commit into
mainfrom
feat-type-name-and-num-fields

Conversation

@clockblocker

@clockblocker clockblocker commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

Exposes public compile-time <rfl/type_name.hpp> (rfl::type_name<T>() / rfl::type_name_v<T>) and rfl::num_fields_v<T> in <rfl/num_fields.hpp>, and fixes a dangling-temporary bug in rfl::internal::get_type_name_str_view<T>(). Purely additive on the public API.

Example

#include <rfl/type_name.hpp>
#include <rfl/num_fields.hpp>

struct Point { int x; int y; };

static_assert(rfl::type_name_v<int> == "int");
static_assert(rfl::num_fields_v<Point> == 2);

Key details

  • rfl::type_name<T>() and rfl::type_name_v<T> return a null-terminated std::string_view backed by static inline constexpr storage (works in constexpr, static_assert, and runtime under C++20 and C++26 without instantiating rfl::Literal or leaking __PRETTY_FUNCTION__ into .rodata).
  • Fixes rfl::internal::get_type_name_str_view<T>() returning a std::string_view into a temporary StringLiteral prvalue.
  • Removes the need for downstream users (such as NVIDIA/cuda-quantum) to call private rfl::internal::get_type_name_str_view or instantiate rfl::named_tuple_t<T>::size() just to read a field count.

AI-authored.

@clockblocker

Copy link
Copy Markdown
Owner Author

Superseded by:

Closing this bundled PR.

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