为了保证 boost 库版本的代码兼容性,这是为了在多个平台上面跨平台编译的兼容性,所以我们通常需要去兼容打上这些补丁。
namespace std {
#if BOOST_VERSION < 107600
template <>
struct hash<boost::asio::ip::address_v4> {
public:
std::size_t operator()(const boost::asio::ip::address_v4& addr) const noexcept {
return std::hash<unsigned int>()(addr.to_uint());
}
};
template <>
struct hash<boost::asio::ip::address_v6> {
public:
std::size_t operator()(const boost::asio::ip::address_v6& addr) const noexcept {
const boost::asio::ip::address_v6::bytes_type bytes = addr.to_bytes();
std::size_t result = static_cast<std::size_t>(addr.scope_id());
combine_4_bytes(result, &bytes[0]);
combine_4_bytes(result, &bytes[4]);
combine_4_bytes(result, &bytes[8]);
combine_4_bytes(result, &bytes[12]);