我有以下代码:
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <map>
using namespace std;
struct vals
{
int cods[5];
int sz;
};
struct myComp
{
bool operator()(vals A, vals B) const
{
int i=0;
while(A.cods[i]==B.cods[i] && i<A.sz)
i++;
if(i==A.sz)
return false; //<-----this is the value im changing..
else
return A.cods[i] > B.cods[i];
}
};
map< vals, int, myComp> Mp;
int main()
{
vals g, h;
g.sz=h.sz=3;
g.cods[0] = 12;
g.cods[1] = 22;
g.cods[2] = 32;
Mp.insert(pair< vals, int >(g,4));
Mp.insert(pair< vals, int >(g,7));
cout<<Mp.count(g)<<endl;
cout<<Mp.size()<<endl;
return 0;
}
现在,当声明Mp
为 map 并放入false
二进制谓词时.. 输出为: 1 1
Mp => map && binary predicate:true ==> output: 0 2
Mp => multimap && binary predicate:true ===> output: 0 2
Mp => multimap && binary predicate:false ===> output: 2 2
我认为谓词的返回值只是告诉stl
是否将一个元素放在它的前面或后面。但我不明白这对地图本身的大小有何影响。请对此有所了解。谢谢你。