Add hash function to URL

This commit is contained in:
Vinnie Falco
2013-10-25 15:36:24 -07:00
parent dc591f8943
commit 7bae496257
2 changed files with 39 additions and 1 deletions

View File

@@ -103,6 +103,36 @@ private:
String m_userinfo;
};
/** URL comparisons. */
/** @{ */
inline bool operator== (URL const& lhs, URL const& rhs) { return lhs.full() == rhs.full(); }
inline bool operator!= (URL const& lhs, URL const& rhs) { return ! (lhs.full() == rhs.full()); }
inline bool operator< (URL const& lhs, URL const& rhs) { return lhs.full() < rhs.full(); }
inline bool operator> (URL const& lhs, URL const& rhs) { return rhs.full() < lhs.full(); }
inline bool operator<= (URL const& lhs, URL const& rhs) { return ! (rhs.full() < lhs.full()); }
inline bool operator>= (URL const& lhs, URL const& rhs) { return ! (lhs.full() < rhs.full()); }
/** @} */
extern std::size_t hash_value (beast::URL const& url);
}
//------------------------------------------------------------------------------
namespace std {
template <typename T>
struct hash;
template <>
struct hash <beast::URL>
{
std::size_t operator() (beast::URL const& v) const
{ return beast::hash_value (v); }
};
}
//------------------------------------------------------------------------------
#endif

View File

@@ -25,7 +25,6 @@ URL::URL ()
: m_port (0)
{
}
URL::URL (
String scheme_,
String host_,
@@ -154,5 +153,14 @@ String URL::full () const
return s;
}
//------------------------------------------------------------------------------
std::size_t hash_value (URL const& v)
{
return std::size_t (v.full().hash());
}
}
// boost::hash support