Hi,
I have an vector of objects
Code:
std::vector<Class> v1;
and now I want to make a vector of Class *, which index pointing to a element in v1. for example
Code:
std::vector<Class *> v2;
v2[0] = &v1[0]
I can easily do this by writing the following loop
Code:
v2.reserve ( v1.size() );
for (vector<Class>::iterator it = v1.begin(); it != v1.end(); it++) {
    v2.push_back ( &(*it) );
}
But I wanted to do this in a more STL style way, so I used a transform:
Code:
transform (v1.begin(), v1.territories.end(), v2.begin(), addressof<Class>() );
However, the addressof unary functor doesn't exist, so I coded one like so:
Code:
template <class T> struct addressof : std::unary_function <T,T> {
  T* operator() (T& x) const
    {return &x;}
};
Now my two questions are,
1) Does a functor like addressof already exist?
2) Is there anything wrong/weird with my approach?

I wanted to create an array of Class *, so I could quickly shuffle the array without copying the class instance many times. e.g.
Code:
random_shuffle ( v2.begin(), v2.end() );
I know that my v2 array will contain invalid pointers if v1 changes, however, once v1 is setup it will never grow/shrink.

thanks
Andrew