T
thomas
---code---
int func(int &elem) const{
return elem+2;
}
vector<int> vec(30,0);
foreach(vec.begin(), vec.end(), func);
----code-----
As we see that the "func" function can only do operations on the
"elem" itself, not the iterator.
But if I want to do this:
for each element in vector vec
*elem = iter - vec.begin(); //its position in the vector.
how can I do this? in the "func" function, I only can see the
"elem"(int), I cannot get the "iter"(iterator), so the position info
is missing?
Of course I know that I can do it by a for loop, but any other way to
do it?
int func(int &elem) const{
return elem+2;
}
vector<int> vec(30,0);
foreach(vec.begin(), vec.end(), func);
----code-----
As we see that the "func" function can only do operations on the
"elem" itself, not the iterator.
But if I want to do this:
for each element in vector vec
*elem = iter - vec.begin(); //its position in the vector.
how can I do this? in the "func" function, I only can see the
"elem"(int), I cannot get the "iter"(iterator), so the position info
is missing?
Of course I know that I can do it by a for loop, but any other way to
do it?