D
Diego Martins
Let's say I have a vector of pointers of Base
vector<Base *> vec;
Now, someone assured me all elements of the vector are of dynamic type
Derived *.
I want to use for_each or other STL algorithms in this container using
Derived members.
My current workaround is presented as follows:
void KludgeFunction(Base * elem) {
static_cast<Derived *>(elem)->myDerivedOperation();
}
....
for_each(vec.begin(),vec.end(),KludgeFunction);
We know if vec was vector<Derived *>, we can do it more simply by:
for_each(vec.begin(),vec.end(),mem_fun(&Derived::myDerivedOperation));
Do you how can I build something to avoid writing the KludgeFunction?
- an interator adaptor?
- a binder?
any ideas?
Diego Martins
HP
vector<Base *> vec;
Now, someone assured me all elements of the vector are of dynamic type
Derived *.
I want to use for_each or other STL algorithms in this container using
Derived members.
My current workaround is presented as follows:
void KludgeFunction(Base * elem) {
static_cast<Derived *>(elem)->myDerivedOperation();
}
....
for_each(vec.begin(),vec.end(),KludgeFunction);
We know if vec was vector<Derived *>, we can do it more simply by:
for_each(vec.begin(),vec.end(),mem_fun(&Derived::myDerivedOperation));
Do you how can I build something to avoid writing the KludgeFunction?
- an interator adaptor?
- a binder?
any ideas?
Diego Martins
HP