Hi,
I want a user defined key for tr1 unordered_map.
My classes are,
template<typena me T>
struct work{
int count;
work(int count) : count(count){}
};
template<typena me W>
class worker{
public:
typedef worker<Wself_ty pe;
worker(W& w,int pos) : w_(&w),pos_(pos ){}
bool operator== (const self_type& other) const {
assert(w_ == other.w_);
return pos_ == other.pos_;
}
private:
W* w_;
int pos_;
friend std::size_t hash(const self_type& self){
return self.pos_ + w_->count;
}
};
and want to have worker class as key to map.
so calling is,
typedef work<intWORK;
typedef worker<WORKWORK ER;
WORK w(2);
WORKER w1(w,1);
WORKER w2(w,2);
WORKER w3(w,3);
unordered_map<W ORKER,intm;
m.insert(std::m ake_pair(w1,5)) ;
i have == op for worker.and either declaring a hash_value or hash
function is not working.
how can i do it?
thanks
abir
I want a user defined key for tr1 unordered_map.
My classes are,
template<typena me T>
struct work{
int count;
work(int count) : count(count){}
};
template<typena me W>
class worker{
public:
typedef worker<Wself_ty pe;
worker(W& w,int pos) : w_(&w),pos_(pos ){}
bool operator== (const self_type& other) const {
assert(w_ == other.w_);
return pos_ == other.pos_;
}
private:
W* w_;
int pos_;
friend std::size_t hash(const self_type& self){
return self.pos_ + w_->count;
}
};
and want to have worker class as key to map.
so calling is,
typedef work<intWORK;
typedef worker<WORKWORK ER;
WORK w(2);
WORKER w1(w,1);
WORKER w2(w,2);
WORKER w3(w,3);
unordered_map<W ORKER,intm;
m.insert(std::m ake_pair(w1,5)) ;
i have == op for worker.and either declaring a hash_value or hash
function is not working.
how can i do it?
thanks
abir
Comment