Pegah
Pegah

Reputation: 682

defining a hash set with a compare function

I am trying to do a very simple task of defining a new type of hash set which has a compare function as well.

using namespace std;
#include <iostream>
#include <ext/hash_set>
#include <hash_set>
#include <functional>
#include <hash_compare>
typedef __gnu_cxx::hash_set<int, hash_compare<int, less<int> > > hashcomp;

int main(int argc, char *  const argv[]) {

}

Error: hash_compare is not defined (line 7)
Error: expected unqualified-id before ">" token (line 7)
Error: template argument 2 is invalid. (line 7)

Upvotes: 0

Views: 656

Answers (2)

James Kanze
James Kanze

Reputation: 154017

Your requirements are contradictory. A hash table has a random order, by definition.

Upvotes: 0

Sarfaraz Nawaz
Sarfaraz Nawaz

Reputation: 361692

Seeing the error, I guess you haven't included <functional> as you're using std::less<int> in your code. I'm assuming that less<int> in your code is actually std::less<int>.

EDIT:

The error message clearly says

Error: hash_compare is not defined.

What else do you want? Include the header file which defines hash_compare.

Upvotes: 1

Related Questions