public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
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 1/2] libstdc++: Implement ranges::adjacent_view from P2321R2
Date: Wed, 31 Aug 2022 14:31:45 +0100	[thread overview]
Message-ID: <CACb0b4k0SAy1-fHDd5nLt67VbGJtB7dJOfj9c_DhbbeBzKLH4g@mail.gmail.com> (raw)
In-Reply-To: <2fb1f58c-70ee-a271-d508-a7d172c61a1a@idea>

On Wed, 31 Aug 2022 at 14:30, Patrick Palka <ppalka@redhat.com> wrote:
>
> On Wed, 31 Aug 2022, Jonathan Wakely wrote:
>
> > On Tue, 30 Aug 2022 at 18:14, Patrick Palka via Libstdc++
> > <libstdc++@gcc.gnu.org> wrote:
> > >
> > > Tested on x86_64-pc-linux-gnu, does this look OK for trunk?
> >
> >
> > > +    constexpr
> > > +    _Iterator(__as_sentinel, iterator_t<_Base> __first, iterator_t<_Base> __last)
> > > +    {
> > > +      if constexpr (!bidirectional_range<_Base>)
> > > +       for (auto& __it : _M_current)
> > > +         __it = __last;
> > > +      else
> > > +       for (ssize_t __i = _Nm-1; __i >= 0; --__i)
> >
> > ssize_t is defined by POSIX in <sys/types.h> but isn't in ISO C or
> > C++. It looks like MinGW defines it to ... something ... sometimes,
> > but I don't think we can rely on it for non-POSIX targets.
>
> I see.  Using ssize_t makes the loop a little cleaner but it's hardly
> necessary, so consider it rewritten into:
>
>   for (size_t __i = 0; __i < _Nm; ++__i)
>     {
>       _M_current[_Nm - 1 - __i] = __last;
>       ranges::advance(__last, -1, __first);
>     }
>
> >
> >
> > > +    template<size_t _Nm>
> > > +      struct _Adjacent : __adaptor::_RangeAdaptorClosure
> > > +      {
> > > +       template<viewable_range _Range>
> > > +         requires (_Nm == 0) || __detail::__can_adjacent_view<_Nm, _Range>
> > > +         [[nodiscard]]
> > > +         constexpr auto
> > > +         operator()(_Range&& __r) const
> >
> > Does this attribute actually work here?
> >
> > I thought we needed to use `operator() [[nodiscard]]` for functions
> > with a requires-clause, because otherwise the attribute gives a parse
> > error. Maybe I've misremembered the problem, and it just doesn't give
> > a -Wunused-result warning. The decl above is setting off my spidey
> > sense for some reason though.
>
> Oops yeah, it looks like this position of [[nodiscard]] works with
> standard concepts, but it's a parse error with -fconcepts-ts due to the
> different requires-clause grammar.
>
> Here's v2 which avoids using ssize_t, and puts the [[nodiscard]] after
> 'operator()' (_Zip and _ZipTransform have the same issue which I can
> fix separately):

OK for trunk with those changes, thanks.


      reply	other threads:[~2022-08-31 13:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-30 17:13 Patrick Palka
2022-08-30 17:13 ` [PATCH 2/2] libstdc++: Implement ranges::adjacent_transform_view " Patrick Palka
2022-09-01 11:14   ` Jonathan Wakely
2022-08-31 10:26 ` [PATCH 1/2] libstdc++: Implement ranges::adjacent_view " Jonathan Wakely
2022-08-31 13:30   ` Patrick Palka
2022-08-31 13:31     ` 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=CACb0b4k0SAy1-fHDd5nLt67VbGJtB7dJOfj9c_DhbbeBzKLH4g@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).