minor confusion
From: ma740988 (ma740988_at_pegasus.cc.ucf.edu)
Date: 02/22/04
- Next message: Bob Smith: "Efficiently passing strings?"
- Previous message: Buck Rogers: "printing strings & right justifying text"
- Next in thread: Leor Zolman: "Re: minor confusion"
- Reply: Leor Zolman: "Re: minor confusion"
- Reply: Josh Sebastian: "Re: minor confusion"
- Reply: Francis Glassborow: "Re: minor confusion"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 21 Feb 2004 16:55:06 -0800
The for_each alogrithm calls the print function for each element in
the range vec.begin to vec.end, BUT the print function expects an int
argument. So now I'm confused on how to tie the two together?
In other words, I'd expect the for_each to look something like
for_each (vec.begin(), vec.end(), print(vec(idx));
#include <iostream>
#include <vector>
#include <algorithm>
void print( int elements_ )
{
std::cout << elements_;
}
int main()
{
std::vector<int> vec;
for (int idx=1; idx<=9; idx++)
{
vec.push_back(idx);
}
// now print them
std::for_each(vec.begin(), vec.end(), print);
std::cout << std::endl;
}
I realize this may be a question for the 'standards' group,
nonetheless, for_each is an algorithm and part of the 'std' namespace.
Why is not a part of say an algorithm namespace? so instead of doing
std::for_each we'd do alg::for_each .. or ..
A solution lies in a text/newsgroups/google search etc, but for the
uninitiated what this does is make us wonder. What all makes up the
'algorithm'
The same can be said about 'std::vector'.
Thanks in advance
- Next message: Bob Smith: "Efficiently passing strings?"
- Previous message: Buck Rogers: "printing strings & right justifying text"
- Next in thread: Leor Zolman: "Re: minor confusion"
- Reply: Leor Zolman: "Re: minor confusion"
- Reply: Josh Sebastian: "Re: minor confusion"
- Reply: Francis Glassborow: "Re: minor confusion"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|