473,385 Members | 1,461 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,385 software developers and data experts.

for_each function and operator()

Hello everyone,
I can not find related information in MSDN, so I want to confirm here,
that,

the implementation of for_each is something like,

Expand|Select|Wrap|Line Numbers
  1. template <class A, class BB for_each (A begin, A end, B Func)
  2. {
  3. while (begin != end) Func(*begin++);
  4. return Func;
  5. }
  6.  
So, operator(*A) of class Func will be invoked? Right?
thanks in advance,
George
Dec 3 '07 #1
3 1721
George2 wrote:
Hello everyone,
I can not find related information in MSDN, so I want to confirm here,
that,

the implementation of for_each is something like,

Expand|Select|Wrap|Line Numbers
  1. template <class A, class BB for_each (A begin, A end, B Func)
  2. {
  3.     while (begin != end) Func(*begin++);
  4.     return Func;
  5. }
  6.  

So, operator(*A) of class Func will be invoked? Right?
Yes.
Dec 3 '07 #2
George2 wrote:
I can not find related information in MSDN, so I want to confirm here,
that,

the implementation of for_each is something like,

Expand|Select|Wrap|Line Numbers
  1. template <class A, class BB for_each (A begin, A end, B Func)
  2. {
  3.    while (begin != end) Func(*begin++);
  4.    return Func;
  5. }
  6.  

So, operator(*A) of class Func will be invoked? Right?
If 'B' is a class, then yes, operator(). If 'B' is a function type,
then the function 'Func' will be called.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 3 '07 #3
On Dec 3, 4:30 pm, George2 <george4acade...@yahoo.comwrote:
Hello everyone,

I can not find related information in MSDN, so I want to confirm here,
that,
if your tools are not outdated you can just right click on what you
have typed and select 'go to definition'.
>
the implementation of for_each is something like,

Expand|Select|Wrap|Line Numbers
  1. template <class A, class BB for_each (A begin, A end, B Func)
  2. {
  3.     while (begin != end) Func(*begin++);
  4.     return Func;}
  5.  
MS actualy devices a for loop instead of while and uses preincrement(+
+it) operation which results in more optimized and readable
implementation.
regards,
FM.
Dec 3 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Alex Vinokur | last post by:
Functor-parameters in the for_each() and transform() algorithms are passed by value. Might it make sense to have also algorithms for_each2() and transform2() which pass Functor-parameters by...
18
by: John Black | last post by:
Hi, I am not familiar with for_each very well, suppoase I have a vector<pair<unsigned int, unsigned int> > vec1 and the contents are {<0x00000000, 0x000000FF>, <0x10000000, 0x2FFFFFFF>} what...
6
by: Michal Wyrebski | last post by:
Hello, I'm new in this group and I don't know if my questions are too silly, but I'm intermediate programmer and don't have enought experience. Please be charitable. I don't know how to write...
1
by: Capstar | last post by:
Hi NG, I have a question on std::for_each. I try to use this in combination with std::bind2nd to call a method of all functions in a container (std::set or std::map) and pass that method the...
9
by: shaun | last post by:
I am working on code where I am handed a vector of pointers vector<T*> or a map<std::string, T*>, and I have to delete the objects and set the pointers to zero. I have been using a 'for' loop and...
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...
27
by: Fraser Ross | last post by:
Is it wrong to describe for_each as a modifying algorithm? It is described as one here: http://www.josuttis.com/libbook/algolist.pdf. transform appears to be the algorithm to use for modifying...
3
by: PolkaHead | last post by:
I was wondering if there's a way to traverse a two-dimensional vector (vector of vectors) with a nested for_each call. The code included traverses the "outer" vector with a for_each, than it...
9
by: Chris Roth | last post by:
I have a vector of vectors: vector< vector<double v; and have initialized it with: v( 5 ); as I know I will have 5 columns of data. At this point, I read text file data into each of the the...
9
by: nguillot | last post by:
Hello I used to loop on a std::map<k, dto act on the data (d) like that (d being a class with setIntMember method): typedef std::map<k, dtMap; struct setIntMember { setIntMember(int j) :...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.