G
Guest
I want to write a shorthand version of the following code, which
iterates over all the elements of a STL container, e.g. vector:
for (vector<char>::const_iterator i = v.begin(); i != v.end(); ++i)
{
...
}
I want to reduce this somewhat bulky line, which appears everywhere in
my code, to something shorter, like:
for_each_i(v)
{
....
}
I'm not using the STL for_each because I don't necessarily want to
define a function/functor for my for loop.
It seems the problem is I can't get v's type from v. No "typeof" in
C++.
So I have to settle with something that looks like this:
for_each_i(vector<char>, v)
{
...
}
... which is ugly.
Any ideas on how to implement this for_each_i macro?
iterates over all the elements of a STL container, e.g. vector:
for (vector<char>::const_iterator i = v.begin(); i != v.end(); ++i)
{
...
}
I want to reduce this somewhat bulky line, which appears everywhere in
my code, to something shorter, like:
for_each_i(v)
{
....
}
I'm not using the STL for_each because I don't necessarily want to
define a function/functor for my for loop.
It seems the problem is I can't get v's type from v. No "typeof" in
C++.
So I have to settle with something that looks like this:
for_each_i(vector<char>, v)
{
...
}
... which is ugly.
Any ideas on how to implement this for_each_i macro?