title: unordered_map not iterating all keys
body: <p>I have the following code to iterate over all the keys in an unordered_map, while iterating I pass the map to some other function. Due to some reason the iterator is not able to iterate over all keys. I am not able to figure out why and how to fix this. If I pass the map as value instead of reference then it works as expected, but I want to pass by reference to save the copy.</p>
  
  <p>Code:</p>
  
  <pre><code>void DFS(char curr, unordered_map&lt;char, unordered_set&lt;char&gt;&gt;&amp; G) {
      cout &lt;&lt; "Traversing: " &lt;&lt; curr &lt;&lt; endl;
      for(const char&amp; ch: G[curr]) {
          DFS(ch, G);
      }
  }
  
  int main() {
      unordered_map&lt;char, unordered_set&lt;char&gt;&gt; G;
  
      G['c'].emplace('b');
      G['b'].emplace('a');
  
      for(auto it : G) {
          cout &lt;&lt; "Starting with: " &lt;&lt; it.first &lt;&lt; endl;
          DFS(it.first, G);
      }
  }
  </code></pre>
  
  <p>The output I get is:</p>
  
  <pre><code>Starting with: b
  Traversing: b
  Traversing: a
  </code></pre>
  
  <p>Note that it is not traversing key <code>c</code>.</p>
  
  <p><strong>UPDATE:</strong>
  Changing the DFS function to make the map const like below is also not helping:</p>
  
  <pre><code>void DFS(const char curr, const unordered_map&lt;char, unordered_set&lt;char&gt;&gt;&amp; G) {
      cout &lt;&lt; "Traversing: " &lt;&lt; curr &lt;&lt; endl;
      for(auto ch: G.at(curr)) {
          DFS(ch, G);
      }
  }
  </code></pre>
  
  <p>And it is throwing an exception as well:</p>
  
  <pre><code>terminate called after throwing an instance of 'std::out_of_range'
    what():  _Map_base::at
  </code></pre>