
2 Feb
2007
2 Feb
'07
8:05 p.m.
Hi, I have a sorted int vector 'orgWidth'. I would like to save the save into a new int vector 'newWidth' if the value of the current element is 10% bigger than the previous one. For example, orgWidth int vector : 300 366 729 769 781 1297 newWidth int vector: 300 366 729 1297 I know how to add the value to the newWidth vector using the if_then with boost. But my question is how can I update the value of the 'previousWidth' as I use for_each() algorithm. int previousWidth = -1; vector<int> orgWidth; for_each(orgWidth.begin(), orgWidth.end(), if_then( (_1 > (previousWidth * 1.1)) , bind (&vector<int>::push_back,boost::ref(newWidth), _1 ))); Thanks for any help.