From 0e46762962d93b529aa6db827952eae5ded181a7 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sun, 29 Sep 2013 07:43:31 -0700 Subject: [PATCH] Add hasher functors for IPEndpoint --- beast/net/IPEndpoint.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/beast/net/IPEndpoint.h b/beast/net/IPEndpoint.h index b3f87cb0c..7040cff24 100644 --- a/beast/net/IPEndpoint.h +++ b/beast/net/IPEndpoint.h @@ -144,6 +144,14 @@ public: operator std::string () const; /** @} */ + struct hasher + { + std::size_t operator() (V4 const& v) const + { + return v.value; + } + }; + /** The value as a 32 bit unsigned. */ uint32 value; }; @@ -195,6 +203,14 @@ public: return to_string(); } /** @} */ + + struct hasher + { + std::size_t operator() (V6 const&) const + { + return 0; + } + }; }; //-------------------------------------------------------------------------- @@ -286,6 +302,20 @@ public: operator std::string () const; /** @} */ + struct hasher + { + std::size_t operator() (IPEndpoint const& value) const + { + std::size_t hash (0); + if (value.isV4()) + hash = V4::hasher() (value.v4()); + else if (value.isV6()) + hash = V6::hasher() (value.v6()); + hash += value.port(); + return hash; + } + }; + private: Type m_type; uint16 m_port;