From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed 4/5] libstdc++: Make net::ip::basic_endpoint comparisons constexpr
Date: Fri, 24 Feb 2023 14:28:07 +0000 [thread overview]
Message-ID: <20230224142808.714075-4-jwakely@redhat.com> (raw)
In-Reply-To: <20230224142808.714075-1-jwakely@redhat.com>
Tested x86_64-linux. Pushed to trunk.
-- >8 --
libstdc++-v3/ChangeLog:
* include/experimental/internet (basic_endpoint): Add missing
constexpr to comparison operators.
* testsuite/experimental/net/internet/endpoint/cons.cc: New test.
---
libstdc++-v3/include/experimental/internet | 12 ++--
.../net/internet/endpoint/cons.cc | 66 +++++++++++++++++++
2 files changed, 72 insertions(+), 6 deletions(-)
create mode 100644 libstdc++-v3/testsuite/experimental/net/internet/endpoint/cons.cc
diff --git a/libstdc++-v3/include/experimental/internet b/libstdc++-v3/include/experimental/internet
index 5336b8a8ce3..cae07f466da 100644
--- a/libstdc++-v3/include/experimental/internet
+++ b/libstdc++-v3/include/experimental/internet
@@ -1626,19 +1626,19 @@ namespace ip
*/
template<typename _InternetProtocol>
- inline bool
+ constexpr bool
operator==(const basic_endpoint<_InternetProtocol>& __a,
const basic_endpoint<_InternetProtocol>& __b)
{ return __a.address() == __b.address() && __a.port() == __b.port(); }
template<typename _InternetProtocol>
- inline bool
+ constexpr bool
operator!=(const basic_endpoint<_InternetProtocol>& __a,
const basic_endpoint<_InternetProtocol>& __b)
{ return !(__a == __b); }
template<typename _InternetProtocol>
- inline bool
+ constexpr bool
operator< (const basic_endpoint<_InternetProtocol>& __a,
const basic_endpoint<_InternetProtocol>& __b)
{
@@ -1647,19 +1647,19 @@ namespace ip
}
template<typename _InternetProtocol>
- inline bool
+ constexpr bool
operator> (const basic_endpoint<_InternetProtocol>& __a,
const basic_endpoint<_InternetProtocol>& __b)
{ return __b < __a; }
template<typename _InternetProtocol>
- inline bool
+ constexpr bool
operator<=(const basic_endpoint<_InternetProtocol>& __a,
const basic_endpoint<_InternetProtocol>& __b)
{ return !(__b < __a); }
template<typename _InternetProtocol>
- inline bool
+ constexpr bool
operator>=(const basic_endpoint<_InternetProtocol>& __a,
const basic_endpoint<_InternetProtocol>& __b)
{ return !(__a < __b); }
diff --git a/libstdc++-v3/testsuite/experimental/net/internet/endpoint/cons.cc b/libstdc++-v3/testsuite/experimental/net/internet/endpoint/cons.cc
new file mode 100644
index 00000000000..1b5c92c0b58
--- /dev/null
+++ b/libstdc++-v3/testsuite/experimental/net/internet/endpoint/cons.cc
@@ -0,0 +1,66 @@
+// { dg-do run { target c++14 } }
+// { dg-require-effective-target net_ts_ip }
+// { dg-add-options net_ts }
+
+#include <experimental/internet>
+#include <testsuite_hooks.h>
+
+using namespace std::experimental::net;
+
+constexpr void
+test_default()
+{
+ ip::tcp::endpoint t1;
+ VERIFY( t1.protocol() == ip::tcp::v4() );
+ VERIFY( t1.address() == ip::address() );
+ VERIFY( t1.port() == 0 );
+
+ ip::udp::endpoint t2;
+ VERIFY( t2.protocol() == ip::udp::v4() );
+ VERIFY( t2.address() == ip::address() );
+ VERIFY( t2.port() == 0 );
+}
+
+constexpr void
+test_proto()
+{
+ ip::tcp::endpoint t1(ip::tcp::v4(), 22);
+ VERIFY( t1.protocol() == ip::tcp::v4() );
+ VERIFY( t1.address() == ip::address_v4() );
+ VERIFY( t1.port() == 22 );
+
+ ip::tcp::endpoint t2(ip::tcp::v6(), 80);
+ VERIFY( t2.protocol() == ip::tcp::v6() );
+ VERIFY( t2.address() == ip::address_v6() );
+ VERIFY( t2.port() == 80 );
+}
+
+constexpr void
+test_addr()
+{
+ ip::address_v4 a1(ip::address_v4::bytes_type(1, 2, 3, 4));
+ ip::tcp::endpoint t1(a1, 22);
+ VERIFY( t1.protocol() == ip::tcp::v4() );
+ VERIFY( t1.address() == a1 );
+ VERIFY( t1.port() == 22 );
+
+ ip::address_v6 a2(ip::address_v6::bytes_type(21,22,23,24,25,26,27,28,29));
+ ip::tcp::endpoint t2(a2, 80);
+ VERIFY( t2.protocol() == ip::tcp::v6() );
+ VERIFY( t2.address() == a2 );
+ VERIFY( t2.port() == 80 );
+}
+
+int main()
+{
+ test_default();
+ test_proto();
+ test_addr();
+
+ constexpr bool c = [] {
+ test_default();
+ test_proto();
+ test_addr();
+ return true;
+ };
+}
--
2.39.2
next prev parent reply other threads:[~2023-02-24 14:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-24 14:28 [committed 1/5] libstdc++: Optimize net::ip::address_v4::to_string() Jonathan Wakely
2023-02-24 14:28 ` [committed 2/5] libstdc++: Fix conversion to/from net::ip::address_v4::bytes_type Jonathan Wakely
2023-02-24 14:28 ` [committed 3/5] libstdc++: Fix members of net::ip::network_v4 Jonathan Wakely
2023-02-24 14:28 ` Jonathan Wakely [this message]
2023-02-24 14:28 ` [committed 5/5] libstdc++: Constrain net::executor constructors Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230224142808.714075-4-jwakely@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).