title: How to check for std::vector out of range access
body: <p>[Found a doublicate here: <a href="https://stackoverflow.com/questions/7497637/c-detect-out-of-range-access">C++ - detect out-of-range access</a> ]</p>
  
  <p>If I have a programm with "out of range vector access", like this:</p>
  
  <pre><code>  std::vector&lt;int&gt; A(2);
    ...
    A[10] = 3;
  </code></pre>
  
  <p><strong>Do I have a way to find this error for sure?</strong>
  I mean something like compile in debug mode and see whether some assertion stops the execution.</p>
  
  <p>Up to now I have checked it by my own. But may be I don't have to write additional code?</p>
  
  <hr>
  
  <p>P.S. I checked assertion of course. It doesn't called. </p>
  
  <p>With this program:</p>
  
  <pre><code>#include &lt;vector&gt;
  
  int main() {
    std::vector&lt;int&gt; A(2);
    A[10] = 3;
    return 0;
  }
  </code></pre>
  
  <p>compiled by</p>
  
  <pre><code>g++ 1.cpp -O0; ./a.out
  </code></pre>
  
  <p>So it looks like std doesn't have assertion in the code, I can't stop wonder why they don't make such a simple check.</p>