title: using std::equal_range to search the vector within some ranges
body: <p>I have a std::vector with the element as pair and need to find all the elements with the first component within some ranges, for example, to find all elements such that abs(value of first component - reference)&lt;0.01, I got the code from other post that</p>
  
  <pre><code>bool comp(pair&lt;double, double&gt; v1, pair&lt;double, double&gt; v2)
  {
    return (abs(v1.first-v2.first)&lt;0.001);
  }
  
  vector&lt; pair&lt;double, double&gt; data;
  for (int i=0; i&lt;10; i++)
  {
    double a, b; 
    // a &amp; b are initialized randomly (the code was not shown here)
    data.push_back(make_pair(a, b));
  }
  
  // we sort the vector here based on the pair.first (code not shown)
  
  // compval is used as reference value, i.e. we are going to find all elements with     abs(pair.first-ref.first)&lt;0.01
  pair&lt;double, double&gt; ref
  ref.first = 0.5;
  ref.second = 0.5;
  
  std::pair&lt; vector&lt; pair&lt;double, double&gt;::iterator, vector&lt; pair&lt;double, double&gt;::iterator&gt; const range = std::equal_range(data.begin(), data.end(), ref, comp);
  </code></pre>
  
  <p>but if you look at all elements given by the resulting ranges, you will see that all elements of the data instead of the one satisfying abs(pair.first-ref.first)&lt;0.01 will be returned. Is that anything I miss in the code? Thanks.</p>