You need to use:
typedef std::map<int, int> map_type;
map_type map = /* ... */;
BOOST_FOREACH(const map_type::value_type& myPair, map)
{
// ...
}
The reason being that the macro expects two parameters. When you try to inline the pair definition, you introduce a second comma, making the macro three parameters instead. The preprocessor doesn’t respect any C++ constructs, it only knows text.
So when you say BOOST_FOREACH(pair<int, int>, map), the preprocessor sees these three arguments for the macro:
1.pair<int
2. int>
3. map
Which is wrong. This is mentioned in the for-each documentation.