public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Daniel Krügler" <daniel.kruegler@gmail.com>
To: Jonathan Wakely <jwakely@redhat.com>
Cc: Patrick Palka <ppalka@redhat.com>,
	gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org
Subject: Re: [PATCH 2/3] libstdc++: Implement ranges::iota from P2440R1
Date: Mon, 14 Nov 2022 11:17:22 +0100	[thread overview]
Message-ID: <CAGNvRgDUbuOLxesO3g5TDAkfjbvGfz7-+EirGYY+icDxKiW4sg@mail.gmail.com> (raw)
In-Reply-To: <CACb0b4mNF-_WyL48YdAWkYjDtf3CzD9KAo8RbY7v-TkShZhs4A@mail.gmail.com>

Am Mo., 14. Nov. 2022 um 11:09 Uhr schrieb Jonathan Wakely via
Libstdc++ <libstdc++@gcc.gnu.org>:
>
> On Mon, 14 Nov 2022 at 04:52, Patrick Palka via Libstdc++
> <libstdc++@gcc.gnu.org> wrote:
> >
> > Tested on x86_64-pc-linux-gnu, does this look OK for trunk?
> >
> > libstdc++-v3/ChangeLog:
> >
> >         * include/bits/ranges_algo.h (out_value_result): Define.
> >         (iota_result): Define.
> >         (__iota_fn, iota): Define.
> >         * testsuite/25_algorithms/iota/1.cc: New test.
> > ---
> >  libstdc++-v3/include/bits/ranges_algo.h       | 48 +++++++++++++++++++
> >  .../testsuite/25_algorithms/iota/1.cc         | 29 +++++++++++
> >  2 files changed, 77 insertions(+)
> >  create mode 100644 libstdc++-v3/testsuite/25_algorithms/iota/1.cc
> >
> > diff --git a/libstdc++-v3/include/bits/ranges_algo.h b/libstdc++-v3/include/bits/ranges_algo.h
> > index da0ca981dc3..f003117c569 100644
> > --- a/libstdc++-v3/include/bits/ranges_algo.h
> > +++ b/libstdc++-v3/include/bits/ranges_algo.h
> > @@ -3517,6 +3517,54 @@ namespace ranges
> >    };
> >
> >    inline constexpr __contains_subrange_fn contains_subrange{};
> > +
> > +  template<typename _Out, typename _Tp>
> > +    struct out_value_result
> > +    {
> > +      [[no_unique_address]] _Out out;
> > +      [[no_unique_address]] _Tp value;
> > +
> > +      template<typename _Out2, typename _Tp2>
> > +       requires convertible_to<const _Out&, _Out2>
> > +         && convertible_to<const _Tp&, _Tp2>
> > +       constexpr
> > +       operator out_value_result<_Out2, _Tp2>() const &
> > +       { return {out, value}; }
> > +
> > +      template<typename _Out2, typename _Tp2>
> > +       requires convertible_to<_Out, _Out2>
> > +         && convertible_to<_Tp, _Tp2>
> > +       constexpr
> > +       operator out_value_result<_Out2, _Tp2>() &&
> > +       { return {std::move(out), std::move(value)}; }
> > +    };
> > +
> > +  template<typename _Out, typename _Tp>
> > +    using iota_result = out_value_result<_Out, _Tp>;
> > +
> > +  struct __iota_fn
> > +  {
> > +    template<input_or_output_iterator _Out, sentinel_for<_Out> _Sent, weakly_incrementable _Tp>
> > +      requires indirectly_writable<_Out, const _Tp&>
> > +      constexpr iota_result<_Out, _Tp>
> > +      operator()(_Out __first, _Sent __last, _Tp __value) const
> > +      {
> > +       while (__first != __last)
> > +         {
> > +           *__first = static_cast<add_const_t<_Tp>&>(__value);
>
> Is this any different to const_cast<const _Tp&>(__value) ?

I think it is. const_cast<const _Tp&> can potentially mean the removal
of volatile, so I would always look with suspicion on const_cast<const
_Tp&>, while static_cast is clearer. Alternatively, as_const could be
used, which does add_const_t.

- Daniel

  reply	other threads:[~2022-11-14 10:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-14  4:50 [PATCH 1/3] libstdc++: Implement ranges::contains/contains_subrange from P2302R4 Patrick Palka
2022-11-14  4:50 ` [PATCH 2/3] libstdc++: Implement ranges::iota from P2440R1 Patrick Palka
2022-11-14 10:08   ` Jonathan Wakely
2022-11-14 10:17     ` Daniel Krügler [this message]
2022-11-14 10:20       ` Jonathan Wakely
2022-11-14 15:11         ` Patrick Palka
2022-11-14 15:12           ` Jonathan Wakely
2022-11-14  4:50 ` [PATCH 3/3] libstdc++: Implement ranges::find_last{,_if,_if_not} from P1223R5 Patrick Palka
2022-11-14 15:12   ` [PATCH 3/3] libstdc++: Implement ranges::find_last{, _if, _if_not} " Jonathan Wakely
2022-11-14  9:04 ` [PATCH 1/3] libstdc++: Implement ranges::contains/contains_subrange from P2302R4 Jonathan Wakely
2022-11-14 15:07   ` Patrick Palka
2022-11-14 15:09     ` 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=CAGNvRgDUbuOLxesO3g5TDAkfjbvGfz7-+EirGYY+icDxKiW4sg@mail.gmail.com \
    --to=daniel.kruegler@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jwakely@redhat.com \
    --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).