在用stl的sort模板函数的时候遇到一个运行时错误,觉得很诡异,搜索了一下,原来VC05以后的版本会运行时检查比较函数是否为strict weak ordering,由此顺便了解了下strict weak ordering。而VC的运行时检查机制也耐人寻味。此为文章链接:
http://hi.baidu.com/haochaoqing/item/00b40cf2b8c4efc0a835a255
http://support.microsoft.com/kb/949171
把第二篇的内容贴出来如下:
Action
Sort any STL collection using stable_sort() or sort() with duplicate items using the following custom predicate
bool CustPredicate (int elem1, int elem2 )
{
if(elem1 > elem2)
return true;
if (elem1 < elem2)
return false;
return true;
}
bool CustPredicate (int elem1, int elem2 )
{
if(elem1 > elem2)
return true;
if (elem1 < elem2)
return false;
return true;
}
Result