By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,778 Members | 1,919 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,778 IT Pros & Developers. It's quick & easy.

Implicit iteration counter in std::for_each

P: n/a
Hi everybody,

does anyone knows is there any way to have an implicit iteration
counter in std::for_each ?
e.g. std::for_each(c.begin(), c.end(), boost::bind(&C::set_id, _1,
<iteration_counter>));
so the first object will have id of 0, second of 1 and so on ?..

Best regards, Paul Sujkov

Mar 14 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 2007-03-14 16:17, ps*****@gmail.com wrote:
Hi everybody,

does anyone knows is there any way to have an implicit iteration
counter in std::for_each ?
e.g. std::for_each(c.begin(), c.end(), boost::bind(&C::set_id, _1,
<iteration_counter>));
so the first object will have id of 0, second of 1 and so on ?..
I'm not too familiar with the boost::bind and such but could you not use
a member in the functor. Using a static member you could perhaps even
get rid of using boost::bind.

--
Erik Wikström
Mar 14 '07 #2

P: n/a
On 14 Mar 2007 08:17:55 -0700 in comp.lang.c++, ps*****@gmail.com wrote,
>does anyone knows is there any way to have an implicit iteration
counter in std::for_each ?
e.g. std::for_each(c.begin(), c.end(), boost::bind(&C::set_id, _1,
<iteration_counter>));
check std::generate()

Mar 14 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.