Is there an easy way of creating a vector of pointers to the elements of a vector?
i.e. easier than the below
std::vector<T*> fn(std::vector<T> &v)
{
std::vector<T*> r;
for (int i = 0; i < v.size(); i++)
{
r.push_back(&v[i]);
}
return r;
}
EDIT: Incoming vector by reference
As @Benoit suggested, it is a bad idea to store these pointers. But if you really want to do it, you can use
std::transformlike this: