
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.

Meryl Silverburgh wrote:
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.
I'm not sure if it's useful to you, but the boost::bind solution is to use a
helper function:
#include
participants (2)
-
Meryl Silverburgh
-
Peter Dimov