From b5b9717ed687681e8abb9004ec003ff388f26319 Mon Sep 17 00:00:00 2001 From: Christopher Kohlhoff Date: Sun, 24 Feb 2019 10:20:27 -1000 Subject: [PATCH] Add noexcept qualifier to ip::address_v4 class. --- asio/include/asio/ip/address_v4.hpp | 56 +++++++++++++----------- asio/include/asio/ip/impl/address_v4.ipp | 20 ++++----- 2 files changed, 41 insertions(+), 35 deletions(-) diff --git a/asio/include/asio/ip/address_v4.hpp b/asio/include/asio/ip/address_v4.hpp index 4348ef2e..4d6af7fd 100644 --- a/asio/include/asio/ip/address_v4.hpp +++ b/asio/include/asio/ip/address_v4.hpp @@ -60,7 +60,7 @@ public: #endif /// Default constructor. - address_v4() + address_v4() ASIO_NOEXCEPT { addr_.s_addr = 0; } @@ -72,21 +72,21 @@ public: ASIO_DECL explicit address_v4(uint_type addr); /// Copy constructor. - address_v4(const address_v4& other) + address_v4(const address_v4& other) ASIO_NOEXCEPT : addr_(other.addr_) { } #if defined(ASIO_HAS_MOVE) /// Move constructor. - address_v4(address_v4&& other) + address_v4(address_v4&& other) ASIO_NOEXCEPT : addr_(other.addr_) { } #endif // defined(ASIO_HAS_MOVE) /// Assign from another address. - address_v4& operator=(const address_v4& other) + address_v4& operator=(const address_v4& other) ASIO_NOEXCEPT { addr_ = other.addr_; return *this; @@ -94,7 +94,7 @@ public: #if defined(ASIO_HAS_MOVE) /// Move-assign from another address. - address_v4& operator=(address_v4&& other) + address_v4& operator=(address_v4&& other) ASIO_NOEXCEPT { addr_ = other.addr_; return *this; @@ -102,10 +102,10 @@ public: #endif // defined(ASIO_HAS_MOVE) /// Get the address in bytes, in network byte order. - ASIO_DECL bytes_type to_bytes() const; + ASIO_DECL bytes_type to_bytes() const ASIO_NOEXCEPT; /// Get the address as an unsigned integer in host byte order - ASIO_DECL uint_type to_uint() const; + ASIO_DECL uint_type to_uint() const ASIO_NOEXCEPT; #if !defined(ASIO_NO_DEPRECATED) /// Get the address as an unsigned long in host byte order @@ -140,10 +140,10 @@ public: #endif // !defined(ASIO_NO_DEPRECATED) /// Determine whether the address is a loopback address. - ASIO_DECL bool is_loopback() const; + ASIO_DECL bool is_loopback() const ASIO_NOEXCEPT; /// Determine whether the address is unspecified. - ASIO_DECL bool is_unspecified() const; + ASIO_DECL bool is_unspecified() const ASIO_NOEXCEPT; #if !defined(ASIO_NO_DEPRECATED) /// (Deprecated: Use network_v4 class.) Determine whether the address is a @@ -160,58 +160,64 @@ public: #endif // !defined(ASIO_NO_DEPRECATED) /// Determine whether the address is a multicast address. - ASIO_DECL bool is_multicast() const; + ASIO_DECL bool is_multicast() const ASIO_NOEXCEPT; /// Compare two addresses for equality. - friend bool operator==(const address_v4& a1, const address_v4& a2) + friend bool operator==(const address_v4& a1, + const address_v4& a2) ASIO_NOEXCEPT { return a1.addr_.s_addr == a2.addr_.s_addr; } /// Compare two addresses for inequality. - friend bool operator!=(const address_v4& a1, const address_v4& a2) + friend bool operator!=(const address_v4& a1, + const address_v4& a2) ASIO_NOEXCEPT { return a1.addr_.s_addr != a2.addr_.s_addr; } /// Compare addresses for ordering. - friend bool operator<(const address_v4& a1, const address_v4& a2) + friend bool operator<(const address_v4& a1, + const address_v4& a2) ASIO_NOEXCEPT { return a1.to_uint() < a2.to_uint(); } /// Compare addresses for ordering. - friend bool operator>(const address_v4& a1, const address_v4& a2) + friend bool operator>(const address_v4& a1, + const address_v4& a2) ASIO_NOEXCEPT { return a1.to_uint() > a2.to_uint(); } /// Compare addresses for ordering. - friend bool operator<=(const address_v4& a1, const address_v4& a2) + friend bool operator<=(const address_v4& a1, + const address_v4& a2) ASIO_NOEXCEPT { return a1.to_uint() <= a2.to_uint(); } /// Compare addresses for ordering. - friend bool operator>=(const address_v4& a1, const address_v4& a2) + friend bool operator>=(const address_v4& a1, + const address_v4& a2) ASIO_NOEXCEPT { return a1.to_uint() >= a2.to_uint(); } /// Obtain an address object that represents any address. - static address_v4 any() + static address_v4 any() ASIO_NOEXCEPT { return address_v4(); } /// Obtain an address object that represents the loopback address. - static address_v4 loopback() + static address_v4 loopback() ASIO_NOEXCEPT { return address_v4(0x7F000001); } /// Obtain an address object that represents the broadcast address. - static address_v4 broadcast() + static address_v4 broadcast() ASIO_NOEXCEPT { return address_v4(0xFFFFFFFF); } @@ -261,8 +267,8 @@ ASIO_DECL address_v4 make_address_v4(const char* str); /** * @relates address_v4 */ -ASIO_DECL address_v4 make_address_v4( - const char* str, asio::error_code& ec); +ASIO_DECL address_v4 make_address_v4(const char* str, + asio::error_code& ec) ASIO_NOEXCEPT; /// Create an IPv4 address from an IP address string in dotted decimal form. /** @@ -274,8 +280,8 @@ ASIO_DECL address_v4 make_address_v4(const std::string& str); /** * @relates address_v4 */ -ASIO_DECL address_v4 make_address_v4( - const std::string& str, asio::error_code& ec); +ASIO_DECL address_v4 make_address_v4(const std::string& str, + asio::error_code& ec) ASIO_NOEXCEPT; #if defined(ASIO_HAS_STRING_VIEW) \ || defined(GENERATING_DOCUMENTATION) @@ -290,8 +296,8 @@ ASIO_DECL address_v4 make_address_v4(string_view str); /** * @relates address_v4 */ -ASIO_DECL address_v4 make_address_v4( - string_view str, asio::error_code& ec); +ASIO_DECL address_v4 make_address_v4(string_view str, + asio::error_code& ec) ASIO_NOEXCEPT; #endif // defined(ASIO_HAS_STRING_VIEW) // || defined(GENERATING_DOCUMENTATION) diff --git a/asio/include/asio/ip/impl/address_v4.ipp b/asio/include/asio/ip/impl/address_v4.ipp index dee7cb5f..8d3764fd 100644 --- a/asio/include/asio/ip/impl/address_v4.ipp +++ b/asio/include/asio/ip/impl/address_v4.ipp @@ -57,7 +57,7 @@ address_v4::address_v4(address_v4::uint_type addr) static_cast(addr)); } -address_v4::bytes_type address_v4::to_bytes() const +address_v4::bytes_type address_v4::to_bytes() const ASIO_NOEXCEPT { using namespace std; // For memcpy. bytes_type bytes; @@ -69,7 +69,7 @@ address_v4::bytes_type address_v4::to_bytes() const return bytes; } -address_v4::uint_type address_v4::to_uint() const +address_v4::uint_type address_v4::to_uint() const ASIO_NOEXCEPT { return asio::detail::socket_ops::network_to_host_long(addr_.s_addr); } @@ -108,12 +108,12 @@ std::string address_v4::to_string(asio::error_code& ec) const } #endif // !defined(ASIO_NO_DEPRECATED) -bool address_v4::is_loopback() const +bool address_v4::is_loopback() const ASIO_NOEXCEPT { return (to_uint() & 0xFF000000) == 0x7F000000; } -bool address_v4::is_unspecified() const +bool address_v4::is_unspecified() const ASIO_NOEXCEPT { return to_uint() == 0; } @@ -135,7 +135,7 @@ bool address_v4::is_class_c() const } #endif // !defined(ASIO_NO_DEPRECATED) -bool address_v4::is_multicast() const +bool address_v4::is_multicast() const ASIO_NOEXCEPT { return (to_uint() & 0xF0000000) == 0xE0000000; } @@ -166,8 +166,8 @@ address_v4 make_address_v4(const char* str) return addr; } -address_v4 make_address_v4( - const char* str, asio::error_code& ec) +address_v4 make_address_v4(const char* str, + asio::error_code& ec) ASIO_NOEXCEPT { address_v4::bytes_type bytes; if (asio::detail::socket_ops::inet_pton( @@ -181,8 +181,8 @@ address_v4 make_address_v4(const std::string& str) return make_address_v4(str.c_str()); } -address_v4 make_address_v4( - const std::string& str, asio::error_code& ec) +address_v4 make_address_v4(const std::string& str, + asio::error_code& ec) ASIO_NOEXCEPT { return make_address_v4(str.c_str(), ec); } @@ -195,7 +195,7 @@ address_v4 make_address_v4(string_view str) } address_v4 make_address_v4(string_view str, - asio::error_code& ec) + asio::error_code& ec) ASIO_NOEXCEPT { return make_address_v4(static_cast(str), ec); }