Что Вы сохраняете во вводе, Вы проигрываете в удобочитаемости. Много отладчиков не будут иметь подсказки, что Вы отсылаете к любому настолько отлаживающему, является более трудным. Это не делает программы выполненными быстрее.
Считают создание кода в Вашем с оператором методом объекта, к которому Вы обращаетесь.
A reliable fallback when the bind-syntax gets too weird is to define your own functor:
struct callDoSomething {
void operator()(const X* x){
StaticFuncClass::doSomething(x->getName(), funcReturningString());
}
};
for_each(ctr.begin(), ctr.end(), callDoSomething());
This is more or less what the bind
functions do behind the scenes anyway.
The "STL solution" would be to write your own binder... that's why they created the powerful boost::bind.
You can either create a local functor structure, which can be inlined by the compiler (as Jalf showed), or use a simple function:
void myFunc( const X* x ) {
StaticFuncClass::doSomething(x->getName(), funcrReturningString() );
}
for_each( c.begin(), c.end(), myFunc );