Functor が必要なことを実行できるかどうかを調べようとして、私はここに潜んでいました。
私がやりたいことは、クラス メソッドへの呼び出しをラップし、何らかの方法で関数が返す値をキャプチャすることです。Functor クラスが与えられた場合、コメントをコードに変換するにはどうすればよいでしょうか。
template < typename Func >
class MySpecializedFunctor
{
Func t;
MyObject& p;
public:
MyFunctor( MyObject &obj, Func f )
{
p = obj;
t = f;
}
void runFunc( ... )
{
// Can I use an ellipsis '...' to pass values into t->xxxx() ???
// Assume the first param is always time, the others are never the same
bool b = p->t( time( NULL ), /* first value of ... */, /* second value of ... */ );
if ( !b )
{
// log error here
}
}
}
これは一種の Functor であるため、ラップされる関数は n 個のパラメーターを持つことができます。
これは可能ですか?
編集: C++0X を使用できません。