我爱Aspx >> VC.Net >> Effective STL: Item 21:永远让比较函数对相同元素返回false const string*, // from page 89. Beware,
bool> { // this code is flawed!
bool operator()(const string *ps1, const string *ps2) const
{
return !( *ps1 < *ps2); // just negate the old test;
} // this is incorrect!
};
想法是通过将比较函数内部结果取反来反序。很不幸,取反“<”不会给你(你所期望的)“>”,它给你的是“>=”。而你现在知道,因为“>=”将对相同的元素返回true,对关联容器,它不是一个有效的比较函数。
你真正需要的比较类型是这个:
struct StringPtrGreater: // this is a valid
public binary_function<const string*, // comparison type for
const string*, // associative containers
bool> {
bool operator()(const string *ps1, const string *ps2) const
{
return *ps2 < *ps1; // return whether *ps2
获取系统当前打开的端口(tcp。u..[05-21]
实战DeviceIoControl 之六:访问..[05-21]
By value? Or by reference?[05-21]
一个计算万年历的简单程序[05-21]
一个计算万年历的简单程序[05-21]
获取远程网卡MAC地址。[05-21]
获取远程网卡MAC地址。[05-21]
随机数的检验及发生[05-21]
关于VC代码的编写和调试(二)[05-21]
剖析VC中的文件操作[05-21]