r/cpp • u/rsjaffe • Sep 14 '26
Push-based vs Pull-based Customization
https://brevzin.github.io/c++/2026/09/14/push-vs-pull/Emulating Rust attributes with reflection (or at least trying to).
48
Upvotes
5
u/grishavanika Sep 14 '26
Cool stuff. Question: if we are adding consteval blocks and code injection, can we special case templates as in "this code injection should work as if written by user, no weird workarounds"? Or that's the whole problem to be solved?
3
u/chengfeng-xie Sep 15 '26
An even more ideal design, IMO, would be to avoid needing the
tuple_elementsarray, since all of the information required to define these helper templates is already contained in the user class template. Perhaps a function could be introduced to retrieve the names of the non-static data members of the templatetmpl, which could then be used as tokens insidequeue_injection.5
u/zerhud Sep 15 '26
Why it better over simple `struct foo : N::debug {};` ?
2
u/TheoreticalDumbass :illuminati: Sep 15 '26 edited Sep 15 '26
Suppose we had annotation hook
on_class_completion_request()Example:
Let us also assume hooks
on_class_declaration()andon_class_template_declaration()Then we might be able to do:
Problem with classes is they can be templated and not templated, this definition deferring via
on_class_completion_request()is needed for templated classes (IIUC).1
u/Stevo15025 Sep 15 '26
I hope this is a dumb question. Is the `\(` in this code a formatting typo of the blog, or does the code actually need `\(`? If the code needs `\(` idk why but I find that revolting and skin crawling