I am trying to create a unordered_set
of list
of string
.
But I am stuck with this error:
/usr/include/c++/4.8/bits/hashtable_policy.h:1103:22: error: no match for call to '(const std::hash<std::list<std::basic_string<char> > >) (const std::list<std::basic_string<char> >&)'
I suspect, this is because STL doesn't have a hash function for list
of string
.
Creating a set
of the same type works, but I am worried about efficiency issues (insertion and look up times).
Is there any workaround for this? I don't want to implement a hash function for lists! But may be someone can suggest me some alternative ideas.
class MyClass {
private:
struct Hash : public std::unary_function< std::list<std::string> const& ls,
size_t> {
std::size_t operator()(std::list<std::string> const& ls) const;
};
typedef boost::unordered_set< std::list<std::string>, Hash > MyClassSet;
MyClassSet set_;
};
std::size_t MyClass::Hash::operator()(std::list<std::string> const& ls) const {
std::size_t seed = 0;
std::list<std::string>::iterator it = ls.begin();
while ( it != ls.end()) {
boost::hash_combine(seed, *it);
++it;
}
return seed;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.