I just registered this error with Microsoft Connect regarding the inability to compile the following code fragment:
template <typename... P> struct S { template <void(*F)(P...)> static void T() { } }; void A(int, float) { } int main() { S<int, float>::T<&A>(); }
Mistake:
test.cpp(2): error C3520: 'P' : parameter pack must be expanded in this context
Essentially, I cannot unzip a variational type inside a function signature when it is used as a template parameter. This code (I believe) is legal; at least GCC 4.7, Clang 3.0, and ICC 13 support it.
I saw this SO question , but no workarounds are requested or given, which I am looking for.
Although this is not supercritical (itโs obvious that I have been doing without variable templates for many years), this template is of particular importance for some work that I would like to do, and some articles that I would like to do C ++ 11 for serialization, binding script, etc., What I would like to use for Visual Studio users (since this is by far the dominant compiler toolkit in my industry). Hopefully, Microsoft engineers will be able to fix this before RTM 2013, but I'm not holding my breath.
A toy (from memory this time) an example of how it is used is something like (minus the macros, which make it a little easier to use):
Reflect<MyType>("MyType") .bind("GetMatrix", mat44, &MyType::GetMatrix>() .bind("Display", void, &MyType::Display>();
Of course, all this can be done without variation patterns. Of course, it simply requires large amounts of code and accepts restrictions on the maximum degree of related member functions. And yes, the transfer of functions as a template parameter is related to import due to the nature of how member function pointers work in Visual Studio (variable size) and the desire to achieve efficiency on a par with Directly Fast C ++ Delegates (in my niche C + community + this optimization level can sometimes make a difference), which denies the possibility of using std::function or similar constructs.
Is there any workaround for this VS error? Or any other way to use variable templates to use a function pointer parameter (compile time) in VC ++ 12?