title: Is casting to a bool a valid way to check for the existence of a unordered_map value matching a key? c++
body: <p>I have a nested unordered_map and would like to check whether a value has been created for a set of keys. Most of the solutions online like <a href="https://stackoverflow.com/questions/34512437/simplest-method-to-check-whether-unordered-map-of-unordered-maps-contains-key/34512483">this</a> suggest iterating through the keys to check for their existence. Is there an inherent problem with trying to access them and cast them to bool as I've done below? The output from the test leads me to believe it works.</p>
  <pre><code>    std::unordered_map&lt;int, std::unordered_map&lt;int, const char*&gt;&gt; myMap;
      myMap[1][2]=&quot;abc&quot;;
      myMap[2][2]=&quot;false&quot;;
      std::cout &lt;&lt;(bool)myMap[1][2]&lt;&lt; std::endl;
      std::cout &lt;&lt;(bool)myMap[0][0]&lt;&lt; std::endl;
      std::cout &lt;&lt;(bool)myMap[0][0]&lt;&lt; std::endl;
      std::cout &lt;&lt;(bool)myMap[1][4]&lt;&lt; std::endl;
      std::cout &lt;&lt;(bool)myMap[2][2]&lt;&lt; std::endl;
  </code></pre>
  <p>Output</p>
  <pre><code>1
  0
  0
  0
  1
  </code></pre>