3
我想返回一个std::function
,其类型取决于我的函数模板的一个模板参数的类型。如何返回依赖于模板参数的函数类型?
// Return a function object whose type is directly dependent on F
template<typename F, typename Arg1, typename Arg2>
auto make_f2_call(Arg1&& arg1, Arg2&& arg2)
-> std::function<--what-goes-here?-->
{
return [arg1, arg2](F f) { return f(arg1, arg2); };
}
// Usage example, so that it's clearer what the function does:
...
typedef bool (*MyFPtrT)(long id, std::string const& name);
bool testfn1(long id, std::string const& name);
...
auto c2 = make_f2_call<MyFPtrT>(i, n); // std::function<bool(F)>
...
bool result = c2(&testfn1);
按道理--what-goes-here?--
应该返回的F
返回类型,并采取F
类型的参数的函数的函数签名,但我似乎无法告诉我的编译器(Visual Studio 2010和的快递)这个意图。 (注意:在使用示例,这将是std::function<bool(F)>
)
(注:我已经试过的变化都没有成功。)
这是可能的的C++ 0x?
是,这个工程还对VS2010。谢谢! –