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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 01BEF386101E for ; Tue, 20 Apr 2021 10:33:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 01BEF386101E Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-531-tH56YWsZPG255JNe3fDagQ-1; Tue, 20 Apr 2021 06:33:09 -0400 X-MC-Unique: tH56YWsZPG255JNe3fDagQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 203661008060; Tue, 20 Apr 2021 10:33:08 +0000 (UTC) Received: from localhost (unknown [10.33.36.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id BFE3B5C1C4; Tue, 20 Apr 2021 10:33:07 +0000 (UTC) Date: Tue, 20 Apr 2021 11:33:06 +0100 From: Jonathan Wakely To: Patrick Palka Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: Re: [PATCH] libstdc++: Implement P2259R1 changes [PR95983] Message-ID: <20210420103306.GD3008@redhat.com> References: <20210420022521.518892-1-ppalka@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210420022521.518892-1-ppalka@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline X-Spam-Status: No, score=-14.0 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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Apr 2021 10:33:43 -0000 On 19/04/21 22:25 -0400, Patrick Palka via Libstdc++ wrote: >This implements the wording changes of P2259R1 "Repairing input range >adaptors and counted_iterator", which resolves LWG 3283, 3289 and 3408. > >The wording changes are relatively straightforward, but they require >some boilerplate to implement: the changes to make a type alias >"conditionally present" in some iterator class are realized by defining >a base class template and an appropriately constrained partial >specialization thereof that contains the type alias, and having the >iterator class derive from this base class. Sometimes the relevant >condition depend on members from the iterator class, but because a >class is incomplete when instantiating its bases, the constraints on >the partial specialization can't use anything from the iterator class. >This patch works around this by hoisting these members out to the >enclosing scope (e.g. transform_view::_Iterator::_Base is hoisted out >to transform_view::_Base so that transform_view::__iter_cat can use it). > >This patch also implements the proposed resolution of LWG 3291 to rename >iota_view::iterator_category to iota_view::iterator_concept, which was >previously problematic due to LWG 3408. > >Tested on x86_64-pc-linux-gnu. > >libstdc++-v3/ChangeLog: > > PR libstdc++/95983 > * include/bits/stl_iterator.h (__detail::__move_iter_cat): > Define. > (move_iterator): Derive from the above in C++20 in order to > conditionally define iterator_category as per P2259. > (move_iterator::__base_cat): No longer used, so remove. > (move_iterator::iterator_category): Remove in C++20. > (__detail::__common_iter_use_postfix_proxy): Define. > (common_iterator::_Proxy): Rename to ... > (common_iterator:__arrow_proxy): ... this. > (common_iterator::__postfix_proxy): Define as per P2259. > (common_iterator::operator->): Adjust. > (common_iterator::operator++): Adjust as per P2259. > (iterator_traits::_S_iter_cat): Define. > (iterator_traits::iterator_category): Change as > per P2259. > (__detail::__counted_iter_value_type): Define. > (__detail::__counted_iter_concept): Define. > (__detail::__counted_iter_cat): Define. > (counted_iterator): Derive from the above three classes in order > to conditionally define value_type, iterator_concept and > iterator category respectively as per P2259. > (counted_iterator::operator->): Define as per P2259. > (incrementable_traits): Remove as per P2259. > (iterator_traits): Adjust as per P2259. > * include/std/ranges (__detail::__iota_view_iter_cat): Define. > (iota_view::_Iterator): Derive from the above in order to > conditionally define iterator_category as per P2259. > (iota_view::_S_iter_cat): Rename to ... > (iota_view::_S_iter_concept): ... this. > (iota_view::iterator_concept): Use it to apply LWG 3291 changes. > (iota_view::iterator_category): Remove. > (__detail::__filter_view_iter_cat): Define. > (filter_view::_Iterator): Derive from the above in order to > conditionally define iterator_category as per P2259. > (filter_view::_Iterator): Move to struct __filter_view_iter_cat. > (filter_view::_Iterator::iterator_category): Remove. > (transform_view::_Base): Define. > (transform_view::__iter_cat): Define. > (transform_view::_Iterator): Derive from the above in order to > conditionally define iterator_category as per P2259. > (transform_view::_Iterator::_Base): Just alias > transform_view::_Base. > (transform_view::_Iterator::_S_iter_cat): Move to struct > transform_view::__iter_cat. > (transform_view::_Iterator::iterator_category): Remove. > (transform_view::_Sentinel::_Base): Just alias > transform_view::_Base. > (join_view::_Base): Define. > (join_view::_Outer_iter): Define. > (join_view::_Inner_iter): Define. > (join_view::_S_ref_is_glvalue): Define. > (join_view::__iter_cat): Define. > (join_view::_Iterator): Derive from it in order to conditionally > define iterator_category as per P2259. > (join_view::_Iterator::_Base): Just alias join_view::_Base. > (join_view::_Iterator::_S_ref_is_glvalue): Just alias > join_view::_S_ref_is_glvalue. > (join_view::_Iterator::_S_iter_cat): Move to struct > transform_view::__iter_cat. > (join_view::_Iterator::_Outer_iter): Just alias > join_view::_Outer_iter. > (join_view::_Iterator::_Inner_iter): Just alias > join_view::_Inner_iter. > (join_view::_Iterator::iterator_category): Remove. > (join_view::_Sentinel::_Base): Just alias join_view::_Base. > (__detail::__split_view_outer_iter_cat): Define. > (__detail::__split_view_inner_iter_cat): Define. > (split_view::_Base): Define. > (split_view::_Outer_iter): Derive from __split_view_outer_iter_cat > in order to conditionally define iterator_category as per P2259. > (split_view::_Outer_iter::iterator_category): Remove. > (split_view::_Inner_iter): Derive from __split_view_inner_iter_cat > in order to conditionally define iterator_category as per P2259. > (split_view::_Inner_iter::_S_iter_cat): Move to > __split_view_inner_iter_cat. > (split_view::_Inner_iter::iterator_category): Remove. > (elements_view::_Base): Define. > (elements_view::__iter_cat): Define. > (elements_view::_Iterator): Derive from the above in order to > conditionall define iterator_category as per P2259. > (elements_view::_Iterator::_Base): Just alias > elements_view::_Base. > (elements_view::_Iterator::_S_iter_concept) > (elements_view::_Iterator::iterator_concept): Define as per > P2259. > (elements_view::_Iterator::iterator_category): Remove. > (elements_view::_Sentinel::_Base): Just alias > elements_view::_Base. > * testsuite/24_iterators/headers/iterator/synopsis_c++20: Adjust > constraints on iterator_traits. > * testsuite/std/ranges/p2259.cc: New test. >--- > libstdc++-v3/include/bits/stl_iterator.h | 128 ++++++-- > libstdc++-v3/include/std/ranges | 299 ++++++++++++------ > .../headers/iterator/synopsis_c++20.cc | 1 + > libstdc++-v3/testsuite/std/ranges/p2259.cc | 91 ++++++ > 4 files changed, 412 insertions(+), 107 deletions(-) > create mode 100644 libstdc++-v3/testsuite/std/ranges/p2259.cc > >diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h >index dc8b101e8f8..049f83cff90 100644 >--- a/libstdc++-v3/include/bits/stl_iterator.h >+++ b/libstdc++-v3/include/bits/stl_iterator.h >@@ -1302,6 +1302,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > }; > #endif // C++20 > >+ namespace __detail >+ { >+#if __cplusplus > 201703L && __cpp_lib_concepts >+ template >+ struct __move_iter_cat >+ { }; >+ >+ template >+ requires requires { typename iterator_traits<_Iterator>::iterator_category; } >+ struct __move_iter_cat<_Iterator> >+ { >+ using iterator_category >+ = __clamp_iter_cat::iterator_category, >+ random_access_iterator_tag>; >+ }; >+#endif >+ } >+ > // 24.4.3 Move iterators > /** > * Class template move_iterator is an iterator adapter with the same >@@ -1313,13 +1331,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > */ > template > class move_iterator >+#if __cplusplus > 201703L && __cpp_lib_concepts >+ : public __detail::__move_iter_cat<_Iterator> >+#endif I really wish we didn't have to add base classes for these conditionally-present member types. It would be much nicer if we could have constrained alias-declarations e.g. using iterator_category requires (...) = ...;