标签:iostream lang less 习惯 错误 http name result tran
#include <list>
#include <string>
#include <iostream>
using namespace std;
struct Info
{
int id;
string name;
bool operator<(const Info rh) const
{
return id <= rh.id;
//return id < rh.id;
}
};
void func()
{
list<Info> infos;
infos.push_back({1, "1"});
infos.push_back({3, "3"});
infos.push_back({3, "3"});
infos.push_back({2, "2"});
infos.sort();
}
output:
编译正常,运行崩溃
const auto _Result = static_cast<bool>(_Pred(_Left, _Right));
if (_Result)
{
_STL_VERIFY(!_Pred(_Right, _Left), "invalid comparator");
}
template<>
struct less<void>
{ // transparent functor for operator<
typedef int is_transparent;
template<class _Ty1,
class _Ty2>
constexpr auto operator()(_Ty1&& _Left, _Ty2&& _Right) const
-> decltype(static_cast<_Ty1&&>(_Left)
< static_cast<_Ty2&&>(_Right))
{ // transparently apply operator< to operands
return (static_cast<_Ty1&&>(_Left)
< static_cast<_Ty2&&>(_Right));
}
};
结论:
bool operator<(const Info rh) const
{
// return id <= rh.id;
return id < rh.id;
}
标签:iostream lang less 习惯 错误 http name result tran
原文地址:https://www.cnblogs.com/faithlocus/p/13404111.html