title: Non consistent if statment in C++
body: <p>So I have a simple code that behaves differently in 2 cases</p>
  <p>In the first case, when I write it with <code>(vecthread.size() - 5)</code> inside the if statement it will go in the if statement and then throws an error &quot;out_of_range&quot;. He goes in even tho the vector was empty.</p>
  <pre><code>vector&lt;thread*&gt; vecthread;
  for (int i = 0; i &lt; max; i++)
      {
          //int temp = vecthread.size() - 5;
          if((vecthread.size() - 5) &gt; 0) {
             ...
          }
          thread* newThread = new thread(forj, max, mkg, x, &amp;counter, &amp;countermax);
          vecthread.push_back(newThread);
      }
  </code></pre>
  <p>But if i use the <code>temp</code> int here like so:</p>
  <pre><code>vector&lt;thread*&gt; vecthread;
  for (int i = 0; i &lt; max; i++)
      {
          int temp = vecthread.size() - 5;
          if(temp &gt; 0) {
             ...
          }
          thread* newThread = new thread(forj, max, mkg, x, &amp;counter, &amp;countermax);
          vecthread.push_back(newThread);
      }
  </code></pre>
  <p>It will work correctly and not enter the if statement.
  Can anyone explain what's happening here?
  I don't wanna pollute my code with those unnessesary temp values if I can avoid it</p>
  <p>Down below the full code:</p>
  <pre><code>void dspi() {
      double pi = 2 * acos(0.0);
      o.open(&quot;pi.dat&quot;);
      int max = 100;
      int max2 = pow(max,2);
      vector&lt;int&gt; lfg {1};
      vector&lt;thread*&gt; vecthread;
      calculatorlfg(max, &amp;lfg); //calculates pseudorandom numbers using the lagged Fibonacci-Generator method and writes them into lfg
      int counter = 0;
      int countermax = 0;
      for (int i = 0; i &lt; max; i++)
      {
          double x = betrag(lfg.at(i)/(pow(2,31)-1));
          int bla = vecthread.size() - 5;
          if((vecthread.size() - 5) &gt; 0) {
              vecthread.at(vecthread.size()-5)-&gt;join();
              double temp = double(counter)/double(countermax);
              o &lt;&lt; counter &lt;&lt; &quot;\t&quot; &lt;&lt; countermax&lt;&lt; &quot;\t&quot; &lt;&lt; temp &lt;&lt; &quot;\t&quot; &lt;&lt; temp - pi/4 &lt;&lt; endl;
              cout &lt;&lt; countermax &lt;&lt; &quot;/&quot; &lt;&lt; max2 &lt;&lt; endl;
          }
          thread* newThread = new thread(forj, max, mkg, x, &amp;counter, &amp;countermax);
          vecthread.push_back(newThread);
      }
      o.close();
  }
  </code></pre>