Lambda library if_then question
I have a function which check the x of a RectList if it matches
certain value, it put the y in an int vector, like this.
class Rect{
int x;
int y;
};
typedef list
Meryl Silverburgh wrote:
But when I try to replace the code using boost lambda, I can't get it to compile. can you please tell me what am I missing?
void addKey(RectList& rectList, vector<int>& keys, int value) {
for_each(rectList.begin(), rectList.end(), if_then( bind (&Rect::x, _1) == value, deviantKey.push_back( bind (&Rect::y, _1) )));
}
You're missing a bind. You need to bind the push_back call. for_each(rectList.begin(), rectList.end(), if_then( bind( &Rect::x, _1) == value, bind(&std::vector<int>::push_back, deviantKey, bind( &Rect::y, _1)))); Not tested. Sebastian Redl
participants (2)
-
Meryl Silverburgh
-
Sebastian Redl