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.129.124]) by sourceware.org (Postfix) with ESMTPS id B366F385840D for ; Fri, 14 Apr 2023 09:50:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B366F385840D 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=1681465807; 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: in-reply-to:in-reply-to:references:references; bh=X7H+6mJ7fL3OcpFU3SVwvq+jBVDQzRgqZQ7TNCiBQAg=; b=Ebr7ZTb1r6bDpG1GnUQ7wmFl91S1yZF1U/U5kd4KHKgqi9njQjglNxpraYsM2HO5WBnEyz +YiIiujNc63uCklT6MOYknvC/eNQWS8+T8GViUYmuJarhIlRuDcI9PqlzUsM0TeQh37cFF qFpxdf+EM1bPhBppnj2VjlJBaPiqoL4= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-643-DsTbkmHrONe8Fhg_adZudA-1; Fri, 14 Apr 2023 05:50:06 -0400 X-MC-Unique: DsTbkmHrONe8Fhg_adZudA-1 Received: by mail-lf1-f71.google.com with SMTP id t15-20020a192d4f000000b004eb3fa146c4so13410196lft.15 for ; Fri, 14 Apr 2023 02:50:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681465804; x=1684057804; h=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=X7H+6mJ7fL3OcpFU3SVwvq+jBVDQzRgqZQ7TNCiBQAg=; b=c3OuN10qZRCIUmZlcUV592mmvuXR4y6TNIoU+qELDKZHOX8LSM/zdXqloPV/ngmHMA 6VO4XQ5qa1/OkFwj8VtMl88xfU+uLdmJ91B1w+hYTL/xQU7w//WFmZeTs3KJ8MHS80fJ L1P9mGXLHebu3gpJbOco5mbFFK2N4cyPuHIFXOIreg9jaRtSGw+Hc5NcBeOujs8u6rGu 8d9Ui3DxFWAVpboJYYois9lwSK1YLh3LXX8Bh60nvRDSqcaOgCppiCm97R+E1zO+EusZ nvCpQOipHgrR0V0XsDXsSsGfgh4WnWKlYn/ghZI/pZFXRBzpTaKb0LR9SWS8xL2Ma5de 4lqQ== X-Gm-Message-State: AAQBX9e623vS0K002zlORx7EumBsSmXQeNiilFetu5IKnrtWs7hGU059 xXGBqIFQ2ORU3IcmW3SAWvD5HYOz4+y7CMFPwNmTXD4BJcSZS00SeoeQs0ogc8alHHTYwwXuIqn yTjnPMKJAci/X8Q5X1n1I1uyBceB1adE= X-Received: by 2002:a2e:7c03:0:b0:2a7:757a:6586 with SMTP id x3-20020a2e7c03000000b002a7757a6586mr1739616ljc.9.1681465804527; Fri, 14 Apr 2023 02:50:04 -0700 (PDT) X-Google-Smtp-Source: AKy350afth9Afii6XzZIe+y1I8fNEGnCkIGEPU5hD8vajXGAtmiE9LRHAwxkaHr2G+Fx0zXj5h24PvyI6SAXrrL5plU= X-Received: by 2002:a2e:7c03:0:b0:2a7:757a:6586 with SMTP id x3-20020a2e7c03000000b002a7757a6586mr1739606ljc.9.1681465804186; Fri, 14 Apr 2023 02:50:04 -0700 (PDT) MIME-Version: 1.0 References: <20230414040042.1498825-1-ppalka@redhat.com> In-Reply-To: <20230414040042.1498825-1-ppalka@redhat.com> From: Jonathan Wakely Date: Fri, 14 Apr 2023 10:49:53 +0100 Message-ID: Subject: Re: [PATCH 1/2] libstdc++: Move down definitions of ranges::cbegin/cend/cetc To: Patrick Palka Cc: 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" X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Fri, 14 Apr 2023 at 05:02, Patrick Palka via Libstdc++ wrote: > > This moves down the definitions of the const range access CPOs to after > the definition of input_range in preparation for implementing P2287R4 > which redefines these CPOs in a way that indirectly uses input_range. > > tested on x86_64-pc-linux-gnu, does this look OK for trunk? OK > > libstdc++-v3/ChangeLog: > > * include/bits/ranges_base.h (__cust_access::__as_const) > (__cust_access::_CBegin, __cust::cbegin) > (__cust_access::_CEnd, __cust::cend) > (__cust_access::_CRBegin, __cust::crbegin) > (__cust_access::_CREnd, __cust::crend) > (__cust_access::_CData, __cust::cdata): Move down definitions to > shortly after the definition of input_range. > --- > libstdc++-v3/include/bits/ranges_base.h | 174 +++++++++++++----------- > 1 file changed, 91 insertions(+), 83 deletions(-) > > diff --git a/libstdc++-v3/include/bits/ranges_base.h b/libstdc++-v3/include/bits/ranges_base.h > index 86952b34096..c89cb3e976a 100644 > --- a/libstdc++-v3/include/bits/ranges_base.h > +++ b/libstdc++-v3/include/bits/ranges_base.h > @@ -177,45 +177,6 @@ namespace ranges > } > }; > > - // If _To is an lvalue-reference, return const _Tp&, otherwise const _Tp&&. > - template > - constexpr decltype(auto) > - __as_const(_Tp& __t) noexcept > - { > - static_assert(std::is_same_v<_To&, _Tp&>); > - > - if constexpr (is_lvalue_reference_v<_To>) > - return const_cast(__t); > - else > - return static_cast(__t); > - } > - > - struct _CBegin > - { > - template > - [[nodiscard]] > - constexpr auto > - operator()(_Tp&& __e) const > - noexcept(noexcept(_Begin{}(__cust_access::__as_const<_Tp>(__e)))) > - requires requires { _Begin{}(__cust_access::__as_const<_Tp>(__e)); } > - { > - return _Begin{}(__cust_access::__as_const<_Tp>(__e)); > - } > - }; > - > - struct _CEnd final > - { > - template > - [[nodiscard]] > - constexpr auto > - operator()(_Tp&& __e) const > - noexcept(noexcept(_End{}(__cust_access::__as_const<_Tp>(__e)))) > - requires requires { _End{}(__cust_access::__as_const<_Tp>(__e)); } > - { > - return _End{}(__cust_access::__as_const<_Tp>(__e)); > - } > - }; > - > template > concept __member_rbegin = requires(_Tp& __t) > { > @@ -337,32 +298,6 @@ namespace ranges > } > }; > > - struct _CRBegin > - { > - template > - [[nodiscard]] > - constexpr auto > - operator()(_Tp&& __e) const > - noexcept(noexcept(_RBegin{}(__cust_access::__as_const<_Tp>(__e)))) > - requires requires { _RBegin{}(__cust_access::__as_const<_Tp>(__e)); } > - { > - return _RBegin{}(__cust_access::__as_const<_Tp>(__e)); > - } > - }; > - > - struct _CREnd > - { > - template > - [[nodiscard]] > - constexpr auto > - operator()(_Tp&& __e) const > - noexcept(noexcept(_REnd{}(__cust_access::__as_const<_Tp>(__e)))) > - requires requires { _REnd{}(__cust_access::__as_const<_Tp>(__e)); } > - { > - return _REnd{}(__cust_access::__as_const<_Tp>(__e)); > - } > - }; > - > template > concept __member_size = !disable_sized_range> > && requires(_Tp& __t) > @@ -547,36 +482,18 @@ namespace ranges > } > }; > > - struct _CData > - { > - template > - [[nodiscard]] > - constexpr auto > - operator()(_Tp&& __e) const > - noexcept(noexcept(_Data{}(__cust_access::__as_const<_Tp>(__e)))) > - requires requires { _Data{}(__cust_access::__as_const<_Tp>(__e)); } > - { > - return _Data{}(__cust_access::__as_const<_Tp>(__e)); > - } > - }; > - > } // namespace __cust_access > > inline namespace __cust > { > inline constexpr __cust_access::_Begin begin{}; > inline constexpr __cust_access::_End end{}; > - inline constexpr __cust_access::_CBegin cbegin{}; > - inline constexpr __cust_access::_CEnd cend{}; > inline constexpr __cust_access::_RBegin rbegin{}; > inline constexpr __cust_access::_REnd rend{}; > - inline constexpr __cust_access::_CRBegin crbegin{}; > - inline constexpr __cust_access::_CREnd crend{}; > inline constexpr __cust_access::_Size size{}; > inline constexpr __cust_access::_SSize ssize{}; > inline constexpr __cust_access::_Empty empty{}; > inline constexpr __cust_access::_Data data{}; > - inline constexpr __cust_access::_CData cdata{}; > } > > /// [range.range] The range concept. > @@ -690,6 +607,97 @@ namespace ranges > concept common_range > = range<_Tp> && same_as, sentinel_t<_Tp>>; > > + namespace __cust_access > + { > + // If _To is an lvalue-reference, return const _Tp&, otherwise const _Tp&&. > + template > + constexpr decltype(auto) > + __as_const(_Tp& __t) noexcept > + { > + static_assert(std::is_same_v<_To&, _Tp&>); > + > + if constexpr (is_lvalue_reference_v<_To>) > + return const_cast(__t); > + else > + return static_cast(__t); > + } > + > + struct _CBegin > + { > + template > + [[nodiscard]] > + constexpr auto > + operator()(_Tp&& __e) const > + noexcept(noexcept(_Begin{}(__cust_access::__as_const<_Tp>(__e)))) > + requires requires { _Begin{}(__cust_access::__as_const<_Tp>(__e)); } > + { > + return _Begin{}(__cust_access::__as_const<_Tp>(__e)); > + } > + }; > + > + struct _CEnd final > + { > + template > + [[nodiscard]] > + constexpr auto > + operator()(_Tp&& __e) const > + noexcept(noexcept(_End{}(__cust_access::__as_const<_Tp>(__e)))) > + requires requires { _End{}(__cust_access::__as_const<_Tp>(__e)); } > + { > + return _End{}(__cust_access::__as_const<_Tp>(__e)); > + } > + }; > + > + struct _CRBegin > + { > + template > + [[nodiscard]] > + constexpr auto > + operator()(_Tp&& __e) const > + noexcept(noexcept(_RBegin{}(__cust_access::__as_const<_Tp>(__e)))) > + requires requires { _RBegin{}(__cust_access::__as_const<_Tp>(__e)); } > + { > + return _RBegin{}(__cust_access::__as_const<_Tp>(__e)); > + } > + }; > + > + struct _CREnd > + { > + template > + [[nodiscard]] > + constexpr auto > + operator()(_Tp&& __e) const > + noexcept(noexcept(_REnd{}(__cust_access::__as_const<_Tp>(__e)))) > + requires requires { _REnd{}(__cust_access::__as_const<_Tp>(__e)); } > + { > + return _REnd{}(__cust_access::__as_const<_Tp>(__e)); > + } > + }; > + > + struct _CData > + { > + template > + [[nodiscard]] > + constexpr auto > + operator()(_Tp&& __e) const > + noexcept(noexcept(_Data{}(__cust_access::__as_const<_Tp>(__e)))) > + requires requires { _Data{}(__cust_access::__as_const<_Tp>(__e)); } > + { > + return _Data{}(__cust_access::__as_const<_Tp>(__e)); > + } > + }; > + > + } // namespace __cust_access > + > + inline namespace __cust > + { > + inline constexpr __cust_access::_CBegin cbegin{}; > + inline constexpr __cust_access::_CEnd cend{}; > + inline constexpr __cust_access::_CRBegin crbegin{}; > + inline constexpr __cust_access::_CREnd crend{}; > + inline constexpr __cust_access::_CData cdata{}; > + } > + > namespace __detail > { > template > -- > 2.40.0.335.g9857273be0 >