title: What is the easiest way to create a generic template iterator that can iterate through std::map values, in particular?
body: <p>I'd like to have a generic template iterator that iterates through a container of elements and accesses a specific member of the element. For example, if I have a <code>map&lt;string, int&gt;</code>, I iterate on the map values in a way like this:</p>
  
  <pre><code>for (TheCoolIter i = TheCoolIter(my_map.begin()); i != TheCoolIter(my_map.end()); ++i)
      int val = *i;
  </code></pre>
  
  <p>and <code>*i</code> return <code>p.second</code>.</p>
  
  <p>But if I iterate through a vector of struct-s <code>*i</code> returns <code>MyStruct::a_member</code>;</p>
  
  <p>This iterator can used if a class has <code>std::map</code> internally but exposes an interface for enumerating the map values without knowing the map type and key type, for example.</p>
  
  <p>EDIT1:</p>
  
  <p>The same code should iterate on <code>std::vector&lt;int&gt;</code> and on the values of <code>std::map&lt;string, int&gt;</code></p>
  
  <p>EDIT2:</p>
  
  <p>A <a href="https://gist.github.com/eruffaldi/93d09ed6644ae3fa279f" rel="nofollow noreferrer">good example</a>.</p>