alexbuisson
alexbuisson

Reputation: 8509

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)
{
}

Upvotes: 5

Views: 243

Answers (1)

juanchopanza
juanchopanza

Reputation: 227628

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

Upvotes: 12

Related Questions