| re: STL:invoking a member of an object not in the container
Steven T. Hatton wrote:[color=blue]
> I have a std::vector<Vec3*> _vertices and an object BoundingBox _bbox. _bbox
> has a member function called void expandBy(Vec3& v); I want to call
> _bbox.expandBy on every member of _vertices. I know I can loop through and
> do that. I also know I can create a function object and pass it. The
> latter can be pretty slick, if I will be doing it a lot. It seems more
> trouble than it's worth to do it for only one function in one class.
> AFAIK, there is no way to use things such as mem_fun to do that. They
> apply to the objects in the container being iterated over by the STL
> algorithm.
>
> Is there a way to accomplish what I want with the STL algorithms? Boost?[/color]
Actually, using 'bind1st' and 'mem_fun' should be enough, no need for
Boost. I can never remember the right order of things, takes me a couple
of tries to get it right, but the direction is something like
BoundingBox _bbox;
for_each(_vertices.begin(), _vertices.end(),
bind1st(mem_fun(&BoundingBox::expandBy), &_bbox));
V |