Implicit iteration counter in std::for_each

P

psujkov

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
 
G

Guest

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.
 
D

David Harmon

On 14 Mar 2007 08:17:55 -0700 in comp.lang.c++, (e-mail address removed) 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()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top