Ensure that hash_append will never throw

Conflicts:
	src/beast/beast/net/IPAddress.h
This commit is contained in:
Nik Bougalis
2015-01-07 07:49:03 -08:00
committed by Vinnie Falco
parent e8c07717fc
commit f78269b02d
2 changed files with 11 additions and 9 deletions

View File

@@ -24,8 +24,9 @@
#include <beast/net/IPAddressV6.h>
#include <beast/hash/hash_append.h>
#include <beast/hash/uhash.h>
#include <beast/utility/noexcept.h>
#include <boost/functional/hash.hpp>
#include <cassert>
#include <cstdint>
#include <ios>
#include <string>
@@ -102,14 +103,14 @@ public:
/** Returns `true` if this address represents an IPv4 address. */
bool
is_v4 () const
is_v4 () const noexcept
{
return m_type == ipv4;
}
/** Returns `true` if this address represents an IPv6 address. */
bool
is_v6() const
is_v6() const noexcept
{
return m_type == ipv6;
}
@@ -121,12 +122,11 @@ public:
AddressV4 const&
to_v4 () const
{
if (m_type != ipv4)
if (!is_v4 ())
throw std::bad_cast();
return m_v4;
}
/** Returns the IPv6 address.
Precondition:
is_v6() == `true`
@@ -134,7 +134,7 @@ public:
AddressV6 const&
to_v6 () const
{
if (m_type != ipv6)
if (!is_v6 ())
throw std::bad_cast();
return m_v6;
}
@@ -142,13 +142,15 @@ public:
template <class Hasher>
friend
void
hash_append(Hasher& h, Address const& addr)
hash_append(Hasher& h, Address const& addr) noexcept
{
using beast::hash_append;
if (addr.is_v4 ())
hash_append(h, addr.to_v4 ());
else
else if (addr.is_v6 ())
hash_append(h, addr.to_v6 ());
else
assert (false);
}
/** Arithmetic comparison. */

View File

@@ -140,7 +140,7 @@ struct AddressV4
Proxy <true> operator[] (std::size_t index) const;
Proxy <false> operator[] (std::size_t index);
/** @{ */
/** @} */
/** The value as a 32 bit unsigned. */
std::uint32_t value;