template<class _Pr, class _Ty1, class _Ty2> inline
bool _Debug_lt_pred(_Pr _Pred,
const _Ty1& _Left, _Ty2& _Right,
_Dbfile_t _File, _Dbline_t _Line)
{ // test if _Pred(_Left, _Right) and _Pred is strict weak ordering
if (!_Pred(_Left, _Right))
return (false);
else if (_Pred(_Right, _Left))
_DEBUG_ERROR2("invalid operator<", _File, _Line);
return (true);
}
STL的所有有序容器 模板的 比较函数的定义,
都必须符合stict weak ordering的二元关系
既能比较出不等,也能比较出大小.
否则在key的比较的时候,执行到这里一定会在else if的分支报错
=========以下是STL文档的原话:
http://www.cplusplus.com/reference/map/map/
CompareA binary predicate that takes two element keys as arguments and returns a bool. The expression comp(a,b), where comp is an object of this type and a and b are key values, shall return true if a is considered to go before b in the strict weak ordering the function defines.
The map object uses this expression to determine both the order the elements follow in the container and whether two element keys are equivalent (by comparing them reflexively: they are equivalent if !comp(a,b) && !comp(b,a)). No two elements in a map container can have equivalent keys.
This can be a function pointer or a function object (see constructor for an example). This defaults to less<T>, which returns the same as applying the less-than operator (a<b).
Aliased as member type map::key_compare.
The STL algorithms for stable_sort ( ) and sort() require the binary predicate to be strict weak ordering.
For example:
· Strict: pred (X, X) is always false.
· Weak: If ! pred (X, Y) && !pred (Y, X), X==Y.
· Ordering: If pred (X, Y) && pred (Y, Z), then pred (X, Z).