21 Oct 2008 redi   » (Master)

cinamod, the simplest solution is to add an overload with the parameters reversed. That's easy if you use a function object instead of a function pointer:

  
struct my_pred
{
  bool operator()(const ComplexType& v1, int v2) const
  {  return v1.field < v2; }
  bool operator()(int v1, const ComplexType& v2) const
  {  return v1 < v2.field;  }
};
...
lower_bound(begin, end, val, my_pred());

What MSVC is doing is not unreasonable, lower_bound requires a StrictWeakOrdering and one of the properties of a strict weak ordering is anti-symmetry. It's not possible to verify your predicate is antisymmetric if the order of the argument types matters.

Also, see the definition of equivalence used by the STL. Your predicate makes it impossible to test for equivalence.

I'm working on a short article about StrictWeakOrderings, which I'll post here when it's ready.

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!