473,326 Members | 2,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Implicit iteration counter in std::for_each

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
2 2020
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Dylan | last post by:
At the moment I often find myself doing something like the following std::list<MyClass*> mcl; /.../fill mcl with some elements //now call aMethod() for each element; for...
6
by: Philip Potter | last post by:
Hello there, I'm reading about the std::for_each() function in TC++PL, 3rd Ed. It seems like a good idea, but in practice I can never see a way to bend it to my wishes without writing huge...
22
by: yurec | last post by:
Hi I wanna give template method of library class with some predicate, which I put to std::for_each in that method.How to break the std::for_each with predicate?(exceptions are used olny in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.