From: Jonathan Wakely <jwakely@redhat.com>
To: Patrick Palka <ppalka@redhat.com>
Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org
Subject: Re: [PATCH] libstdc++: Implement LWG 3715 changes to view_interface::empty
Date: Thu, 9 Mar 2023 17:54:32 +0000 [thread overview]
Message-ID: <CACb0b4mkJCK6wCsiz2iMU_c2+h4Rs5Z1rr=4JS7na8KsxNQHrA@mail.gmail.com> (raw)
In-Reply-To: <20230308155306.257241-1-ppalka@redhat.com>
On Wed, 8 Mar 2023 at 15:53, Patrick Palka via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> Tested on x86_64-pc-linux-gnu, does this look OK for trunk?
OK. I think this would make sense for 12 too.
>
> 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
>
prev parent reply other threads:[~2023-03-09 17:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-08 15:53 Patrick Palka
2023-03-09 17:54 ` Jonathan Wakely [this message]
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='CACb0b4mkJCK6wCsiz2iMU_c2+h4Rs5Z1rr=4JS7na8KsxNQHrA@mail.gmail.com' \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
--cc=ppalka@redhat.com \
/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).