|
Boost Users : |
From: Delfin Rojas (drojas_at_[hidden])
Date: 2006-03-03 20:22:03
> yinglcs2_at_[hidden] wrote
>
> I have a vector of Rect. and I would like to copy those where
> Rect::getX() equals to certain value.
>
> typedef RectList list<Rect>;
>
> void handleX(const RectList& rectList, int value, RectList&
> destList) {
>
> transform(rectList.begin(), rectList.end(),
> back_inserter(destList), if_then ( bind(&Rect::getX,
> _1) == value , _1 ));
> }
>
It seems what you want is copy_if. transform won't help in this case because
it will execute the predicate on every element and assign its return value
to the output iterator, try this (not tested):
for_each(rectList.begin(), rectList.end(), if_then(bind(&Rect::getX, _1) ==
value, bind(&RectList::push_back, ref(destList), _1)));
-delfin
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net