The corresponding algorithm is std :: transform , and you can include a member function call in a unary functor with std :: mem_fun
Example:
#include <vector>
#include <functional>
#include <algorithm>
#include <iterator>
class X
{
public:
X* clone();
};
int main()
{
std::vector<X*> vec1, vec2;
std::transform(vec1.begin(), vec1.end(), std::back_inserter(vec2), std::mem_fun(&X::clone));
}
If the target vector already has the same size as the input range, you can pass vec2.begin()as the third argument. Use back_inserterif the target is empty (or you want to add to it).
source
share