Visual C ++ 12 (VS2013 Preview) variation template with parameter workaround

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?

+8
c ++ 11 visual-c ++
source share
1 answer

Not sure why, but seems to be simplified with typedef:

 template <typename... P> struct S { typedef void (*MyFunc)(P...); template <MyFunc myFunc> static void foo() {} }; void foo2(int, float) {} int main() { S<int, float>::foo<&foo2>(); } 

At least in the preview of Visual Studio 2013 Ultimate.

+6
source share

All Articles