title: set.lower_bound function with pairs
body: <p>I learned that set.lower_bound(key) function returns the value from the set as close as possible to the key, i was wondering how it works when the key passed is a pair(say x,y coordinates of a point), i.e the set contains pairs. </p>
  
  <p>i encountered this in the following code snippet</p>
  
  <pre><code> int compare(pairll a, pairll b)
  { 
          return a.px&lt;b.px; 
  }
  double closest_pair(pairll pnts[],int n)
  {
          sort(pnts,pnts+n,compare);
          double best=INF;
          set&lt;pairll&gt; box;
          box.insert(pnts[0]);
          int left = 0;
          for (int i=1;i&lt;n;++i)
          {
              while (left&lt;i &amp;&amp; pnts[i].px-pnts[left].px &gt; best)
                  box.erase(pnts[left++]);
              for(typeof(box.begin()) it=box.lower_bound(make_pair(pnts[i].py-best, pnts[i].px-best));it!=box.end() &amp;&amp; pnts[i].py+best&gt;=it-&gt;py;it++)
                  best = min(best, sqrt(pow(pnts[i].py - it-&gt;py, 2.0)+pow(pnts[i].px - it-&gt;px, 2.0)));
              box.insert(pnts[i]);
          }
          return best;
  }
  </code></pre>