R
Ram
Hi,
I have a container of base pointers and I want to generate a container
of derived class pointers from it by casting each pointer of base class
to a pointer of derived class. Is it possible to do it using some
algorithm and function object from STL?
e.g.
std::vector<Base*> base_vector;
std::vector<Derived*> derived_vector;
// populate base vector..
I would like to say something like,
std::transform(base_vector.begin(), base_vector.end(),
std::back_inserter(derived_vector), dynamic_cast<Derived*>());
To be short, I am looking for a function object which can convert one
type of object to another. I think cast operators don't behave like
function objects so they can't be passed to stl algorithms.
Thanks
Ram
I have a container of base pointers and I want to generate a container
of derived class pointers from it by casting each pointer of base class
to a pointer of derived class. Is it possible to do it using some
algorithm and function object from STL?
e.g.
std::vector<Base*> base_vector;
std::vector<Derived*> derived_vector;
// populate base vector..
I would like to say something like,
std::transform(base_vector.begin(), base_vector.end(),
std::back_inserter(derived_vector), dynamic_cast<Derived*>());
To be short, I am looking for a function object which can convert one
type of object to another. I think cast operators don't behave like
function objects so they can't be passed to stl algorithms.
Thanks
Ram