"The furthermost iterator i in the range [first, last] such that for any
iterator j in the range [first, i) the following corresponding
conditions hold: *j < value or comp(*j, value) != false"
from this I would assume the value parameter will only every appear as
the right-hand operand and never the left-hand one in the call to
operator<. Is this a bug in VCs STL or am I missing something?
#include <vector>
#include <algorithm>
struct A {
int val;
};
struct B {
int val;
};
bool operator<( const A &a, const B &b ) {
return a.val < b.val;
}
void func ( ) {
std::vector<A> vec;
B comp;
std::lower_bound ( vec.begin(), vec.end(), comp );
}
Thanks,
Michael
You missed the other bit:
Requires: Type T is LessThanComparable (20.1.2).
> from this I would assume the value parameter will only every appear as
> the right-hand operand and never the left-hand one in the call to
> operator<. Is this a bug in VCs STL or am I missing something?
The requirement says that t<u must compile for two values of type T, in
your case B. However, this requirement has been relaxed for the next
standard:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1905.pdf
The dinkumware debugging version does pre-condition checks (e.g. it
checks the requires clauses of the algorithms) to make sure you haven't
written anything non-standard.
Tom
Excellent summary, as always. But IIRC, the final version of V8
fixed this problem. (We made _Debug_lt a template with two parameters
instead of one.) To the OP: Are you using a beta or did this fix not
make the cut?
P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
The two-parameter form of _Debug_lt is in the RTM version of VC 2005. The
OP's code still does not compile using that version, however. The following
operators must be added to support all of the necessary comparisons:
bool operator<( const A &a, const A &a2 ) {
return a.val < a2.val;
}
bool operator<( const B &b, const A &a ) {
return b.val < b.val;
}
-cd
return b.val < a.val;
-cd