Quote Originally Posted by treuss
I think, a reasonable way of achieving this is to provide a clone() function for your class and then use std::transform.
Code:
class C {
  // ...
  virtual C* clone() { return new C(*this); }
}
Call to transform should look something like (not tested):
Code:
std::transform(c_vec.begin(), c_vec.end(),
               std::back_inserter(new_c_vec),
               mem_fun_ref(clone));
or, if you resize new_c_vec before like
Code:
std::transform(c_vec.begin(), c_vec.end(),
               new_c_vec.begin(),
               mem_fun_ref(clone));
Nice idea! But in this case would it be better just to iterate through c_vec and push_back new Cs instead of creating the clone function? It won't be hard to change the classes that rely on this, but I'm just wondering which option you think is more professional.


Cheers.