public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r13-6672] libstdc++: Implement LWG 3715 changes to view_interface::empty
Date: Tue, 14 Mar 2023 20:46:52 +0000 (GMT) [thread overview]
Message-ID: <20230314204652.8C23D3858421@sourceware.org> (raw)
https://gcc.gnu.org/g:f2e7dd8b023b8de30af608afd68e0ecefa5c1de6
commit r13-6672-gf2e7dd8b023b8de30af608afd68e0ecefa5c1de6
Author: Patrick Palka <ppalka@redhat.com>
Date: Tue Mar 14 16:44:30 2023 -0400
libstdc++: Implement LWG 3715 changes to view_interface::empty
libstdc++-v3/ChangeLog:
* include/bits/ranges_util.h (view_interface::empty): Add
preferred overloads that use ranges::size when the range is
sized as per LWG 3715.
* testsuite/std/ranges/adaptors/lwg3715.cc: New test.
Diff:
---
libstdc++-v3/include/bits/ranges_util.h | 16 +++++++++--
.../testsuite/std/ranges/adaptors/lwg3715.cc | 33 ++++++++++++++++++++++
2 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/libstdc++-v3/include/bits/ranges_util.h b/libstdc++-v3/include/bits/ranges_util.h
index e4643e31a20..880a0ce0143 100644
--- a/libstdc++-v3/include/bits/ranges_util.h
+++ b/libstdc++-v3/include/bits/ranges_util.h
@@ -97,15 +97,27 @@ namespace ranges
constexpr bool
empty()
noexcept(noexcept(_S_empty(_M_derived())))
- requires forward_range<_Derived>
+ requires forward_range<_Derived> && (!sized_range<_Derived>)
{ return _S_empty(_M_derived()); }
+ constexpr bool
+ empty()
+ noexcept(noexcept(ranges::size(_M_derived()) == 0))
+ requires sized_range<_Derived>
+ { return ranges::size(_M_derived()) == 0; }
+
constexpr bool
empty() const
noexcept(noexcept(_S_empty(_M_derived())))
- requires forward_range<const _Derived>
+ requires forward_range<const _Derived> && (!sized_range<const _Derived>)
{ return _S_empty(_M_derived()); }
+ constexpr bool
+ empty() const
+ noexcept(noexcept(ranges::size(_M_derived()) == 0))
+ requires sized_range<const _Derived>
+ { return ranges::size(_M_derived()) == 0; }
+
constexpr explicit
operator bool() noexcept(noexcept(ranges::empty(_M_derived())))
requires requires { ranges::empty(_M_derived()); }
diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/lwg3715.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/lwg3715.cc
new file mode 100644
index 00000000000..96ee7087be0
--- /dev/null
+++ b/libstdc++-v3/testsuite/std/ranges/adaptors/lwg3715.cc
@@ -0,0 +1,33 @@
+// { dg-options "-std=gnu++23" }
+// { dg-do run { target c++23 } }
+
+// Verify LWG 3715 changes.
+
+#include <ranges>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ std::istringstream ints("0 1 2 3 4");
+ auto i = std::views::istream<int>(ints);
+ auto r4 = std::views::counted(i.begin(), 4) | std::views::chunk(2);
+ VERIFY( !r4.empty() );
+}
+
+void
+test02()
+{
+ std::istringstream ints("0 1 2 3 4");
+ auto i = std::views::istream<int>(ints);
+ auto r0 = std::views::counted(i.begin(), 0) | std::views::chunk(2);
+ VERIFY( r0.empty() );
+}
+
+int
+main()
+{
+ test01();
+ test02();
+}
reply other threads:[~2023-03-14 20:46 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20230314204652.8C23D3858421@sourceware.org \
--to=ppalka@gcc.gnu.org \
--cc=gcc-cvs@gcc.gnu.org \
--cc=libstdc++-cvs@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).