title: Why is std::map index off by one?
body: <p>I am trying to get the index of the key in the map. I use distance
  for this. Why is the result always one off? I was expecting "ale" 
  index to be 2 but the answer is 1.</p>
  
  <pre><code>#include &lt;map&gt;
  #include &lt;iostream&gt;
  
  int main(){
  
    std::map&lt;std::string, int&gt; my_map;
  
    my_map.insert(std::make_pair("apple", 0));
    my_map.insert(std::make_pair("a", 0));
    my_map.insert(std::make_pair("ale", 0));
    my_map.insert(std::make_pair("aple", 0));
    my_map.insert(std::make_pair("aplle", 0));
  
    std::cout &lt;&lt; "map size = " &lt;&lt; my_map.size() &lt;&lt; std::endl;
    int index  = distance(my_map.begin(), my_map.find("ale"));
    std::cout &lt;&lt; "index = " &lt;&lt; index &lt;&lt; std::endl;
  
    index  = distance(my_map.begin(), my_map.find("a"));
    std::cout &lt;&lt; "index = " &lt;&lt; index &lt;&lt; std::endl;
  }
  </code></pre>