dimanche 4 janvier 2015

Insert works with set but not with unordered_set

In the following piece of code:



#include<unordered_set>
#include<iostream>
#include<utility>
#include<string>
#include<set>

using namespace std;

int main()
{
set<pair<string, string> > g;
pair<string, string> tmp;
tmp.first="hello";
tmp.second="world";
g.insert(tmp);
}


if I change set<pair<string, string> > g; to unordered_set<pair<string, string> > g; I get the error while inserting the pair, like:



test1.cpp:15:14: note: candidate expects 2 arguments, 1 provided
g.insert(tmp);
^


is it something on the lines of "hash function can't be defined for a pair but only for basic data types"? If I'm wrong please correct me, else elaborate it. Thanks!


Aucun commentaire:

Enregistrer un commentaire