// types:
struct bytes_type : array<unsigned char, 16>
{
- template<typename... _Tp> explicit constexpr bytes_type(_Tp... __t)
- : array<unsigned char, 16>{{static_cast<unsigned char>(__t)...}} { }
+ template<typename... _Tp>
+ explicit constexpr
+ bytes_type(_Tp... __t)
+ : array<unsigned char, 16>{{static_cast<unsigned char>(__t)...}}
+ { }
};
// constructors:
// members:
constexpr protocol_type protocol() const noexcept
{
- return _M_data._M_v4.sin_family == AF_INET6
- ? protocol_type::v6() : protocol_type::v4();
+ return _M_is_v6() ? protocol_type::v6() : protocol_type::v4();
}
constexpr ip::address
address() const noexcept
{
ip::address __addr;
- if (protocol().family() == AF_INET6)
+ if (_M_is_v6())
{
__builtin_memcpy(&__addr._M_v6._M_bytes,
_M_data._M_v6.sin6_addr.s6_addr, 16);
{ _M_data._M_v4.sin_port = address_v4::_S_hton_16(__port_num); }
void* data() noexcept { return &_M_data; }
+
const void* data() const noexcept { return &_M_data; }
+
constexpr size_t size() const noexcept
- {
- return protocol().family() == AF_INET6
- ? sizeof(sockaddr_in6) : sizeof(sockaddr_in);
- }
+ { return _M_is_v6() ? sizeof(sockaddr_in6) : sizeof(sockaddr_in); }
void
resize(size_t __s)
{
- if ((protocol().family() == AF_INET6 && __s != sizeof(sockaddr_in6))
- || (protocol().family() == AF_INET && __s != sizeof(sockaddr_in)))
+ if (__s != size())
__throw_length_error("net::ip::basic_endpoint::resize");
}
sockaddr_in _M_v4;
sockaddr_in6 _M_v6;
} _M_data;
+
+ constexpr bool _M_is_v6() const noexcept
+ { return _M_data._M_v4.sin_family == AF_INET6; }
};
/** basic_endpoint comparisons
* @{
*/
- inline bool
- operator==(const tcp& __a, const tcp& __b)
+ constexpr bool
+ operator==(const tcp& __a, const tcp& __b) noexcept
{ return __a.family() == __b.family(); }
- inline bool
- operator!=(const tcp& __a, const tcp& __b)
+ constexpr bool
+ operator!=(const tcp& __a, const tcp& __b) noexcept
{ return !(__a == __b); }
/// @}
* @{
*/
- inline bool
- operator==(const udp& __a, const udp& __b)
+ constexpr bool
+ operator==(const udp& __a, const udp& __b) noexcept
{ return __a.family() == __b.family(); }
- inline bool
- operator!=(const udp& __a, const udp& __b)
+ constexpr bool
+ operator!=(const udp& __a, const udp& __b) noexcept
{ return !(__a == __b); }
/// @}
--- /dev/null
+// { dg-do compile { target c++14 } }
+
+#include <experimental/internet>
+#include <type_traits>
+
+#if __has_include(<netinet/in.h>)
+using namespace std;
+using std::experimental::net::ip::tcp;
+using std::experimental::net::ip::basic_endpoint;
+using std::experimental::net::ip::basic_resolver;
+using std::experimental::net::basic_stream_socket;
+using std::experimental::net::basic_socket_acceptor;
+using std::experimental::net::basic_socket_iostream;
+
+void
+test01()
+{
+ static_assert( ! is_default_constructible<tcp>(), "" );
+ static_assert( is_nothrow_copy_constructible<tcp>(), "" );
+ static_assert( is_nothrow_copy_assignable<tcp>(), "" );
+
+ static_assert( is_same<tcp::endpoint, basic_endpoint<tcp>>(), "");
+ static_assert( is_same<tcp::resolver, basic_resolver<tcp>>(), "");
+ static_assert( is_same<tcp::socket, basic_stream_socket<tcp>>(), "");
+ static_assert( is_same<tcp::acceptor, basic_socket_acceptor<tcp>>(), "");
+ static_assert( is_same<tcp::iostream, basic_socket_iostream<tcp>>(), "");
+
+ static_assert( tcp::v4() == tcp::v4(), "" );
+ static_assert( tcp::v6() == tcp::v6(), "" );
+ static_assert( tcp::v4() != tcp::v6(), "" );
+ static_assert( tcp::v6() != tcp::v4(), "" );
+
+ static_assert( noexcept(tcp::v6() == tcp::v4()), "" );
+ static_assert( noexcept(tcp::v6() != tcp::v4()), "" );
+
+ static_assert( tcp::v4().family() == AF_INET, "" );
+ static_assert( tcp::v6().family() == AF_INET6, "" );
+
+ static_assert( tcp::v4().type() == SOCK_STREAM, "" );
+ static_assert( tcp::v6().type() == SOCK_STREAM, "" );
+
+ static_assert( tcp::v4().protocol() == IPPROTO_TCP, "" );
+ static_assert( tcp::v6().protocol() == IPPROTO_TCP, "" );
+}
+#endif
--- /dev/null
+// { dg-do compile { target c++14 } }
+
+#include <experimental/internet>
+#include <type_traits>
+
+#if __has_include(<netinet/in.h>)
+using namespace std;
+using std::experimental::net::ip::udp;
+using std::experimental::net::ip::basic_endpoint;
+using std::experimental::net::ip::basic_resolver;
+using std::experimental::net::basic_datagram_socket;
+using std::experimental::net::basic_socket_acceptor;
+using std::experimental::net::basic_socket_iostream;
+
+void
+test01()
+{
+ static_assert( ! is_default_constructible<udp>(), "" );
+ static_assert( is_nothrow_copy_constructible<udp>(), "" );
+ static_assert( is_nothrow_copy_assignable<udp>(), "" );
+
+ static_assert( is_same<udp::endpoint, basic_endpoint<udp>>(), "");
+ static_assert( is_same<udp::resolver, basic_resolver<udp>>(), "");
+ static_assert( is_same<udp::socket, basic_datagram_socket<udp>>(), "");
+
+ static_assert( udp::v4() == udp::v4(), "" );
+ static_assert( udp::v6() == udp::v6(), "" );
+ static_assert( udp::v4() != udp::v6(), "" );
+ static_assert( udp::v6() != udp::v4(), "" );
+
+ static_assert( noexcept(udp::v6() == udp::v4()), "" );
+ static_assert( noexcept(udp::v6() != udp::v4()), "" );
+
+ static_assert( udp::v4().family() == AF_INET, "" );
+ static_assert( udp::v6().family() == AF_INET6, "" );
+
+ static_assert( udp::v4().type() == SOCK_DGRAM, "" );
+ static_assert( udp::v6().type() == SOCK_DGRAM, "" );
+
+ static_assert( udp::v4().protocol() == IPPROTO_UDP, "" );
+ static_assert( udp::v6().protocol() == IPPROTO_UDP, "" );
+}
+#endif