From patchwork Fri Oct 1 19:42:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1535504 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=VsJdOaST; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HLgnY0FWpz9t54 for ; Sat, 2 Oct 2021 05:55:13 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6E10F3857411 for ; Fri, 1 Oct 2021 19:55:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E10F3857411 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1633118110; bh=nmu7W6CLg8ZbPieLnmxAeKNyy0+Toi2NQDA+E5lGuZY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=VsJdOaST3bCWl9OXhf+ILepfdl/IMw67CDn5nTKBopoe9skIx588Y2PtiwipmrqLd p0DZbOwHSPmjD39Yx3H4nuiZ0ROyF6kbzNSkI0625KzXvcGQ+53MM6AYl9zQnJfdhc Pd0M2xCMq1X2LegBIp2WgffuWbZjVx/t/iR+Zq/A= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 551873857831 for ; Fri, 1 Oct 2021 19:42:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 551873857831 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 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-Disposition: inline X-Spam-Status: No, score=-13.8 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=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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. 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