title: std vector does not throw out_of_range exception when accessing uninitialized elements
body: <p>I read this tutorial</p>
  <p><a href="https://www.codeguru.com/cpp/cpp/cpp_mfc/stl/article.php/c4027/C-Tutorial-A-Beginners-Guide-to-stdvector-Part-1.htm" rel="nofollow noreferrer">std::vector beginners tutorial</a></p>
  <p>and also saw this question:</p>
  <p><a href="https://stackoverflow.com/q/29952941/1971003">similar tpoic question</a></p>
  <p>Yet, when I run my simple example I did not see the excepted results, which are --&gt; an <code>std::out_of_range</code> exception is NOT thrown.</p>
  <p>Did I misunderstand here something ?</p>
  <p>The sample code I run is the following (the code run and terminates successfully, i.e.- no exceptions thrown):</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  class MyObjNoDefualtCtor
  {
  public:
      MyObjNoDefualtCtor(int a) : m_a(a)
      {
          cout &lt;&lt; &quot;MyObjNoDefualtCtor::MyObjNoDefualtCtor - setting m_a to:&quot; &lt;&lt; m_a &lt;&lt; endl;
      }
  
      MyObjNoDefualtCtor(const MyObjNoDefualtCtor&amp; other) : m_a(other.m_a)
      {
          cout &lt;&lt; &quot;MyObjNoDefualtCtor::copy_ctor - setting m_a to:&quot; &lt;&lt; m_a &lt;&lt; endl;
      }
  
      ~MyObjNoDefualtCtor()
      {
          cout &lt;&lt; &quot;MyObjNoDefualtCtor::~MyObjNoDefualtCtor - address is&quot; &lt;&lt; this &lt;&lt; endl;
      }
  
      // just to be sure - explicitly disable the defualt ctor
      MyObjNoDefualtCtor() = delete;
  
      int m_a;
  };
  
  
  int main(int argc, char** argv)
  {
      // create a vector and reserve 10 int's for it
      // NOTE: no insertion (of any type) has been made into the vector.
      vector&lt;int&gt; vec1;
      vec1.reserve(10);   
  
      // try to access the first element - due to the fact that I did not inserted NOT even a single 
      // element to the vector, I would except here an exception to be thrown.
      size_t index = 0;
      cout &lt;&lt; &quot;vec1[&quot; &lt;&lt; index &lt;&lt; &quot;]:&quot; &lt;&lt; vec1[index] &lt;&lt; endl;
  
      // now try to access the last element - here as well: due to the fact that I did not inserted NOT even a single 
      // element to the vector, I would excpet here an excpetion to be thrown.
      index = 9;
      cout &lt;&lt; &quot;vec1[&quot; &lt;&lt; index &lt;&lt; &quot;]:&quot; &lt;&lt; vec1[index] &lt;&lt; endl;
  
      // same thing goes for user defined type (MyObjNoDefualtCtor) as well
      vector&lt;MyObjNoDefualtCtor&gt; vec2;
      vec2.reserve(10);   
  
      // try to access the first element -  due to the fact that I did not inserted NOT even a single 
      // element to the vector, I would except here an exception to be thrown.
      index = 0;
      cout &lt;&lt; &quot;vec2[&quot; &lt;&lt; index &lt;&lt; &quot;]:&quot; &lt;&lt; vec2[index].m_a &lt;&lt; endl;
  
      // now try to access the last element - here as well: due to the fact that I did not inserted NOT even a single 
      // element to the vector, I would except here an exception to be thrown.
      index = 9;
      cout &lt;&lt; &quot;vec2[&quot; &lt;&lt; index &lt;&lt; &quot;]:&quot; &lt;&lt; vec2[index].m_a &lt;&lt; endl;
  
      return 0;   
  }
  </code></pre>
  <p>Notes:</p>
  <p>The sample code is compiled with <em><strong>-std=c++11</strong></em> option.</p>
  <p>Compiler version is g++ 5.4 (on my Ubuntu 16.04 machine).</p>
  <p>Thanks,</p>
  <p>Guy.</p>