From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 23FAC3858C62 for ; Mon, 14 Nov 2022 10:21:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 23FAC3858C62 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668421273; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JVQQYpCYz1eBFzSzmxAtyVWRt1rL++SDQP71XrbC6uE=; b=Q8SNfCHZS4Z6wjAhpWkWflUreb/ber7SksHpAM7QgsG7rhx4yFaPfCJDrjqN4fCwvXXuQr iv7EWbTaEFWD6s0B2IY/LfbU61kLEtPykC5ayGhwx9efvZmHtOnTn7qdzzgVKfCf9teG/t eLLE63zO6fPk56nSytanLHwmuK1MfLY= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-310-SWUsi9mZMvm9jAzRsxAn7A-1; Mon, 14 Nov 2022 05:21:10 -0500 X-MC-Unique: SWUsi9mZMvm9jAzRsxAn7A-1 Received: by mail-ej1-f72.google.com with SMTP id hq18-20020a1709073f1200b007ade8dd3494so5118932ejc.2 for ; Mon, 14 Nov 2022 02:21:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JVQQYpCYz1eBFzSzmxAtyVWRt1rL++SDQP71XrbC6uE=; b=u50f+NUczaPfZXEBlrqtB4kE1XLCowIHGxkJen7UrZZ8T7zFN+kj0NB/QPIe1b9KlA 8b12IgJBszBhanHt3YY3yMH+EGwM5yRAVU3YtFh7Q3Z3Q3BBaS1IQ7KPpUy/vZecguKI 6HCmGBYTHl9sq0hXfXnIlZdo8qjVR2YHK1Sz+JiW8Wn/dU4Kg8DemmMA8fPvDKranDLN LhAztINsEPir4Z9Z1XVxEOQyqWvslHyk85aYPqZrCk0NxCunTEktcdtTwKuRzfKoZAyO z3E8qbQM+y6CK6lt68w10OHVgrwk6+RrJuHm+Doemj/eQ50jgPoz4oVBZNygV4RrCQ46 Tnvg== X-Gm-Message-State: ANoB5pm3mdLXnyNCpanjSagoeeN65CxjfjsJQgEwwPJGY7/hqgFoKY17 ZJR7FZUqUwxFGWLcZxd8Rnhnl7fBQkuRaGhDSR1l1Q5veciu9PJdIvCOp2RXqRF7ULMgkBMt/h8 TAcNkmEkMJJp2N2bzITDCJqSUbTN5jsKjqw== X-Received: by 2002:a17:907:9258:b0:78d:8dfb:10ad with SMTP id kb24-20020a170907925800b0078d8dfb10admr10219589ejb.289.1668421269377; Mon, 14 Nov 2022 02:21:09 -0800 (PST) X-Google-Smtp-Source: AA0mqf6gkWjxurPgjydBCLWtbO1khrcgyBskLgWj3jROl0uDwrJcSvzUpkKWRHyCl81YWHtDos7xVvohKVGFDToeZXA= X-Received: by 2002:a17:907:9258:b0:78d:8dfb:10ad with SMTP id kb24-20020a170907925800b0078d8dfb10admr10219580ejb.289.1668421269191; Mon, 14 Nov 2022 02:21:09 -0800 (PST) MIME-Version: 1.0 References: <20221114045047.362745-1-ppalka@redhat.com> <20221114045047.362745-2-ppalka@redhat.com> In-Reply-To: From: Jonathan Wakely Date: Mon, 14 Nov 2022 10:20:58 +0000 Message-ID: Subject: Re: [PATCH 2/3] libstdc++: Implement ranges::iota from P2440R1 To: =?UTF-8?Q?Daniel_Kr=C3=BCgler?= Cc: Patrick Palka , gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_NUMSUBJECT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, 14 Nov 2022 at 10:17, Daniel Kr=C3=BCgler wrote: > > Am Mo., 14. Nov. 2022 um 11:09 Uhr schrieb Jonathan Wakely via > Libstdc++ : > > > > On Mon, 14 Nov 2022 at 04:52, Patrick Palka via Libstdc++ > > 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/i= nclude/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 > > > + struct out_value_result > > > + { > > > + [[no_unique_address]] _Out out; > > > + [[no_unique_address]] _Tp value; > > > + > > > + template > > > + requires convertible_to > > > + && convertible_to > > > + constexpr > > > + operator out_value_result<_Out2, _Tp2>() const & > > > + { return {out, value}; } > > > + > > > + template > > > + requires convertible_to<_Out, _Out2> > > > + && convertible_to<_Tp, _Tp2> > > > + constexpr > > > + operator out_value_result<_Out2, _Tp2>() && > > > + { return {std::move(out), std::move(value)}; } > > > + }; > > > + > > > + template > > > + using iota_result =3D out_value_result<_Out, _Tp>; > > > + > > > + struct __iota_fn > > > + { > > > + template _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 !=3D __last) > > > + { > > > + *__first =3D static_cast&>(__value); > > > > Is this any different to const_cast(__value) ? > > I think it is. const_cast can potentially mean the removal > of volatile, True. > so I would always look with suspicion on const_cast _Tp&>, while static_cast is clearer. Alternatively, as_const could be > used, which does add_const_t. Which means evaluating the add_const trait *and* overload resolution for as_const* *and* a runtime function call. Let's go with static_cast.