std::function
関数テンプレートの 1 つのテンプレート引数の型に依存する型のを返したいと思います。
// 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 Express) にこの意図を伝えることができないようです。(注意:使用例では、 になりますstd::function<bool(F)>
。)
(注: のバリエーションを試しましたがstd::result_of<F>::type
成功しませんでした。)
これは C++0x で可能ですか?