在用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;
}

Result

 

相关文章:

  • 2021-10-25
  • 2022-02-18
  • 2021-11-17
  • 2022-12-23
  • 2021-09-11
  • 2022-03-08
  • 2022-12-23
  • 2021-08-29
猜你喜欢
  • 2022-12-23
  • 2021-12-15
  • 2022-12-23
  • 2022-12-23
  • 2021-11-24
  • 2021-11-19
  • 2022-12-23
相关资源
相似解决方案