3
私は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)>
だろう。)
(注:私は成功せずのバリエーションを試してみました。)
はC++ 0xで、このことは可能ですか?
はい、これはVS2010でも動作します。ありがとう! –