4 Mar
2006
4 Mar
'06
1:22 a.m.
yinglcs2@yahoo.com 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