title: all_of function to check condition in all elements of part of an array
body: <p>The following code checks if all elements in the declared array are odd numbers.</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;     // std::cout
  #include &lt;algorithm&gt;    // std::all_of
  #include &lt;array&gt;        // std::array
  
  int main () {
      std::array&lt;int,8&gt; foo = {3,5,7,11,13,17,19,23};
  
      if ( std::all_of(foo.begin(), foo.end(), [](int i){return i%2;}) )
          std::cout &lt;&lt; "All the elements are odd numbers.\n";
  
      return 0;
  }
  </code></pre>
  
  <p>(Sample taken from <a href="http://www.cplusplus.com/reference/algorithm/all_of" rel="nofollow">http://www.cplusplus.com/reference/algorithm/all_of</a>)</p>
  
  <p>I would like to check if <strong>all elements in the declared array starting from <code>foo[2]</code></strong> are odd numbers.</p>
  
  <p>Replacing <code>foo.begin()</code> with <code>foo[2]</code> does not work. I've tried many other things to make this work, all very basic (very basic C++ user here), without success. I do not want to resize the array for achieving this. </p>
  
  <p>Ultimately what I'm looking for is having a loop where a condition is checked for on <strong>every</strong> element of part of an array, just as the <code>for</code> loop checks for a condition on <strong>any</strong> element of part of an array. This is relatively easy to achieve in R, and I'm hoping it may be equally easy to achieve in C++.</p>