title: Is it defined to provide an inverted range to C++ standard algorithms?
body: <p>Consider standard algorithms like, say, <code>std::for_each</code>.</p>
  
  <pre><code>template&lt;class InputIterator, class Function&gt;
  Function for_each(InputIterator first, InputIterator last, Function f);
  </code></pre>
  
  <p>As far as I can tell, there is actually no requirement placed on the <em>relative</em> states of the two <code>InputIterator</code> arguments.</p>
  
  <p>Does that mean that the following is technically valid? Or is it undefined? What can I realistically expect it to <em>do</em>?</p>
  
  <pre><code>std::vector&lt;int&gt; v{0,1,2,3,4};
  std::for_each(
     v.begin()+3,  // range [3,0)
     v.begin(),
     [](int){}
  );
  </code></pre>
  
  <p><a href="http://weegen.home.xs4all.nl/eelis/geordi/" rel="nofollow">geordi</a> tells me:</p>
  
  <blockquote>
    <p>error: function requires a valid iterator range [__first, __last). [+ 13 discarded lines]</p>
  </blockquote>
  
  <p>but I can't tell how compliant this debug diagnostic is.</p>
  
  <hr>
  
  <p>I came up with this question when trying to <em>pedantically</em> determine how explicit is defined the behaviour of the following:</p>
  
  <pre><code>std::vector&lt;int&gt; v; // &lt;-- empty
  std::for_each(      // &lt;-- total no-op? stated or just left to implication?
     v.begin(),
     v.end(),
     [](int){}
  );
  </code></pre>