Remove address_cast.
diff --git a/asio/include/asio/ip/address.hpp b/asio/include/asio/ip/address.hpp index d8068ba..733bbe4 100644 --- a/asio/include/asio/ip/address.hpp +++ b/asio/include/asio/ip/address.hpp
@@ -90,13 +90,11 @@ return type_ == ipv6; } -#if !defined(ASIO_NO_DEPRECATED) /// Get the address as an IP version 4 address. ASIO_DECL asio::ip::address_v4 to_v4() const; /// Get the address as an IP version 6 address. ASIO_DECL asio::ip::address_v6 to_v6() const; -#endif // !defined(ASIO_NO_DEPRECATED) /// Get the address as a string in dotted decimal format. ASIO_DECL std::string to_string() const; @@ -167,18 +165,6 @@ } private: - // Helper function to get the underlying IPv4 address. - friend asio::ip::address_v4 get_v4_helper(const address& a) - { - return a.ipv4_address_; - } - - // Helper function to get the underlying IPv4 address. - friend asio::ip::address_v6 get_v6_helper(const address& a) - { - return a.ipv6_address_; - } - // The type of the address. enum { ipv4, ipv6 } type_; @@ -219,99 +205,6 @@ ASIO_DECL address make_address( const std::string& str, asio::error_code& ec); -/** @defgroup address_cast asio::ip::address_cast - * - * @brief The asio::ip::address_cast function is used to convert between - * address types. - */ -/*@{*/ - -/// Cast a version-independent address to itself. -template <typename T> -inline T address_cast(const address& addr, - typename enable_if<is_same<T, address>::value>::type* = 0) -{ - return addr; -} - -/// Cast a version-independent address to an IPv4 address. -/** - * @throws bad_address_cast if @c a does not represent an IPv4 address. - */ -template <typename T> -inline T address_cast(const address& addr, - typename enable_if<is_same<T, address_v4>::value>::type* = 0) -{ - if (!addr.is_v4()) - { - bad_address_cast ex; - asio::detail::throw_exception(ex); - } - return get_v4_helper(addr); -} - -/// Cast a version-independent address to an IPv6 address. -/** - * @throws bad_address_cast if @c a does not represent an IPv6 address. - */ -template <typename T> -inline T address_cast(const address& addr, - typename enable_if<is_same<T, address_v6>::value>::type* = 0) -{ - if (!addr.is_v6()) - { - bad_address_cast ex; - asio::detail::throw_exception(ex); - } - return get_v6_helper(addr); -} - -/// Cast an IPv4 address to a version-independent address. -template <typename T> -inline T address_cast(const address_v4& addr, - typename enable_if<is_same<T, address>::value>::type* = 0) -{ - return address(addr); -} - -/// Cast an IPv4 address to itself. -template <typename T> -inline T address_cast(const address_v4& addr, - typename enable_if<is_same<T, address_v4>::value>::type* = 0) -{ - return addr; -} - -/// Cast from IPv4 to IPV6 address is not permitted. -template <typename T> -bad_address_cast address_cast(const address_v4&, - typename enable_if<is_same<T, address_v6>::value>::type* = 0) - ASIO_DELETED; - -/// Cast an IPv6 address to a version-independent address. -template <typename T> -inline T address_cast(const address_v6& addr, - typename enable_if<is_same<T, address>::value>::type* = 0) -{ - return address(addr); -} - -/// Cast an IPv6 address to itself. -template <typename T> -inline T address_cast(const address_v6& addr, - typename enable_if<is_same<T, address_v6>::value>::type* = 0) -{ - return addr; -} - -/// Cast from IPv6 to IPv4 address is not permitted. -template <typename T> -bad_address_cast address_cast(const address_v6&, - typename enable_if<is_same<T, address_v4>::value>::type* = 0) - ASIO_DELETED; - -/*@}*/ - #if !defined(ASIO_NO_IOSTREAM) /// Output an address as a string.
diff --git a/asio/include/asio/ip/detail/impl/endpoint.ipp b/asio/include/asio/ip/detail/impl/endpoint.ipp index dc3e6b3..ec477ae 100644 --- a/asio/include/asio/ip/detail/impl/endpoint.ipp +++ b/asio/include/asio/ip/detail/impl/endpoint.ipp
@@ -80,8 +80,7 @@ asio::detail::socket_ops::host_to_network_short(port_num); data_.v4.sin_addr.s_addr = asio::detail::socket_ops::host_to_network_long( - static_cast<asio::detail::u_long_type>( - address_cast<address_v4>(addr).to_ulong())); + addr.to_v4().to_ulong()); } else { @@ -89,7 +88,7 @@ data_.v6.sin6_port = asio::detail::socket_ops::host_to_network_short(port_num); data_.v6.sin6_flowinfo = 0; - asio::ip::address_v6 v6_addr = address_cast<address_v6>(addr); + asio::ip::address_v6 v6_addr = addr.to_v6(); asio::ip::address_v6::bytes_type bytes = v6_addr.to_bytes(); memcpy(data_.v6.sin6_addr.s6_addr, bytes.data(), 16); data_.v6.sin6_scope_id =
diff --git a/asio/include/asio/ip/detail/socket_option.hpp b/asio/include/asio/ip/detail/socket_option.hpp index a44e610..93a9017 100644 --- a/asio/include/asio/ip/detail/socket_option.hpp +++ b/asio/include/asio/ip/detail/socket_option.hpp
@@ -398,7 +398,7 @@ if (multicast_address.is_v6()) { using namespace std; // For memcpy. - address_v6 ipv6_address = address_cast<address_v6>(multicast_address); + address_v6 ipv6_address = multicast_address.to_v6(); address_v6::bytes_type bytes = ipv6_address.to_bytes(); memcpy(ipv6_value_.ipv6mr_multiaddr.s6_addr, bytes.data(), 16); ipv6_value_.ipv6mr_interface = ipv6_address.scope_id(); @@ -407,7 +407,7 @@ { ipv4_value_.imr_multiaddr.s_addr = asio::detail::socket_ops::host_to_network_long( - address_cast<address_v4>(multicast_address).to_ulong()); + multicast_address.to_v4().to_ulong()); ipv4_value_.imr_interface.s_addr = asio::detail::socket_ops::host_to_network_long( address_v4::any().to_ulong());
diff --git a/asio/include/asio/ip/impl/address.ipp b/asio/include/asio/ip/impl/address.ipp index 664c53d..694be60 100644 --- a/asio/include/asio/ip/impl/address.ipp +++ b/asio/include/asio/ip/impl/address.ipp
@@ -134,7 +134,6 @@ return make_address(str.c_str(), ec); } -#if !defined(ASIO_NO_DEPRECATED) asio::ip::address_v4 address::to_v4() const { if (type_ != ipv4) @@ -154,7 +153,6 @@ } return ipv6_address_; } -#endif // !defined(ASIO_NO_DEPRECATED) std::string address::to_string() const {
diff --git a/asio/include/asio/ssl/impl/rfc2818_verification.ipp b/asio/include/asio/ssl/impl/rfc2818_verification.ipp index dbb9ead..9b6ef04 100644 --- a/asio/include/asio/ssl/impl/rfc2818_verification.ipp +++ b/asio/include/asio/ssl/impl/rfc2818_verification.ipp
@@ -78,8 +78,7 @@ { if (address.is_v4() && ip_address->length == 4) { - ip::address_v4::bytes_type bytes = - ip::address_cast<ip::address_v4>(address).to_bytes(); + ip::address_v4::bytes_type bytes = address.to_v4().to_bytes(); if (memcmp(bytes.data(), ip_address->data, 4) == 0) { GENERAL_NAMES_free(gens); @@ -88,8 +87,7 @@ } else if (address.is_v6() && ip_address->length == 16) { - ip::address_v6::bytes_type bytes = - ip::address_cast<ip::address_v6>(address).to_bytes(); + ip::address_v6::bytes_type bytes = address.to_v6().to_bytes(); if (memcmp(bytes.data(), ip_address->data, 16) == 0) { GENERAL_NAMES_free(gens);
diff --git a/asio/src/examples/cpp03/socks4/socks4.hpp b/asio/src/examples/cpp03/socks4/socks4.hpp index 7c6aa9d..d3cb5d6 100644 --- a/asio/src/examples/cpp03/socks4/socks4.hpp +++ b/asio/src/examples/cpp03/socks4/socks4.hpp
@@ -48,8 +48,7 @@ port_low_byte_ = port & 0xff; // Save IP address in network byte order. - address_ = asio::ip::address_cast<asio::ip::address_v4>( - endpoint.address()).to_bytes(); + address_ = endpoint.address().to_v4().to_bytes(); } boost::array<asio::const_buffer, 7> buffers() const
diff --git a/asio/src/tests/unit/ip/address.cpp b/asio/src/tests/unit/ip/address.cpp index 1ed5157..d36bdef 100644 --- a/asio/src/tests/unit/ip/address.cpp +++ b/asio/src/tests/unit/ip/address.cpp
@@ -105,13 +105,6 @@ addr1 = ip::make_address(string_value); addr1 = ip::make_address(string_value, ec); - // address casts. - - addr_v4_value = ip::address_cast<ip::address_v4>(addr1); - addr1 = ip::address_cast<ip::address>(addr_v4_value); - addr_v6_value = ip::address_cast<ip::address_v6>(addr1); - addr1 = ip::address_cast<ip::address>(addr_v6_value); - // address I/O. std::ostringstream os;