Qt foreach-like alternative to iterate over value AND key of an associative container
You can probably do something simpler to avoid making this a special case macro, e.g. using std::tie or boost::tie if that's not available:

#include &lt;map&gt;
#include &lt;functional&gt;
#include &lt;boost/foreach.hpp&gt;
#include &lt;iostream&gt;

int main() {
  std::map&lt;int, std::string&gt; map = {std::make_pair(1,"one"), std::make_pair(2,"two")};
  int k;
  std::string v;
  BOOST_FOREACH(std::tie(k, v), map) {
    std::cout &lt;&lt; "k=" &lt;&lt; k &lt;&lt; " - " &lt;&lt; v &lt;&lt; std::endl;
  }
}