title: Unchecked read from a map in a const function
body: <p>Suppose the following:</p>
  
  <pre><code>struct C {
      ... // lots of other stuff
      int get(int key) const { return m.at(key); } // This will never throw
  private:
      std::unordered_map&lt;int, int&gt; m;
  };
  </code></pre>
  
  <p>Due to how the application works, I know that <code>get</code> never throws. I want to make <code>get</code> as fast as possible. So, I would like to make the access unchecked, i.e. I would like to write something like <code>return m[key]</code>. Of course, I cannot write exactly that while keeping <code>get</code> const. However, I want to keep <code>get</code> const, since it <em>is</em> logically const.</p>
  
  <p>Here is the only (ugly) solution I came up with:</p>
  
  <pre><code>struct C {
      ... // lots of other stuff
      int get(int key) const { return const_cast&lt;C *&gt;(this)-&gt;m[key]; }
  private:
      std::unordered_map&lt;int, int&gt; m;
  }; 
  </code></pre>
  
  <p>Is there a better way?</p>