hi,
this code compiled using visual studio. Have changed the line
const size_t i= __gnu_cxx::hash(x);
from

const size_t i=stdext::hash_value(x);

so that it would compile using gcc. However I am getting an error message as shown below.
Any suggestions appreciated. Thx

template<class X, class Pred= less<X> >
class Hash{
private:
	Pred comp;
public:
	enum{bucket_size = 4, min_buckets = 8};	
	Hash() : comp(){ }
	Hash(Pred p) : comp(p){ }
	size_t operator()(const X& x) const{
		const size_t i= __gnu_cxx::hash(x);
		return 16807U*(i%127773U)+(95329304U-2836U*(i/127773U));
	}
	
};

error: expected initializer before __gnu_cxx

ideally, do not use the (now deprecated) functionality in namespace __gnu_cxx . they have been superceded by tr1 in c++0x.
use -std=c++0x (gcc 4.3) , std::tr1 (gcc4.2) or boost::tr1 (earlier versions).

the error is because __gnu_cxx::hash<> is a struct (function object); not a function. if you have to use it, use it this way

#include <functional>
#include <ext/hash_fun.h>
using namespace std ;

template<class X, class Pred= less<X> >
class Hash{
private:
  Pred comp;
public:
  enum{bucket_size = 4, min_buckets = 8}; 
  Hash() : comp(){ }
  Hash(Pred p) : comp(p){ }
  size_t operator()(const X& x) const{
    const size_t i= __gnu_cxx::hash<X> [B]()[/B] (x);
    return 16807U*(i%127773U)+(95329304U-2836U*(i/127773U));
  }
  
};

Thank you thank you!! That worked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.