-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to reflect template parameter pack? #276
Comments
It's not yet supported, but for now, my preferred workaround looks like this:
|
Thanks! Quite elegant! |
Do you also have a workaround for reflecting a function parameter pack? template <typename T>
consteval meta::info refl(T&& t) {
return reflexpr(t);
}
template <typename... Types>
auto foo(Types... ts){
consteval {
auto pack1 = reflexpr(ts); // error: reference to local variable 'ts' declared in enclosing function
meta::info pack2[sizeof...(ts)]{reflexpr(ts)...}; // error: pack expansion does not contain any unexpanded parameter packs
meta::info pack3[sizeof...(ts)]{refl(ts)...}; // error: reference to local variable 'ts' declared in enclosing function
};
} I am particularly confused by the auto f1(int i) {
consteval {
auto info1 = reflexpr(i); // OK
auto info2 = refl(i); // OK
};
} |
See https://cppx.godbolt.org/z/WMsqfh. Weirdly, the block evaluates and you can even iterate over the array - I guess error is a bug. |
There are a few parts to this. I've fixed
This new syntax branch in general, greatly improves our support for packs; including the introduction of a splice that forms a pack from an expandable expression i.e. As for |
The new syntax being closer to http://open-std.org/JTC1/SC22/WG21/docs/papers/2020/p2237r0.pdf ? Would you be interested in early feedback? |
Yes, closer to though not quite. The main difference being the use of As for early feedback, sure :) |
Cool, I'll switch to experimenting with that then :) |
Fair warning: It's not yet updated for metaprogramming purposes, just the base reflection branch for the moment. Commits are also pretty volatile there (expect force pushes and history rewrites on that branch) :) |
Thanks for the warning :-) Are you planning to add metaprogramming to the same branch? |
When we're ready I anticipate the branch will be merged into Might be some delay in things going to compiler-explorer; we'll have to work with Matt a bit to minimize breakages of existing godbolt links -- I believe those mechanisms are already in place for other compilers he hosts though, so this shouldn't be a big deal. |
Hi,
I probably searched for the wrong terms, but I could not find a way to reflect a parameter pack? I want to consteval-iterate over the template parameters of a class template. Here is one of the (incorrect) things I tried:
See also https://cppx.godbolt.org/z/TYT9WG
Thanks,
Roland
The text was updated successfully, but these errors were encountered: