Skip to content

Avoid instantiating named_tuple_t<T> in HasDefaultVal via apply_to_fields - #126

Open
clockblocker wants to merge 1 commit into
mainfrom
perf-apply-to-fields-has-default-val
Open

clockblocker wants to merge 1 commit into
mainfrom
perf-apply-to-fields-has-default-val

Conversation

@clockblocker

@clockblocker clockblocker commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

AI-authored below this line.

Related munich-data-engineering/reflect-cpp#799 · Related munich-data-engineering/reflect-cpp#641

Problem

Checking whether an aggregate struct contains an rfl::DefaultVal field instantiated named_tuple_t<T>, computed every field name string, and built a full NamedTuple type.

The trait only inspects field types and never uses field names, so all of that template work is wasted on every reflected aggregate.

Before (per reflected aggregate T):
  HasDefaultVal<T> -> named_tuple_t<T> -> field_names_t<T> + NamedTuple<Field<...>...>

After (direct structured-binding type walk):
  HasDefaultVal<T> -> apply_to_fields(T&, HasDefaultValVisitor{}) -> folds over field types only

Summary

  • Adds an internal apply_to_fields helper (C++20 and C++26) that passes structured-binding references directly to a visitor without materializing a tuple or NamedTuple.
  • Drops #include "../NamedTuple.hpp" from has_default_val_v.hpp via forward declaration and fixes a raw-pointer false positive.
For Agents

…tVal

Adds `rfl::internal::apply_to_fields` (C++20 and C++26) to invoke a visitor
directly on structured-binding field references without materializing
`rfl::Tuple` or `rfl::NamedTuple`, and rewrites `HasDefaultVal<T>` on top of it
(dropping `#include "../NamedTuple.hpp"` in favor of a forward declaration and
fixing a raw-pointer false positive).

Judge polish applied:
- Qualifies `rfl::internal::apply_to_fields(...)` and `cpp20::apply_to_fields_impl<...>`
  to prevent ADL ambiguity when user namespaces define `apply_to_fields`.
- Guards `HasDefaultVal<T>`'s `requires` clause with `!is_named_tuple_spec<T>::value`
  before `std::is_aggregate_v<T>` so forward-declared `NamedTuple<...>` stays
  well-formed without including `NamedTuple.hpp`.
- Uses `is_default_val` in `HasDefaultVal<NamedTuple<Fields...>>` so it strips
  one pointer level as documented (instead of two), and renames function
  template `has_default_val_type_v` to `has_default_val_field`.

Downstream validation:
- Verified 0 warnings and 96/96 PASS on munich-data-engineering/sqlgen
  (metaprogramming canary) plus slang-server, moqx, fanuc-libs, and wolf.
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