|
Boost Users : |
Subject: [Boost-users] [Unordered] template find() request
From: Kenneth Heafield (void_at_[hidden])
Date: 2009-03-08 17:07:09
Hello Boost,
Suppose I have a boost::unordered_set<std::string>. Now I want to
find() a const char *, std::string, or even a string without zero
termination (Google StringPiece). Converting these to std::string just
to do a lookup is wasteful. Instead, I want to provide functors like:
struct either_hash {
size_t operator()(const std::string &str) const {
return boost::hash_range(str.begin(), str.end());
}
size_t operator()(const char *str) const {
return boost::hash_range(str, str + std::strlen(str));
}
};
This raises the question: what is either_hash::argument_type ? But it
seems this is not used by boost::unordered_set . It should probably be
std::string to match the underlying hash table.
Would it make sense to change find() to template <class query_type>
const_iterator find(const query_type& q) const ?
For those familiar with Google StringPiece, one solution is using
boost::unordered_set<StringPiece>, but then I have to keep the
underlying strings somewhere outside the table. Further, a generalized
find is useful in other cases, but this was the easiest to explain.
Kenneth
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net