Visual c++ visualc&x2B+;12(VS2013预览版)带功能参数的可变模板解决方案

Visual c++ visualc&x2B+;12(VS2013预览版)带功能参数的可变模板解决方案,visual-c++,c++11,Visual C++,C++11,我刚刚提交了关于无法编译以下玩具代码片段的文件: template <typename... P> struct S { template <void(*F)(P...)> static void T() { } }; void A(int, float) { } int main() { S<int, float>::T<&A>(); } 本质上,当用作模板参数时,我无法在函数签名内部解包变量类型。我认为这是合法的;至少,GC

我刚刚提交了关于无法编译以下玩具代码片段的文件:

template <typename... P> struct S {
    template <void(*F)(P...)> static void T() { }
};

void A(int, float) { }
int main() { S<int, float>::T<&A>(); }
本质上,当用作模板参数时,我无法在函数签名内部解包变量类型。我认为这是合法的;至少,GCC4.7、Clang3.0和ICC13都支持它

我已经看到了,但没有要求或给出解决办法,这就是我正在寻找的

虽然不是非常关键(显然我已经多年没有可变模板了),但这种模式对于我想做的一些工作和我想写的一些关于C++11序列化反射技术、脚本绑定、,这是我希望对VisualStudio用户有用的东西(因为它目前是我所在行业中占主导地位的编译器工具集)。我希望微软的工程师们能在2013年之前解决这个问题,但我不会屏息以待

一个玩具(这次来自内存)如何使用它的示例如下(减去使其稍微易于使用的宏):

Reflect(“MyType”)
.bind(“GetMatrix”、mat44和MyType::GetMatrix>()
.bind(“Display”,void,&MyType::Display>();
当然,这一切都可以在没有可变模板的情况下完成。当然,这只需要大量代码,并接受对绑定成员函数最大算术数的限制。是的,由于Visual Studio中成员函数指针的工作性质(可变大小),将函数作为模板参数传递是非常重要的并且,为了达到效率(在C++社区中的利基中,这种优化有时有时会很重要),这就否定了使用<代码> STD::函数< /> >或类似设计的选项。


这个VS bug有解决方法吗?或者使用可变模板在VC++12中使用(编译时)函数指针参数有其他方法吗?

不知道为什么,但使用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>();
}
模板
结构
{
typedef void(*MyFunc)(第页);
模板
静态void foo(){}
};
void foo2(int,float){}
int main()
{
S::foo();
}

至少在Visual Studio 2013终极预览版上是这样。

太完美了。我需要弄清楚如何轻松地将其应用于绑定成员函数指针,但这应该很简单。
Reflect<MyType>("MyType")
.bind("GetMatrix", mat44, &MyType::GetMatrix>()
.bind("Display", void, &MyType::Display>();
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>();
}