From patchwork Wed Aug 26 20:44:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1352135 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@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org 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=F2JVy0oR; 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 4BcHtH6HHXz9sSJ for ; Thu, 27 Aug 2020 06:45:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8D0C9384B106; Wed, 26 Aug 2020 20:45:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D0C9384B106 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1598474706; bh=HL6znK8nZJFfdd0cnwcw1ZGewGYxFnVG7wE/vpialrE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=F2JVy0oROxEk571jGQZE9qASfNRc4ZBiqqamR7GuZeh3UgDKGZKy9QEAIHYqlo2wl 1RT9pNswdmzxw7+PyqfX6uYBqcq3o5PVMLhGjrQNp6YPBgEkeRkBuAaatl0pjrlcvM 1caokZFp2gTlqgiVzz4ROBE5QXoVutcJ2909BYmI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by sourceware.org (Postfix) with ESMTP id 1FD0D38618F9 for ; Wed, 26 Aug 2020 20:45:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1FD0D38618F9 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-232-Sf3p1rDGONCB9penStsvMQ-1; Wed, 26 Aug 2020 16:44:59 -0400 X-MC-Unique: Sf3p1rDGONCB9penStsvMQ-1 Received: by mail-qv1-f70.google.com with SMTP id y7so2559821qvj.11 for ; Wed, 26 Aug 2020 13:44:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HL6znK8nZJFfdd0cnwcw1ZGewGYxFnVG7wE/vpialrE=; b=hUVgmM2gFUnchr8NRlGDvKFCxTwL9RPeSaeaaRpcb7FnljsesonJJvwt2/Hv+c7n7p X4k5DgEXriuXGPvY2w6VYMwzLygHr/ldPELN5nYZ9met+7XSd1EjFJuFo0t+6Pi9ZHKw VnoKZDLAeuMPqrMuz5bW4SArWJDtPLN3ba6G/rz3irW/xFsostLkBabY38eJvIiiPBwX 8L0qKEawulUFhJiMUvKKSEzb/xnQDWzsHF4GQ857zGSrhssYy6diPIa/WGMmDwWEFlRl yWhCuOhDgCT4tnar1d8GevRrdsAWlBM95bTyQ0pssWAck5bVKLbaqKjdIaAg9Ks8U496 MkFw== X-Gm-Message-State: AOAM532sM7dxt2lpxecxlknJZjYgTIndK5SHmxhB7On5zpa8P0WBw8y2 m7lX2VTPxRtUZRKekvYa8LVk2xlvNVlYdUDeCNyW/31ekza0+BEMda07BE6l2zI08UTzBt/ijDR 9uJ4jX/QcTH4yLny3iw== X-Received: by 2002:ac8:7298:: with SMTP id v24mr7564959qto.198.1598474698968; Wed, 26 Aug 2020 13:44:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHfYpd/gT+Ka4UbJLWlUZyqQGdXq5XGo0+uNl9/h5ntSp4NMDu1x+GVjJpA9i3SBTLeBCYRA== X-Received: by 2002:ac8:7298:: with SMTP id v24mr7564948qto.198.1598474698720; Wed, 26 Aug 2020 13:44:58 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id h20sm131580qkk.79.2020.08.26.13.44.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Aug 2020 13:44:58 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/3] libstdc++: Implement P1994R1 changes to ranges::elements_view Date: Wed, 26 Aug 2020 16:44:52 -0400 Message-Id: <20200826204454.1375362-1-ppalka@redhat.com> X-Mailer: git-send-email 2.28.0.337.ge9b77c84a0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0.0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-16.4 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_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: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Cc: libstdc++@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" The example from the paper doesn't compile without the proposed resolution for LWG 3406, so we'll add a testcase for this once the proposed resolution is in. libstdc++-v3/ChangeLog: P1994R1: elements_view needs its own sentinel. * include/std/ranges (elements_view::end): Replace these two overloads with four new overloads. (elements_view::_Iterator::operator==): Remove. (elements_view::_Iterator::operator-): Likewise. (elements_view::_Sentinel): Define. --- libstdc++-v3/include/std/ranges | 74 ++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 14 deletions(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 9d22b138082..efa8d2cf9f4 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -3366,12 +3366,20 @@ namespace views { return _Iterator(ranges::begin(_M_base)); } constexpr auto - end() requires (!__detail::__simple_view<_Vp>) - { return ranges::end(_M_base); } + end() + { return _Sentinel{ranges::end(_M_base)}; } constexpr auto - end() const requires __detail::__simple_view<_Vp> - { return ranges::end(_M_base); } + end() requires common_range<_Vp> + { return _Iterator{ranges::end(_M_base)}; } + + constexpr auto + end() const requires range + { return _Sentinel{ranges::end(_M_base)}; } + + constexpr auto + end() const requires common_range + { return _Iterator{ranges::end(_M_base)}; } constexpr auto size() requires sized_range<_Vp> @@ -3382,6 +3390,9 @@ namespace views { return ranges::size(_M_base); } private: + template + struct _Sentinel; + template struct _Iterator { @@ -3484,10 +3495,6 @@ namespace views requires equality_comparable> { return __x._M_current == __y._M_current; } - friend constexpr bool - operator==(const _Iterator& __x, const sentinel_t<_Base>& __y) - { return __x._M_current == __y; } - friend constexpr bool operator<(const _Iterator& __x, const _Iterator& __y) requires random_access_range<_Base> @@ -3536,15 +3543,54 @@ namespace views requires random_access_range<_Base> { return __x._M_current - __y._M_current; } - friend constexpr difference_type - operator-(const _Iterator<_Const>& __x, const sentinel_t<_Base>& __y) + friend _Sentinel<_Const>; + }; + + template + struct _Sentinel + { + private: + constexpr bool + _M_equal(const _Iterator<_Const>& __x) const + { return __x._M_current == _M_end; } + + using _Base = __detail::__maybe_const_t<_Const, _Vp>; + sentinel_t<_Base> _M_end = sentinel_t<_Base>(); + + public: + _Sentinel() = default; + + constexpr explicit + _Sentinel(sentinel_t<_Base> __end) + : _M_end(std::move(__end)) + { } + + constexpr + _Sentinel(_Sentinel __other) + requires _Const + && convertible_to, sentinel_t<_Base>> + : _M_end(std::move(__other._M_end)) + { } + + constexpr sentinel_t<_Base> + base() const + { return _M_end; } + + friend constexpr bool + operator==(const _Iterator<_Const>& __x, const _Sentinel& __y) + { return __y._M_equal(__x); } + + friend constexpr range_difference_t<_Base> + operator-(const _Iterator<_Const>& __x, const _Sentinel& __y) requires sized_sentinel_for, iterator_t<_Base>> - { return __x._M_current - __y; } + { return __x._M_current - __y._M_end; } - friend constexpr difference_type - operator-(const sentinel_t<_Base>& __x, const _Iterator<_Const>& __y) + friend constexpr range_difference_t<_Base> + operator-(const _Sentinel& __x, const _Iterator<_Const>& __y) requires sized_sentinel_for, iterator_t<_Base>> - { return -(__y - __x); } + { return __x._M_end - __y._M_current; } + + friend _Sentinel; }; _Vp _M_base = _Vp();