什么叫Strict weak ordering
http://en.wikipedia.org/wiki/Strict_weak_ordering
我要用stl的sort,自己写了个自己类型的compare函数
但一运行就崩错
template<class _Pr, class _Ty1, class _Ty2> inline
bool __CLRCALL_OR_CDECL _Debug_lt_pred(_Pr _Pred, const _Ty1& _Left, const _Ty2& _Right,
const wchar_t *_Where, unsigned int _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<", _Where, _Line);
return (true);
}
出错是会进入到stl算法文件的这里面。具体是会进入
_DEBUG_ERROR2("invalid operator<", _Where, _Line);
这一行。
可我研究了半天,觉得这个逻辑不合理啊。
如果(左右相等)
{
返回
}否则如果(右左不相等)
{
错误
}
我觉得,我怎么都会进入这个错误啊。反正我现在是头疼的不行,如果哪儿写错了,说错了,请担待
[解决办法]
严格弱排序,看下这个链接吧:
http://wxiong1987.blog.sohu.com/56606905.html
[解决办法]
STL里面要严格定义<操作符的。不能莫能两可的。因为这个>,==操作都是利用<来得到的。