2011-08-16 51 views
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?

回答

3

下编译对我来说既GCC 4.5.3和MSVC 2010 EE SP1

auto make_f2_call(Arg1&& arg1, Arg2&& arg2) 
    -> std::function< typename std::result_of<F(Arg1, Arg2)>::type (F)> 
{ 
+0

是,这个工程还对VS2010。谢谢! –

相关问题