Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why BOOST_FOREACH on a map only work with a typedef

I tried to write a simple loop through map<int, int>element and I'm wondering why the 1st syntax I used doesn't work/compile ?

The 1st version I wrote was the following and it doesn't compile with VS'2008 / boost version 1.44:

std::map<int, int> myMap;
...
BOOST_FOREACH(map<int, int>::value_type &p, myMap)
{
}

Now if I rewrite the code like below the compilation is ok, but why ?

typedef std::map<int, int> myMap_t;
myMap_t myMap;
...
BOOST_FOREACH(myMap_t::value_type &p, myMap)
{
}
like image 428
alexbuisson Avatar asked Mar 18 '14 13:03

alexbuisson


1 Answers

It is a preprocessor macro, and it doesn't like the , in map<int, int>.

like image 167
juanchopanza Avatar answered Sep 22 '22 10:09

juanchopanza