Apply a callback to an array: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
Line 110: | Line 110: | ||
} |
} |
||
//prints 1x 2x 3x 4x 5x |
//prints 1x 2x 3x 4x 5x |
||
Using Boost.Lambda |
|||
using namespace std; |
|||
using namespace boost::lambda; |
|||
vector<int> ary(10); |
|||
int i = 0; |
|||
for_each(ary.begin(), ary.end(), _1 = ++var(i)); // init array |
|||
for_each(ary.begin(), ary.end(), _1 = _1 * _1); // square |
|||
copy(ary.begin(), ary.end(), ostream_iterator<int>(cout, " ")); // output |
|||
== [[FP]] == |
== [[FP]] == |