mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Ensure that hash_append will never throw
Conflicts: src/beast/beast/net/IPAddress.h
This commit is contained in:
committed by
Vinnie Falco
parent
e8c07717fc
commit
f78269b02d
@@ -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. */
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user