I'm looking to optimize a portion of my code that is extremely time sensitive (will be running at least 1000x/s). It involves sequentially calling a series of functions to modify a given value. To avoid the overhead of function pointers, I would like to use functors allowing the compiler to inline. What I'm trying to do looks like the following:
Code:
typedef std::unary_function<DataType&, void> Func;
ClassA InstanceOfA;
ClassB InstanceOfB;
class FuncA : public Func{
public:
void operator()(DataType& d){
InstanceOfA.MemberFunc(d);
}
};
class FuncB : public Func{
public:
void operator()(DataType& d){
InstanceOfB.MemberFunc(d);
}
};
...
std::list<Func> listOfFuncs;
...
DataType val;
std::list<Func>::iterator it = listOfFuncs.begin();
(*it)(val)
I can't seem to get it to work though. I must admit I've never used the unary_function STL base type. Am I using it improperly?