Thursday, January 3, 2008

C++ operator< implementation

class Foo
{
  int         a;
  float       b;
  std::string c;

  /* ... */

  bool operator<(const Foo& foo) const
  {
     if (a != foo.a) return a < foo.a;
     if (b != foo.b) return b < foo.b;
     if (c != foo.c) return c < foo.c;
     return false;
  }
}

No comments: