public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Patrick Palka <ppalka@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: libstdc++@gcc.gnu.org, Patrick Palka <ppalka@redhat.com>
Subject: [PATCH] libstdc++: Fix condition for memoizing reverse_view::begin() [PR100621]
Date: Mon, 17 May 2021 12:17:43 -0400	[thread overview]
Message-ID: <20210517161743.870382-1-ppalka@redhat.com> (raw)

A range being a random access range is not a sufficient condition for
ranges::next(iter, sent) to have constant time complexity; the range
must also have a sized sentinel.  This adjusts the memoization condition
for reverse_view accordingly.

Tested on x86_64-pc-linxu-gnu, does this look OK for trunk?  Doesn't
seem to be worth backporting.

libstdc++-v3/ChangeLog:

	* include/std/ranges (reverse_view::_S_needs_cached_begin):
	Set to false if the underlying non-common random-access range
	doesn't have a sized sentinel.
---
 libstdc++-v3/include/std/ranges | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index bf52074ca05..e93469ca3b4 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -3340,7 +3340,9 @@ namespace views::__adaptor
     {
     private:
       static constexpr bool _S_needs_cached_begin
-	= !common_range<_Vp> && !random_access_range<_Vp>;
+	= !common_range<_Vp> && !(random_access_range<_Vp>
+				  && sized_sentinel_for<sentinel_t<_Vp>,
+							iterator_t<_Vp>>);
 
       [[no_unique_address]]
 	__detail::__maybe_present_t<_S_needs_cached_begin,
-- 
2.31.1.621.g97eea85a0a


             reply	other threads:[~2021-05-17 16:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-17 16:17 Patrick Palka [this message]
2021-05-17 16:47 ` 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=20210517161743.870382-1-ppalka@redhat.com \
    --to=ppalka@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).