title: vector::at vs. vector::operator[]
body: <p>I know that <code>at()</code> is slower than <code>[]</code> because of its boundary checking, which is also discussed in similar questions like <a href="https://stackoverflow.com/q/2578638/1168156">C++ Vector at/[] operator speed</a>  or <a href="https://stackoverflow.com/q/3269809/1168156">::std::vector::at() vs operator[] &lt;&lt; surprising results!! 5 to 10 times slower/faster!</a>. I just don't understand what the <code>at()</code> method is good for.</p>
  
  <p>If I have a simple vector like this one: <code>std::vector&lt;int&gt; v(10);</code> and I decide to access its elements by using <code>at()</code> instead of <code>[]</code> in situation when I have a index <code>i</code> and I'm not sure if its in vectors bounds, it forces me to <strong>wrap it with try-catch block</strong>:</p>
  
  <pre><code>try
  {
      v.at(i) = 2;
  }
  catch (std::out_of_range&amp; oor)
  {
      ...
  }
  </code></pre>
  
  <p>although I'm able to do the get the same behaviour by using <code>size()</code> and checking the index on my own, which seems easier and much convenient for me:</p>
  
  <pre><code>if (i &lt; v.size())
      v[i] = 2;
  </code></pre>
  
  <p>So my question is:<br>
  <strong>What are advantages of using <a href="http://www.cplusplus.com/reference/stl/vector/at/" rel="noreferrer">vector::at</a> over <a href="http://www.cplusplus.com/reference/stl/vector/operator%5B%5D/" rel="noreferrer">vector::operator[]</a> ?</strong><br>
  <strong>When should I use <a href="http://www.cplusplus.com/reference/stl/vector/at/" rel="noreferrer">vector::at</a> rather than <a href="http://www.cplusplus.com/reference/stl/vector/size/" rel="noreferrer">vector::size</a> + <a href="http://www.cplusplus.com/reference/stl/vector/operator%5B%5D/" rel="noreferrer">vector::operator[]</a> ?</strong></p>