From patchwork Tue Jun 15 18:27:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1492408 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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=) Authentication-Results: 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=E73+BmCD; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4G4H092N1Gz9sWX for ; Wed, 16 Jun 2021 04:29:12 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EFD273839C74 for ; Tue, 15 Jun 2021 18:29:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EFD273839C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1623781747; bh=PEJS8yy92voKRW1EGrgeKAmJwfn9ugzwNlAlWLdIJu8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=E73+BmCD6Gl7y+udQXWvFg41Y4Po0K6rrZEop1gdM7qBj8FZpNpjwPCIn5v6i7OcJ aEq5wlRX89LKxmswR/5HcP/BxCbPQ45Ivj6HdagStprRX2AtDw5T7qG2kC6yEhw84J 6ww6niSbzrvUxcNl/EoygNgf+hHC/k+AM8ZcamsQ= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id A7CF33840036 for ; Tue, 15 Jun 2021 18:27:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A7CF33840036 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-125-Ruvnfz4zOF2YQMfbaqGMEQ-1; Tue, 15 Jun 2021 14:27:51 -0400 X-MC-Unique: Ruvnfz4zOF2YQMfbaqGMEQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5D7A41084F40; Tue, 15 Jun 2021 18:27:50 +0000 (UTC) Received: from localhost (unknown [10.33.36.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id EDDBB18AAB; Tue, 15 Jun 2021 18:27:49 +0000 (UTC) Date: Tue, 15 Jun 2021 19:27:48 +0100 To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Use function object for __decay_copy helper Message-ID: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-13.9 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-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" By changing __cust_access::__decay_copy from a function template to a function object we avoid ADL. That means it's fine to call it unqualified (the compiler won't waste time doing ADL in associated namespaces, and won't try to complete associated types). This also makes some other minor simplications to other concepts for the [range.access] CPOs. Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: * include/bits/iterator_concepts.h (__cust_access::__decay_copy): Replace with function object. (__cust_access::__member_begin, ___cust_access::_adl_begin): Use __decay_copy unqualified. * include/bits/ranges_base.h (__member_end, __adl_end): Likewise. Use __range_iter_t for type of ranges::begin. (__member_rend): Use correct value category for rbegin argument. (__member_data): Use __decay_copy unqualified. (__begin_data): Use __range_iter_t for type of ranges::begin. Tested powerpc64le-linux. Committed to trunk. commit cb326a6442f09cb36b05ce556fc91e10bfeb0cf6 Author: Jonathan Wakely Date: Tue Jun 15 14:39:02 2021 libstdc++: Use function object for __decay_copy helper By changing __cust_access::__decay_copy from a function template to a function object we avoid ADL. That means it's fine to call it unqualified (the compiler won't waste time doing ADL in associated namespaces, and won't try to complete associated types). This also makes some other minor simplications to other concepts for the [range.access] CPOs. Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: * include/bits/iterator_concepts.h (__cust_access::__decay_copy): Replace with function object. (__cust_access::__member_begin, ___cust_access::_adl_begin): Use __decay_copy unqualified. * include/bits/ranges_base.h (__member_end, __adl_end): Likewise. Use __range_iter_t for type of ranges::begin. (__member_rend): Use correct value category for rbegin argument. (__member_data): Use __decay_copy unqualified. (__begin_data): Use __range_iter_t for type of ranges::begin. diff --git a/libstdc++-v3/include/bits/iterator_concepts.h b/libstdc++-v3/include/bits/iterator_concepts.h index 8723f35c5cb..d18ae32bf20 100644 --- a/libstdc++-v3/include/bits/iterator_concepts.h +++ b/libstdc++-v3/include/bits/iterator_concepts.h @@ -930,17 +930,18 @@ namespace ranges { using std::__detail::__class_or_enum; - template - constexpr decay_t<_Tp> - __decay_copy(_Tp&& __t) - noexcept(is_nothrow_convertible_v<_Tp, decay_t<_Tp>>) - { return std::forward<_Tp>(__t); } + struct { + template + constexpr decay_t<_Tp> + operator()(_Tp&& __t) const + noexcept(is_nothrow_convertible_v<_Tp, decay_t<_Tp>>) + { return std::forward<_Tp>(__t); } + } inline constexpr __decay_copy{}; template concept __member_begin = requires(_Tp& __t) { - { __cust_access::__decay_copy(__t.begin()) } - -> input_or_output_iterator; + { __decay_copy(__t.begin()) } -> input_or_output_iterator; }; // Poison pills so that unqualified lookup doesn't find std::begin. @@ -951,8 +952,7 @@ namespace ranges concept __adl_begin = __class_or_enum> && requires(_Tp& __t) { - { __cust_access::__decay_copy(begin(__t)) } - -> input_or_output_iterator; + { __decay_copy(begin(__t)) } -> input_or_output_iterator; }; // Simplified version of std::ranges::begin that only supports lvalues, diff --git a/libstdc++-v3/include/bits/ranges_base.h b/libstdc++-v3/include/bits/ranges_base.h index 3bc657ca17e..a63ef8eb7f4 100644 --- a/libstdc++-v3/include/bits/ranges_base.h +++ b/libstdc++-v3/include/bits/ranges_base.h @@ -89,6 +89,7 @@ namespace ranges namespace __cust_access { using std::ranges::__detail::__maybe_borrowed_range; + using std::__detail::__range_iter_t; struct _Begin { @@ -127,8 +128,7 @@ namespace ranges template concept __member_end = requires(_Tp& __t) { - { __decay_copy(__t.end()) } - -> sentinel_for(__t)))>; + { __decay_copy(__t.end()) } -> sentinel_for<__range_iter_t<_Tp>>; }; // Poison pills so that unqualified lookup doesn't find std::end. @@ -139,8 +139,7 @@ namespace ranges concept __adl_end = __class_or_enum> && requires(_Tp& __t) { - { __decay_copy(end(__t)) } - -> sentinel_for(__t)))>; + { __decay_copy(end(__t)) } -> sentinel_for<__range_iter_t<_Tp>>; }; struct _End @@ -281,7 +280,7 @@ namespace ranges concept __member_rend = requires(_Tp& __t) { { __decay_copy(__t.rend()) } - -> sentinel_for; + -> sentinel_for(__t)))>; }; void rend(auto&) = delete; @@ -507,12 +506,11 @@ namespace ranges template concept __member_data = requires(_Tp& __t) { - { __cust_access::__decay_copy(__t.data()) } -> __pointer_to_object; + { __decay_copy(__t.data()) } -> __pointer_to_object; }; template - concept __begin_data = requires(_Tp& __t) - { { _Begin{}(__t) } -> contiguous_iterator; }; + concept __begin_data = contiguous_iterator<__range_iter_t<_Tp>>; struct _Data {