Boost.Unordered: custom hasher
Hello all, for using the unordered_set with a user defined class one can define a custom hasher. There seems to be the following options: - overide boost::hash_value - write ur own custom hash functor Both options have then an external hash function. I was more thinking about using a member function as hasher (e.g. like GetHashCode). A supporting class would be then: template <typename T, typename RetType, RetType (T::*pmf)() const> struct unary_function_mf : std::unary_function<T, RetType> { RetType operator()(const T& r) const { return (r.*pmf)(); } }; which makes specifying an unordered_set easier: boost::unordered_set<Person, unary_function_mf<Person, size_t, &Person::GetHashCode> > uset2; My questions: 1) is this correct c++ 2) does something similar exist in Boost (Boost.Function and Bind doesn't seem to support his) 3) is there an advantage of using a free function over functor? The free function has at least one advantage, that it also works with the std::pair hasher.
participants (1)
-
gast128