feat(guard): anchor PTN_BIND names to members - #47
Merged
Conversation
Problem - PTN_BIND names were positional (arg_t<N>), so their meaning depended on the order of member pointers in has<...>; the Type argument was documentary only and misspelled or mismatched names failed with indirect errors. Implementation - PTN_BIND now expands each name to member_t<&Type::name>, making Type meaningful: misspellings fail at the declaration line. - Guards attached to has<...> rewrite member placeholders to the position of their member in the pattern's member list at compile time (resolve_pred over the expression tree), so names follow members regardless of has<...> order. Evaluation machinery is unchanged. - _ign slots occupy no binding position; `_` keeps its positional meaning and mixes freely with member names. - Clear static_asserts when a name is missing from has<...> or is used on a non-structural pattern. Tests - tests_named_placeholder rewritten for member semantics: type checks assert member_t<&T::m>; new cases cover order independence, _ign skipping, mixed `_` + names, and the non-binding has<>[guard] path. - tests_destructure updated from alias names to member names. - New compile_fail cases: name not in has<...>, member placeholder on a non-structural pattern, misspelled PTN_BIND member. - Full suite: 191/191 (GCC 13 + Clang 20, C++17). Notes - Breaking for alias-style PTN_BIND usage (names that were not real members); such declarations now fail at the macro line. - Block-scope PTN_BIND cannot be used inside PTN_ON (captureless caching lambda); documented in docs/api.md. - docs/api.md + roadmap updated; the deferred Type-validation roadmap item is resolved without reflection.
sentomk
force-pushed
the
feat/member-anchored-placeholders
branch
from
August 1, 2026 07:58
64d58b1 to
9210fd4
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Upgrade
PTN_BINDplaceholders from positional (arg_t<N>) to member-anchored (member_t<&Type::name>). Guards attached tohas<...>rewrite each name to the position of its member in the pattern's member list at compile time, so names follow members — the order of member pointers inhas<...>no longer matters. This also activates the previously documentaryTypeargument and resolves the deferred Type-validation roadmap item without static reflection.Changes
PTN_BIND(Type, ...)now expands each name toconstexpr member_t<&Type::name>; misspelled member names fail right at the macro line.guard.hpp:member_position(skips_ignslots) +resolve_expr/resolve_predexpression-tree rewriting; evaluation machinery untouched.has_pattern::operator[](non-binding path) and a newguard_resolverhook inbinding_base.hpp, specialized forstructural_bind_pattern(binding path)._keeps its positional meaning and mixes freely with member names.has<...>or used on a non-structural pattern.docs/api.mdPTN_BINDsection rewritten (member semantics +PTN_ONcapture caveat); roadmap WIP entry added and the deferred validation item marked resolved.Testing
tests_named_placeholder.cpprewritten for member semantics: type checks assertmember_t<&T::m>; new cases cover order independence (has<&P::y, &P::x>),_ignslot skipping, mixed_+ member names, and the non-bindinghas<>[guard]path. Block-scope binds useptn::onbecausePTN_ON's captureless caching lambda cannot capture block-scope names.tests_destructure.cppmigrated from alias names to member names.member_placeholder_not_in_pattern,member_placeholder_non_structural,ptn_bind_unknown_member.Notes
PTN_BINDusage (placeholder names that were not real members): such declarations now fail at the macro line. Member-named usage is source-compatible with identical semantics when written in matching order.