OK, I know BOOST_FOREACH isn't part of the official (1.33.1) build yet, but
hopefully some people here are using this excellent algorithm and can help
me out... (note that I am using MS Visual Studio 2005):
How can I use BOOST_FOREACH to iterate through a map? For example, the
following won't build:
std::map m;
BOOST_FOREACH(std::pair p, m)
{
}
I get the following error:
warning C4002: too many actual parameters for macro 'BOOST_FOREACH'
However, the following will work OK:
std::map m;
std::pair p;
BOOST_FOREACH(p, m)
{
}
But is there a way to declare the pair within the FOREACH loop? Note that I
also tried the following, with no success:
std::map m;
BOOST_FOREACH(std::map::value_type p, m)
{
}
A typedef also seems to work, e.g.:
std::map m;
typedef std::pair mpair;
BOOST_FOREACH(mpair p, m)
{
}
Can the pair be declared without a typedef? Is this a limitation of the MS
compiler?
Thanks in advance.