21 Oct 2008 cinamod   » (Master)

Anyone know how to fix this?

Trying to port some C++ code to Visual Studio 2005. It works fine with VS 2003 and G++. Keep yer snarky comments to yourselves :)

The C++ Standard Template Library defines a nice set of algorithms in its <algorithm> header. One of these is std::lower_bound(), which is basically a bsearch. Its prototype is:

lower_bound(iterator begin, iterator end, value_type value, predicate_type predicate)

predicate_type's rules are pretty simple: it's just a less-than operator. For instances of the specified types T1 and T2, it returns true if "t1 < t2" and false otherwise.

In my case, my iterated contents are a complex type, and the value type is an int. There is no requirement that T1 and T2 be of the same type. I define the predicate as follows:

int my_pred(const ComplexType& v1, int v2)
  return v1.field < v2;

In a lame attempt to be helpful, Microsoft checks that if "a" isn't less-than "b", then "b" shouldn't be less-than "a". In doing so, it assumes that the _Left and _Right types are interchangeable as far as the predicate _Pred is concerned, thus screwing me (and more importantly, the C++ standard) royally:

	if (!_Pred(_Left, _Right))
		return (false);
	else if (_Pred(_Right, _Left))
		_DEBUG_ERROR2("invalid operator<", _Where, _Line);

Any thoughts?


Thanks, Hub. I used a functor class. It needed 3 functors:

(type, int), (int, type) and (type, type)

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!