title: When I should use std::map::at to retrieve map element
body: <p>I have read different articles on web and questions at <a href="https://stackoverflow.com/search?q=How%20to%20find%20if%20a%20given%20key%20exists%20in%20a%20C%2B%2B%20std%3A%3Amap">stackoverflow</a>, but for me it is not clear is there any exclusive case when it is better to use <code>std::map::at</code> to retrieve map element.</p>
  
  <p>According to <a href="http://www.cplusplus.com/reference/map/map/at/" rel="noreferrer">definition</a>, <code>std::map::at</code> </p>
  
  <blockquote>
    <p>Returns a reference to the mapped value of the element identified with
    key k.</p>
    
    <p>If k does not match the key of any element in the container, the
    function throws an out_of_range exception.</p>
  </blockquote>
  
  <p>For me only case when it is worth to use <code>std::map::at</code> when you 100% sure that element with particular key exist, otherwise you should consider exception handling.</p>
  
  <ol>
  <li>Is there any case where <code>std::map::at</code> considered as most efficient and elegant way to do?  In what cases you will recommend to use <code>std::map::at</code> ?</li>
  <li>Am I right that it is better to use <code>map::find()</code> when there is a possibility to not have element with such a key? And <code>map::find()</code> it is faster and more elegant approach?</li>
  </ol>
  
  <blockquote>
  <pre><code>if ( map.find("key") != map.end() )
  {
      // found 
  
  } else
  {
      // not found
  }
  </code></pre>
  </blockquote>
  
  <p><strong>p.s</strong> </p>
  
  <p><code>map::operator[]</code>  sometimes can be dangerous, because if an element doesn't exist then it will inserts it.</p>
  
  <p><strong>EDITED:</strong> links somehow related <a href="https://stackoverflow.com/questions/10821405/difference-between-map-and-map-at-in-c">link 1</a> <a href="https://stackoverflow.com/questions/2781899/how-to-find-whether-an-element-exists-in-stdmap">link 2</a> <a href="https://stackoverflow.com/questions/1939953/how-to-find-if-a-given-key-exists-in-a-c-stdmap">link 3</a> <a href="https://stackoverflow.com/questions/3136520/determine-if-map-contains-a-value-for-a-key">link 4</a> <a href="https://stackoverflow.com/questions/535317/checking-value-exist-in-a-stdmap-c">link 5</a> <a href="https://stackoverflow.com/questions/10582089/stl-map-should-use-find-or-n-identifier-to-find-element-in-map">link 6</a></p>