title: How to use BOOST_FOREACH with a boost::ptr_map?
body: <p>How can I use BOOST_FOREACH efficiently (number-of-character/readability-wise) with a boost::ptr_map?  </p>
  
  <p>Kristo demonstrated in his <a href="https://stackoverflow.com/questions/461507/how-to-use-boostforeach-with-a-boostptrmap#461908">answer</a> that it is possible to use BOOST_FOREACH with a ptr_map, but it does not really save me any typing (or makes my code really more readable) than iterating over the ptr_map with an iterator:</p>
  
  <pre><code>typedef boost::ptr_container_detail::ref_pair&lt;int, int* const&gt; IntPair;
  BOOST_FOREACH(IntPair p, mymap) {
      int i = p.first;
  }
  
  // vs.
  
  boost::ptr_map&lt;int, T&gt;::iterator it;
  for (it = mymap.begin(); it != mymap.end(); ++it) {
      // doSomething()
  }
  </code></pre>
  
  <p>The following code is somewhere along the lines what I wish for. It follows the standard way on how to use BOOST_FOREACH with a std::map.  Unfortunately this does not compile:</p>
  
  <pre><code>boost::ptr_map&lt;int, T&gt; mymap;
  // insert something into mymap
  // ...
  
  typedef pair&lt;int, T&gt; IntTpair;
  BOOST_FOREACH (IntTpair &amp;p, mymap) {
      int i = p.first;
  }
  </code></pre>