請問為什麼這段程式碼會輸出:8 8
#include <iostream>
#include <vector>
#include <set>
using namespace std;
struct cmp{
bool operator()(int a,int b){
return a==b;
}
};
int main()
{
vector<int> x{8,4,6,1,4,2,7,8,8,5,8,8};
set<int,cmp> y(x.begin(),x.end());
for(auto iter=y.begin();iter!=y.end();iter++){
cout<<*iter<<" ";
}
return 0;
}
我知道 set 自定義函式不能這樣用,但我還是好奇這個輸出的原因,根據等於的定義是:!comp(a, b) && !comp(b, a),那這個輸出應該要是:8 8 8 8 8 吧