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 ESMTP id 518A43857830 for ; Fri, 1 Oct 2021 19:42:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 518A43857830 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-408-0KOJ6bxCO1apXt9LzRIn8A-1; Fri, 01 Oct 2021 15:42:23 -0400 X-MC-Unique: 0KOJ6bxCO1apXt9LzRIn8A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D1B1B1927802; Fri, 1 Oct 2021 19:42:22 +0000 (UTC) Received: from localhost (unknown [10.33.36.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 819EA5F4F0; Fri, 1 Oct 2021 19:42:22 +0000 (UTC) Date: Fri, 1 Oct 2021 20:42:21 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Simplify __normal_iterator converting constructor Message-ID: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="UfteVUxMdjZUPL/K" Content-Disposition: inline X-Spam-Status: No, score=-14.5 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_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Oct 2021 19:42:26 -0000 --UfteVUxMdjZUPL/K Content-Type: text/plain; charset=us-ascii Content-Disposition: inline This uses C++11 features to simplify the definition of the __normal_iterator constructor that allows converting from iterator to const_iterator. The previous definition relied on _Container::pointer which is present in std::vector and std::basic_string, but is not actually part of the container requirements. Removing the use of _Container::pointer and defining it in terms of is_convertible allows __normal_iterator to be used with new container types which do not define a pointer member. Specifically, this will allow it to be used in std::basic_stacktrace. In theory this will enable some conversions which were not previously permitted, for example __normal_iterator> can now be converted to __normal_iterator>. In practice this doesn't matter because the library never uses such types. In any case, allowing those conversions is consistent with the corresponding constructors of std::reverse_iterator and std::move_iterator. Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: * include/bits/stl_iterator.h (__normal_iterator): Simplify converting constructor and do not require _Container::pointer. Tested powerpc64le-linux. Committed to trunk. --UfteVUxMdjZUPL/K Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" commit fb4d55ef61ca3191ec946d4d41e0e715f4cc4197 Author: Jonathan Wakely Date: Thu May 6 13:44:36 2021 libstdc++: Simplify __normal_iterator converting constructor This uses C++11 features to simplify the definition of the __normal_iterator constructor that allows converting from iterator to const_iterator. The previous definition relied on _Container::pointer which is present in std::vector and std::basic_string, but is not actually part of the container requirements. Removing the use of _Container::pointer and defining it in terms of is_convertible allows __normal_iterator to be used with new container types which do not define a pointer member. Specifically, this will allow it to be used in std::basic_stacktrace. In theory this will enable some conversions which were not previously permitted, for example __normal_iterator> can now be converted to __normal_iterator>. In practice this doesn't matter because the library never uses such types. In any case, allowing those conversions is consistent with the corresponding constructors of std::reverse_iterator and std::move_iterator. Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: * include/bits/stl_iterator.h (__normal_iterator): Simplify converting constructor and do not require _Container::pointer. diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index 8517652a173..df774eeb63f 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -1022,6 +1022,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef std::iterator_traits<_Iterator> __traits_type; +#if __cplusplus >= 201103L + template + using __convertible_from + = std::__enable_if_t::value>; +#endif + public: typedef _Iterator iterator_type; typedef typename __traits_type::iterator_category iterator_category; @@ -1042,12 +1048,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _M_current(__i) { } // Allow iterator to const_iterator conversion +#if __cplusplus >= 201103L + template> + _GLIBCXX20_CONSTEXPR + __normal_iterator(const __normal_iterator<_Iter, _Container>& __i) + noexcept +#else + // N.B. _Container::pointer is not actually in container requirements, + // but is present in std::vector and std::basic_string. template - _GLIBCXX20_CONSTEXPR __normal_iterator(const __normal_iterator<_Iter, typename __enable_if< - (std::__are_same<_Iter, typename _Container::pointer>::__value), - _Container>::__type>& __i) _GLIBCXX_NOEXCEPT + (std::__are_same<_Iter, typename _Container::pointer>::__value), + _Container>::__type>& __i) +#endif : _M_current(__i.base()) { } // Forward iterator requirements --UfteVUxMdjZUPL/K--