operator()
状況によっては、callable (関数、関数ポインター、ラムダを使用mem_fn
したオブジェクト インスタンスなど)を型消去できることが望ましい場合があります。タイプが必要です。
std::function
理想的ですが、クラス テンプレートをインスタンス化するシグネチャを自動的に決定する方法はないようstd::function
です。任意の callable の関数シグネチャを取得したり、適切なstd::function
インスタンス化インスタンス (make_function
関数テンプレートなど) にラップしたりする簡単な方法はありますか?
具体的には、次のいずれかを探しています
template<typename F> using get_signature = ...;
template<typename F> std::function<get_signature<F>> make_function(F &&f) { ... }
をmake_function([](int i) { return 0; })
返すようなものstd::function<int(int)>
。インスタンスが複数の署名で呼び出し可能な場合 (たとえば、複数の template または default-parameter を持つオブジェクト)、明らかにこれは機能しないと予想されますoperator()
。
過度に複雑でない非ブースト ソリューションが優先されますが、ブーストは問題ありません。
編集:自分の質問に答えます。