title: STL function for determining if distance is within `n`
body: <p>Let's say I have some container <code>C</code> of elements and two iterators <code>it1</code> and <code>it2</code> (<code>it1 &lt;= it2</code> wlog) . If <code>std::distance(it1, it2) &lt;= n</code>, I want to perform some action <code>f</code>. Furthermore, <code>it1</code> and <code>it2</code> are changing (possibly randomly) within a loop and I need to check the distance with every iteration.</p>
  
  <p>If <code>C</code> is very large and not random-access, calling <code>std::distance</code> on every iteration is extremely wasteful, since we only need to determine if the distance is less than some <code>n</code>. It's fairly trivial to write some function which would take two iterators and an integer and return whether or not the distance between the two is within the provided integer, however I'm wondering if there is some way to use the STL to accomplish this task.  </p>
  
  <p>Essentially, what I am looking for is an STL version of the function below:</p>
  
  <pre><code>template &lt;class ForwardIt&gt;
  bool is_within(ForwardIt it1, ForwardIt it2, int n) {
    int i = 0;
    while (i++ &lt;= n)
      if (it1++ == it2) return true;
    return false
  }
  </code></pre>