title: C++11: `error: expected primary-expression before ‘)’ token in code` for line sweep to find closest pair
body: <p>This is an attempted O(NlogN) solution to the <a href="https://uva.onlinejudge.org/index.php?option=onlinejudge&amp;Itemid=99999999&amp;page=show_problem&amp;category=&amp;problem=1186&amp;mosmsg=Submission+received+with+ID+17697249" rel="nofollow">closest pair problem</a>, written in C++11. I used <a href="http://codeforces.com/blog/entry/22175" rel="nofollow">std::complex for geometry</a>. The comparators may be confusing, to the explain: <code>cmp</code> initially sorts the points by x and then y, and <code>compare_y</code> sorts the points in the <a href="http://www.cs.mcgill.ca/~cs251/ClosestPair/ClosestPairPS.html" rel="nofollow">bounding box</a> by y value.</p>
  
  <p>The following are the errors I get, followed by my code.</p>
  
  <pre><code>cp.cpp: In function ‘int main()’:
  cp.cpp:49:95: error: expected primary-expression before ‘)’ token
                   for (set&lt;point&gt;::iterator it = s.lower_bound(s.begin(), s.end(), t1, compare_y); it &lt; s.upper_bound(s.begin(), s.end(), t2, compare_y); ++it) {
                                                                                                 ^
  cp.cpp:49:150: error: expected primary-expression before ‘)’ token
                   for (set&lt;point&gt;::iterator it = s.lower_bound(s.begin(), s.end(), t1, compare_y); it &lt; s.upper_bound(s.begin(), s.end(), t2, compare_y); ++it) {
  </code></pre>
  
  <p><code></code></p>
  
  <pre><code>#include &lt;bits/stdc++.h&gt;
  using namespace std;
  
  const double EPS = 1e-9;
  
  // define x, y as real(), imag()
  typedef complex&lt;double&gt; point;
  #define x real()
  #define y imag()
  
  bool cmp(point a, point b) {
      if (a.x &lt; b.x) return true;
      if (a.x - b.x &lt; EPS &amp;&amp; a.y &lt; b.y) return true;
      return false;
  }
  
  struct compare_y {
      bool operator() (const point&amp; lhs, const point&amp; rhs) const{
          if (lhs.y &lt; rhs.y) return true;
      }
  };
  
  int main() {
      int n;
      while (scanf("%d", &amp;n) &amp;&amp; n != 0) {
  
          vector&lt;point&gt; coord;
          for (int i=0; i&lt;n; ++i) {
              double xi, yi;
              scanf("%lf%lf", &amp;xi, &amp;yi);
              point t(xi, yi);
              coord.push_back(t);
          }
          sort(coord.begin(), coord.end(), cmp);
  
          double h = 10000000;
          set&lt;point, compare_y&gt; s;
          s.insert(coord[0]);
          for (int i=1; i&lt;n; ++i) {
  
              for (auto pt:s) {
                  if (abs(pt-coord[i])+EPS &gt; h) { // bound by x
                      s.erase(pt);
                  }
              }
              point t1 = coord[i]; t1.imag(t1.y - h);
              point t2 = coord[i]; t2.imag(t2.y + h);
              for (set&lt;point&gt;::iterator it = s.lower_bound(s.begin(), s.end(), t1, compare_y); it &lt; s.upper_bound(s.begin(), s.end(), t2, compare_y); ++it) {
                  h = min(h, abs(*it-coord[i]));
              }
  
  
              s.insert(coord[i]);
          }
          if (h + EPS &gt;= 10000)
              printf("INFINITY\n");
          else
              printf("%.4lf\n", h);
  
      }
  }
  </code></pre>