public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libstdc++: Implement LWG 3715 changes to view_interface::empty
@ 2023-03-08 15:53 Patrick Palka
  2023-03-09 17:54 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2023-03-08 15:53 UTC (permalink / raw)
  To: gcc-patches; +Cc: libstdc++, Patrick Palka

Tested on x86_64-pc-linux-gnu, does this look OK for trunk?

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.
---
 libstdc++-v3/include/bits/ranges_util.h       | 16 +++++++--
 .../testsuite/std/ranges/adaptors/lwg3715.cc  | 33 +++++++++++++++++++
 2 files changed, 47 insertions(+), 2 deletions(-)
 create mode 100644 libstdc++-v3/testsuite/std/ranges/adaptors/lwg3715.cc

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();
+}
-- 
2.40.0.rc0.57.g454dfcbddf


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-03-09 17:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-08 15:53 [PATCH] libstdc++: Implement LWG 3715 changes to view_interface::empty Patrick Palka
2023-03-09 17:54 ` Jonathan Wakely

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).