From patchwork Thu Aug 25 15:39:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 767 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp300358wro; Thu, 25 Aug 2022 08:42:34 -0700 (PDT) X-Google-Smtp-Source: AA6agR6pt/LrxZMsgR/AU6ygF7tleS+qewusGZjMMWeERF44bc+WFSt5G/TY364V6/CDU6KALo2C X-Received: by 2002:a05:6402:2b8b:b0:43a:5475:f1ae with SMTP id fj11-20020a0564022b8b00b0043a5475f1aemr3629070edb.363.1661442154256; Thu, 25 Aug 2022 08:42:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661442154; cv=none; d=google.com; s=arc-20160816; b=GpuxPuWE+oOIjYrdv6kE8CGzA4Xj6x46MW3ZjkIHXbWsd3Y+3tW2zdvQVviXYps5sG dNs1vLvlY6qCtbzX6bE98doldcXSQ9VHkpCHVrnCgaGe6a3S5OpuYh3P8o3YwHuWyB8E k/BaeaeamuYvM4hDGcAmnRLN+M1GlJmmFOJuhijAZipxlV8ZM9hN37nQuVxltWNX/u2O 4m5uhPSsCXsB38UFs8U9E0kZbpLiDukeWNcwi4DmSlQQNpB8MWe9h3pjaHOY58BnfKvd Yf1UwygstIYTy1hxZ/8Vi5RCLtpbgSchIBiYj0WLb38gi+PCr2hN2BAgiRfLevz9ag85 ONeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=XFSBArmRVuSKfpxCOpwn2JghhHg5RdweiFL52SVx6fM=; b=VQoAnqh0QxxBd8016ORdaq9hVzdhBPrEclOQvh4EsDhizs9JvuPEbjS6D6c0AflIK+ Wpnp/mWge8sjm7HM0eC31gm/NJ0+IQcXlZHxKybThYxYcDhn9xt8WDbFvpw+paytxj4C jlzXUOANgd8i2MxZaOuqEDmNVG8edwWehMzb55/KA+mN2/3UWNRqd2qCvlaMqmYxJGYU QZpyqfiXbNgxTOVovV1HMoDesavdvN8ZtyUMhXtGA202c8Nuf7blXyHtSu9unkDvO+OE MgMIxuGZMtGBt4tC1RJpqAcxEVYwOcu7z6irjyntIMohDD53q6f8nn9VeRFSy5rXnr6Q ISvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="kP8rdX/L"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id l18-20020a056402255200b0043bee43477csi7504695edb.576.2022.08.25.08.42.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 08:42:34 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="kP8rdX/L"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EBD6838515FE for ; Thu, 25 Aug 2022 15:41:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EBD6838515FE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661442112; bh=XFSBArmRVuSKfpxCOpwn2JghhHg5RdweiFL52SVx6fM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=kP8rdX/LIhHcbTMUgC51ZTbUgkAoaJVtQgR6Xpeu/4AzE3uyRAZK/E7ZMmV/0nMfV C05WxaKy012Wnyb1BAcX9McUDREA/Y/qtTtBTPUTnCUHBLYUSfd6OPeuYU1B7rfI1z OLkeeNem7w2QxCGgZ4cGbxV/hpk52aK0nY+xXilU= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id A8A843851ABD for ; Thu, 25 Aug 2022 15:40:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A8A843851ABD Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-539-euRjtNyFM2eX_j6acO2OqQ-1; Thu, 25 Aug 2022 11:40:04 -0400 X-MC-Unique: euRjtNyFM2eX_j6acO2OqQ-1 Received: by mail-qv1-f70.google.com with SMTP id d10-20020a0cf6ca000000b00496744bc8e6so11837188qvo.2 for ; Thu, 25 Aug 2022 08:40:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=XFSBArmRVuSKfpxCOpwn2JghhHg5RdweiFL52SVx6fM=; b=JSDAkM1Kr7Oq+asH9egHSoFZBErSbILHGFPDzRE21q961K8l7zrkayAQA5Ir6B/Vvw E+N2RwdztwVGUYZV19ouiizxvBuwEERkBIq+TTmlRlHW1C++AayzVKJi3NlcTz13crq+ kPT9VYUXZXonkeW9xRmIe/hcIyqnGfsvaCUYSv5TMR51dfNGoIsP26MQyew5e7UO/8uy nIi0dKAd2cA6WZ1/3JhKuxh4oa5K1SaiDi3kBzZ1kWP07Sc6lCi7FXawnrtZsAqJjwdo VKabspH383DKOL10UcTDjaWWPPo4H6t79eIih7fT9jq6dVP929jgTCZzq/9RoyXTxla6 z3tw== X-Gm-Message-State: ACgBeo0DAfvi0f5tibRvTjmiF/htT86M/5UhyWLbj+wle9hz8we7ycds xt4vFkhYeIu9HzFmZHTM9iHSAec7O8l+h2x1+tb/rIQQlJ6befJ/NGrtifUgp2U9olGXHNA/KoJ rs0R3d8fvbI4EasI3TdD9X0iKQlayUqEqVgr7u+5Hl5ois5HYbSA0rL9mLG8YtOCdYPs= X-Received: by 2002:ac8:5dd3:0:b0:344:94e6:d667 with SMTP id e19-20020ac85dd3000000b0034494e6d667mr4140032qtx.409.1661442003589; Thu, 25 Aug 2022 08:40:03 -0700 (PDT) X-Received: by 2002:ac8:5dd3:0:b0:344:94e6:d667 with SMTP id e19-20020ac85dd3000000b0034494e6d667mr4139998qtx.409.1661442003137; Thu, 25 Aug 2022 08:40:03 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id j27-20020a05620a147b00b006ba9b2167a2sm16033677qkl.16.2022.08.25.08.40.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 08:40:02 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/2] libstdc++: Implement ranges::zip_transform_view from P2321R2 Date: Thu, 25 Aug 2022 11:39:37 -0400 Message-Id: <20220825153938.2249619-1-ppalka@redhat.com> X-Mailer: git-send-email 2.37.2.382.g795ea8776b MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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, KAM_NUMSUBJECT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1742148368184930162?= X-GMAIL-MSGID: =?utf-8?q?1742148368184930162?= Tested on x86_64-pc-linux-gnu, does this look OK for trunk? libstdc++-v3/ChangeLog: * include/std/ranges (zip_view::_Iterator): Befriend zip_transform_view. (__detail::__range_iter_cat): Define. (zip_transform_view): Define. (zip_transform_view::_Iterator): Define. (zip_transform_view::_Sentinel): Define. (views::__detail::__can_zip_transform_view): Define. (views::_ZipTransform): Define. (views::zip_transform): Define. * testsuite/std/ranges/zip_transform/1.cc: New test. --- libstdc++-v3/include/std/ranges | 343 ++++++++++++++++++ .../testsuite/std/ranges/zip_transform/1.cc | 108 ++++++ 2 files changed, 451 insertions(+) create mode 100644 libstdc++-v3/testsuite/std/ranges/zip_transform/1.cc diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index fb815c48f99..d748cb73346 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -4502,6 +4502,12 @@ namespace views::__adaptor return input_iterator_tag{}; } + template + requires (view<_Ws> && ...) && (sizeof...(_Ws) > 0) && is_object_v<_Fp> + && regular_invocable<_Fp&, range_reference_t<_Ws>...> + && std::__detail::__can_reference...>> + friend class zip_transform_view; + public: // iterator_category defined in __zip_view_iter_cat using iterator_concept = decltype(_S_iter_concept()); @@ -4781,6 +4787,343 @@ namespace views::__adaptor inline constexpr _Zip zip; } + + namespace __detail + { + template + using __range_iter_cat + = typename iterator_traits>>::iterator_category; + } + + template + requires (view<_Vs> && ...) && (sizeof...(_Vs) > 0) && is_object_v<_Fp> + && regular_invocable<_Fp&, range_reference_t<_Vs>...> + && std::__detail::__can_reference...>> + class zip_transform_view : public view_interface> + { + [[no_unique_address]] __detail::__box<_Fp> _M_fun; + zip_view<_Vs...> _M_zip; + + using _InnerView = zip_view<_Vs...>; + + template + using __ziperator = iterator_t<__detail::__maybe_const_t<_Const, _InnerView>>; + + template + using __zentinel = sentinel_t<__detail::__maybe_const_t<_Const, _InnerView>>; + + template + using _Base = __detail::__maybe_const_t<_Const, _InnerView>; + + template + struct __iter_cat + { }; + + template + requires forward_range<_Base<_Const>> + struct __iter_cat<_Const> + { + private: + static auto + _S_iter_cat() + { + using __detail::__maybe_const_t; + using __detail::__range_iter_cat; + using _Res = invoke_result_t<__maybe_const_t<_Const, _Fp>&, + range_reference_t<__maybe_const_t<_Const, _Vs>>...>; + if constexpr (!is_lvalue_reference_v<_Res>) + return input_iterator_tag{}; + else if constexpr ((derived_from<__range_iter_cat<_Vs, _Const>, + random_access_iterator_tag> && ...)) + return random_access_iterator_tag{}; + else if constexpr ((derived_from<__range_iter_cat<_Vs, _Const>, + bidirectional_iterator_tag> && ...)) + return bidirectional_iterator_tag{}; + else if constexpr ((derived_from<__range_iter_cat<_Vs, _Const>, + forward_iterator_tag> && ...)) + return forward_iterator_tag{}; + else + return input_iterator_tag{}; + } + public: + using iterator_category = decltype(_S_iter_cat()); + }; + + template class _Iterator; + template class _Sentinel; + + public: + zip_transform_view() = default; + + constexpr explicit + zip_transform_view(_Fp __fun, _Vs... __views) + : _M_fun(std::move(__fun)), _M_zip(std::move(__views)...) + { } + + constexpr auto + begin() + { return _Iterator(*this, _M_zip.begin()); } + + constexpr auto + begin() const + requires range + && regular_invocable...> + { return _Iterator(*this, _M_zip.begin()); } + + constexpr auto + end() + { + if constexpr (common_range<_InnerView>) + return _Iterator(*this, _M_zip.end()); + else + return _Sentinel(_M_zip.end()); + } + + constexpr auto + end() const + requires range + && regular_invocable...> + { + if constexpr (common_range) + return _Iterator(*this, _M_zip.end()); + else + return _Sentinel(_M_zip.end()); + } + + constexpr auto + size() requires sized_range<_InnerView> + { return _M_zip.size(); } + + constexpr auto + size() const requires sized_range + { return _M_zip.size(); } + }; + + template + zip_transform_view(_Fp, Rs&&...) -> zip_transform_view<_Fp, views::all_t...>; + + template + requires (view<_Vs> && ...) && (sizeof...(_Vs) > 0) && is_object_v<_Fp> + && regular_invocable<_Fp&, range_reference_t<_Vs>...> + && std::__detail::__can_reference...>> + template + class zip_transform_view<_Fp, _Vs...>::_Iterator : public __iter_cat<_Const> + { + using _Parent = __detail::__maybe_const_t<_Const, zip_transform_view>; + + _Parent* _M_parent = nullptr; + __ziperator<_Const> _M_inner; + + constexpr + _Iterator(_Parent& __parent, __ziperator<_Const> __inner) + : _M_parent(std::__addressof(__parent)), _M_inner(std::move(__inner)) + { } + + friend class zip_transform_view; + + public: + // iterator_category defined in zip_transform_view::__iter_cat + using iterator_concept = typename __ziperator<_Const>::iterator_concept; + using value_type + = remove_cvref_t&, + range_reference_t<__detail::__maybe_const_t<_Const, _Vs>>...>>; + using difference_type = range_difference_t<_Base<_Const>>; + + _Iterator() = default; + + constexpr + _Iterator(_Iterator __i) + requires _Const && convertible_to<__ziperator, __ziperator<_Const>> + : _M_parent(__i._M_parent), _M_inner(std::move(__i._M_inner)) + { } + + constexpr decltype(auto) + operator*() const + { + return std::apply([&](const auto&... __iters) -> decltype(auto) { + return std::__invoke(*_M_parent->_M_fun, *__iters...); + }, _M_inner._M_current); + } + + constexpr _Iterator& + operator++() + { + ++_M_inner; + return *this; + } + + constexpr void + operator++(int) + { + ++*this; + } + + constexpr _Iterator + operator++(int) requires forward_range<_Base<_Const>> + { + auto __tmp = *this; + ++*this; + return __tmp; + } + + constexpr _Iterator& + operator--() requires bidirectional_range<_Base<_Const>> + { + --_M_inner; + return *this; + } + + constexpr _Iterator + operator--(int) requires bidirectional_range<_Base<_Const>> + { + auto __tmp = *this; + --*this; + return __tmp; + } + + constexpr _Iterator& + operator+=(difference_type __x) requires random_access_range<_Base<_Const>> + { + _M_inner += __x; + return *this; + } + + constexpr _Iterator& + operator-=(difference_type __x) requires random_access_range<_Base<_Const>> + { + _M_inner -= __x; + return *this; + } + + constexpr decltype(auto) + operator[](difference_type __n) const requires random_access_range<_Base<_Const>> + { + return std::apply([&](const _Is&... __iters) -> decltype(auto) { + return std::__invoke(*_M_parent->_M_fun, __iters[iter_difference_t<_Is>(__n)]...); + }, _M_inner._M_current); + } + + friend constexpr bool + operator==(const _Iterator& __x, const _Iterator& __y) + requires equality_comparable<__ziperator<_Const>> + { return __x._M_inner == __y._M_inner; } + + friend constexpr bool + operator<(const _Iterator& __x, const _Iterator& __y) + requires random_access_range<_Base<_Const>> + { return __x._M_inner < __y._M_inner; } + + friend constexpr bool + operator>(const _Iterator& __x, const _Iterator& __y) + requires random_access_range<_Base<_Const>> + { return __x._M_inner > __y._M_inner; } + + friend constexpr bool + operator<=(const _Iterator& __x, const _Iterator& __y) + requires random_access_range<_Base<_Const>> + { return __x._M_inner <= __y._M_inner; } + + friend constexpr bool + operator>=(const _Iterator& __x, const _Iterator& __y) + requires random_access_range<_Base<_Const>> + { return __x._M_inner >= __y._M_inner; } + + friend constexpr auto + operator<=>(const _Iterator& __x, const _Iterator& __y) + requires random_access_range<_Base<_Const>> && three_way_comparable<__ziperator<_Const>> + { return __x._M_inner <=> __y._M_inner; } + + friend constexpr _Iterator + operator+(const _Iterator& __i, difference_type __n) + requires random_access_range<_Base<_Const>> + { return _Iterator(*__i._M_parent, __i._M_inner + __n); } + + friend constexpr _Iterator + operator+(difference_type __n, const _Iterator& __i) + requires random_access_range<_Base<_Const>> + { return _Iterator(*__i._M_parent, __i._M_inner + __n); } + + friend constexpr _Iterator + operator-(const _Iterator& __i, difference_type __n) + requires random_access_range<_Base<_Const>> + { return _Iterator(*__i._M_parent, __i._M_inner - __n); } + + friend constexpr difference_type + operator-(const _Iterator& __x, const _Iterator& __y) + requires sized_sentinel_for<__ziperator<_Const>, __ziperator<_Const>> + { return __x._M_inner - __y._M_inner; } + }; + + template + requires (view<_Vs> && ...) && (sizeof...(_Vs) > 0) && is_object_v<_Fp> + && regular_invocable<_Fp&, range_reference_t<_Vs>...> + && std::__detail::__can_reference...>> + template + class zip_transform_view<_Fp, _Vs...>::_Sentinel + { + __zentinel<_Const> _M_inner; + + constexpr explicit + _Sentinel(__zentinel<_Const> __inner) + : _M_inner(__inner) + { } + + friend class zip_transform_view; + + public: + _Sentinel() = default; + + constexpr + _Sentinel(_Sentinel __i) + requires _Const && convertible_to<__zentinel, __zentinel<_Const>> + : _M_inner(std::move(__i._M_inner)) + { } + + template + requires sentinel_for<__zentinel<_Const>, __ziperator> + friend constexpr bool + operator==(const _Iterator& __x, const _Sentinel& __y) + { return __x._M_inner == __y._M_inner; } + + template + requires sized_sentinel_for<__zentinel<_Const>, __ziperator> + friend constexpr range_difference_t<__detail::__maybe_const_t> + operator-(const _Iterator& __x, const _Sentinel& __y) + { return __x._M_inner - __y._M_inner; } + + template + requires sized_sentinel_for<__zentinel<_Const>, __ziperator> + friend constexpr range_difference_t<__detail::__maybe_const_t> + operator-(const _Sentinel& __x, const _Iterator& __y) + { return __x._M_inner - __y._M_inner; } + }; + + namespace views + { + namespace __detail + { + template + concept __can_zip_transform_view + = requires { zip_transform_view(std::declval<_Fp>(), std::declval<_Ts>()...); }; + } + + struct _ZipTransform + { + template + requires (sizeof...(_Ts) == 0) || __detail::__can_zip_transform_view<_Fp, _Ts...> + [[nodiscard]] + constexpr auto + operator()(_Fp&& __f, _Ts&&... __ts) const + { + if constexpr (sizeof...(_Ts) == 0) + return views::empty>>; + else + return zip_transform_view(std::forward<_Fp>(__f), std::forward<_Ts>(__ts)...); + } + }; + + inline constexpr _ZipTransform zip_transform; + } #endif // C++23 } // namespace ranges diff --git a/libstdc++-v3/testsuite/std/ranges/zip_transform/1.cc b/libstdc++-v3/testsuite/std/ranges/zip_transform/1.cc new file mode 100644 index 00000000000..5ea24c578a8 --- /dev/null +++ b/libstdc++-v3/testsuite/std/ranges/zip_transform/1.cc @@ -0,0 +1,108 @@ +// { dg-options "-std=gnu++23" } +// { dg-do run { target c++23 } } + +#include +#include +#include +#include +#include + +namespace ranges = std::ranges; +namespace views = std::views; + +constexpr bool +test01() +{ + static_assert(ranges::empty(views::zip_transform([] { return 0; }))); + + auto z1 = views::zip_transform(std::identity{}, + std::array{1, 2, 3}); + VERIFY( ranges::equal(z1, (int[]){1, 2, 3}) ); + const auto i0 = z1.begin(), i1 = z1.begin() + 1; + VERIFY( i0 + 1 - 1 == i0 ); + VERIFY( i0 < i1 ); + VERIFY( i1 < z1.end() ); + VERIFY( i1 - i0 == 1 ); + VERIFY( i0 - i1 == -1 ); + VERIFY( z1.end() - i1 == 2 ); + VERIFY( i1 - z1.end() == -2 ); + ranges::iter_swap(i0, i1); + VERIFY( ranges::equal(std::move(z1), (int[]){2, 1, 3}) ); + + auto z2 = views::zip_transform(std::multiplies{}, + std::array{-1, 2}, + std::array{3, 4, 5}); + auto i2 = z2.begin(); + i2 += 1; + i2 -= -1; + VERIFY( i2 == z2.end() ); + VERIFY( ranges::size(z2) == 2 ); + VERIFY( ranges::size(std::as_const(z2)) == 2 ); + VERIFY( ranges::equal(z2, (int[]){-3, 8}) ); + + auto z3 = views::zip_transform([] (auto... xs) { return ranges::max({xs...}); }, + std::array{1, 6, 7, 0, 0}, + std::array{2, 5, 9}, + std::array{3, 4, 8, 0}); + VERIFY( ranges::size(z3) == 3 ); + VERIFY( ranges::equal(z3, (int[]){3, 6, 9}) ); + + return true; +} + +constexpr bool +test02() +{ + using __gnu_test::test_input_range; + using __gnu_test::test_forward_range; + using __gnu_test::test_random_access_range; + + using ty1 = ranges::zip_transform_view, + views::all_t>, + views::all_t>>; + static_assert(ranges::forward_range); + static_assert(!ranges::random_access_range); + static_assert(!ranges::sized_range); + + using ty2 = ranges::zip_transform_view>, + views::all_t>, + views::all_t>>; + static_assert(ranges::input_range); + static_assert(!ranges::forward_range); + static_assert(!ranges::sized_range); + + return true; +} + +constexpr bool +test03() +{ + int u[] = {1, 2, 3, 4}, v[] = {4, 5, 6}; + auto z = views::zip_transform(std::plus{}, + u | views::filter([](auto) { return true; }), + v); + using ty = decltype(z); + static_assert(ranges::forward_range); + static_assert(!ranges::common_range); + static_assert(!ranges::sized_range); + VERIFY( z.begin() == z.begin() ); + VERIFY( z.begin() != z.end() ); + VERIFY( ranges::next(z.begin(), 3) == z.end() ); + auto it = z.begin(); + ++it; + it++; + it--; + --it; + VERIFY( it == z.begin() ); + + return true; +} + +int +main() +{ + static_assert(test01()); + static_assert(test02()); + static_assert(test03()); +} From patchwork Thu Aug 25 15:39:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 766 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp300104wro; Thu, 25 Aug 2022 08:41:57 -0700 (PDT) X-Google-Smtp-Source: AA6agR5x79OlbzmJTE/o+57kCVuXzPRq70hc8Lf7G4yNBZVYfGY5PsCZQ5/nPHZvFfmFFwklScFh X-Received: by 2002:a05:6402:3583:b0:43d:6943:44a with SMTP id y3-20020a056402358300b0043d6943044amr3607154edc.409.1661442117411; Thu, 25 Aug 2022 08:41:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661442117; cv=none; d=google.com; s=arc-20160816; b=kdMqMdYPHFzUSrtxWCXvZDud3+2UrTJtAcVC8UBempxPbILu0UMpJGqflrY5KhcD2M JoooTwnX7cb5dZgQJCsub6t7xak48Tg7Anes0ko79VEq+F/lhGZAi6ykua71rn9YctLw sOy4DkPdt1wclIvi4Bc9dipRDsxaAqtdkLNWausqTAGKLblDWEub361jYwSBADAu6C/x qTgeI1iIW9ZCKo+pAuE8LeoAcZPB/uqq0sc4gCc3gj3Wj3L4JsO5L7esCuk7BmliRGUl La6n2/NnRjdzEtv1qpVZB6KpeadGkqo+87rdFtFTYpXAShzEdG5EpA/u5x+qhNTn2J/R OG3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=zRMjThG9807+WKyva0WSMVl57g7gmrZNyZ0JE2yJTxs=; b=p1Cv0BkVxeHlLOphJRKslrI3A9QaCYI6qNGzk78yoJuDuzyk/j7MA34T+AFYnSkd8D 2fk4t8CH/vOcjeasU5phnYlbDRuncbCERP3/l8TCNgKqcE1v0K/+CqZ9PsUBfwaqKaOn mHkqbWg/v/TWt20SZD4s0oHt1jZRPN3MDUpYMDvT8Eo+zB8jrPxxfvEiCIHh+Zw6xD/z oNMoYWc3a7qqS1dNuVFxuEWPAn0lu1bn4qTFwzrCvktQR2+wUKK6FROna0eOtB6mvpRf srIhFesAT14crt+aVDEJGh79QFYP9Gddsa/Etp70xIjTSETogDJP+noFbkOQl+h5Paie X8LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Hx0MrusM; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id tl24-20020a170907c31800b0072af6e1fff0si3257836ejc.330.2022.08.25.08.41.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 08:41:57 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Hx0MrusM; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 291D03851A95 for ; Thu, 25 Aug 2022 15:40:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 291D03851A95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661442054; bh=zRMjThG9807+WKyva0WSMVl57g7gmrZNyZ0JE2yJTxs=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Hx0MrusMsBeT3gQZNR43YXtcOh7c3xGbBSsVclRjxRzYdgBibbs/dH4FTt/VVy6z1 92cmFDJ5I3LrNznbuE4jBdPEqLAXfo8/8Oh5vnRmKA+ojP0xiCwwM++KJFdBm8Rlps 5bKmh8pJqUFGdZtYKJHq4avNncA5drylxk7pkbVs= 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 ESMTPS id C985438515F3 for ; Thu, 25 Aug 2022 15:40:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C985438515F3 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-346-mP1X8OIwPG6VVjJ8mABttA-1; Thu, 25 Aug 2022 11:40:05 -0400 X-MC-Unique: mP1X8OIwPG6VVjJ8mABttA-1 Received: by mail-qk1-f199.google.com with SMTP id l15-20020a05620a28cf00b006b46997c070so17777727qkp.20 for ; Thu, 25 Aug 2022 08:40:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=zRMjThG9807+WKyva0WSMVl57g7gmrZNyZ0JE2yJTxs=; b=p48C7GKP6Ji3h8IsBtDDwdML9ay1KnWQqiiGfzEyaNxexIhqNBNIW6ol6PBO0a6oio K9Yp4qocUXQntsFzpiCPzecoMS444X7k/2iK4D+9jUmGY1tO8AYUmgpKhe5aDkCwOzgs /ncE9kW6HrzUHdsZSSqeQB3Z+ISsP2olI+kMhxOu7Aj3y4wG82mWmnDKCyuPq8AdZ7Iv b+N+kLWQxPucgGJHNBJKPwUfL8I79nGWSgnBgOuHDtQXwYifrJ0IDeUZ/YxntVFdgYA5 jUTcp281vXtQ85VHWnWUvUHu2JVq1fKtB5mEkVTDUADJgIyq0GAAb0L/+gCxgy8BzkaG 3Yjg== X-Gm-Message-State: ACgBeo3yIRZZBNqCHJ2ssOLwLGshzHcWJvg8tBkmqmZ/PszxzA7s7s8y o4+UNimlx1KyEUjEX3lnHrdrfz5gxSzRTCux6Xlv7OVmoQbh2SMhR49uvJpbzLSr2ttMTiT2l3x yAfgJzfqcmvTcC4BNn38aToEGq8EPPI6KO7P8EvNznoOtRNOFg8UA9UDPmif6CHMmhAQ= X-Received: by 2002:a05:620a:450e:b0:6bb:a4cf:de01 with SMTP id t14-20020a05620a450e00b006bba4cfde01mr3532931qkp.636.1661442004631; Thu, 25 Aug 2022 08:40:04 -0700 (PDT) X-Received: by 2002:a05:620a:450e:b0:6bb:a4cf:de01 with SMTP id t14-20020a05620a450e00b006bba4cfde01mr3532920qkp.636.1661442004356; Thu, 25 Aug 2022 08:40:04 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id j27-20020a05620a147b00b006ba9b2167a2sm16033677qkl.16.2022.08.25.08.40.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 08:40:04 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/2] libstdc++: Implement LWG 3692/3702 changes to zip_/zip_transform_view Date: Thu, 25 Aug 2022 11:39:38 -0400 Message-Id: <20220825153938.2249619-2-ppalka@redhat.com> X-Mailer: git-send-email 2.37.2.382.g795ea8776b In-Reply-To: <20220825153938.2249619-1-ppalka@redhat.com> References: <20220825153938.2249619-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1742148329519186599?= X-GMAIL-MSGID: =?utf-8?q?1742148329519186599?= Tested on x86_64-pc-linux-gnu, does this look OK for trunk? libstdc++-v3/ChangeLog: * include/std/ranges (zip_view::_Iterator::operator<): Remove. (zip_view::_Iterator::operator>): Remove. (zip_view::_Iterator::operator<=): Remove. (zip_view::_Iterator::operator>=): Remove. (zip_view::_Iterator::operator<=>): Remove three_way_comparable constraint. (zip_transform_view::_Iterator): Ditto. --- libstdc++-v3/include/std/ranges | 43 +-------------------------------- 1 file changed, 1 insertion(+), 42 deletions(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index d748cb73346..bf0ff29c38c 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -4616,30 +4616,9 @@ namespace views::__adaptor }(make_index_sequence{}); } - friend constexpr bool - operator<(const _Iterator& __x, const _Iterator& __y) - requires __detail::__all_random_access<_Const, _Vs...> - { return __x._M_current < __y._M_current; } - - friend constexpr bool - operator>(const _Iterator& __x, const _Iterator& __y) - requires __detail::__all_random_access<_Const, _Vs...> - { return __y < __x; } - - friend constexpr bool - operator<=(const _Iterator& __x, const _Iterator& __y) - requires __detail::__all_random_access<_Const, _Vs...> - { return !(__y < __x); } - - friend constexpr bool - operator>=(const _Iterator& __x, const _Iterator& __y) - requires __detail::__all_random_access<_Const, _Vs...> - { return !(__x < __y); } - friend constexpr auto operator<=>(const _Iterator& __x, const _Iterator& __y) requires __detail::__all_random_access<_Const, _Vs...> - && (three_way_comparable>> && ...) { return __x._M_current <=> __y._M_current; } friend constexpr _Iterator @@ -5008,29 +4987,9 @@ namespace views::__adaptor requires equality_comparable<__ziperator<_Const>> { return __x._M_inner == __y._M_inner; } - friend constexpr bool - operator<(const _Iterator& __x, const _Iterator& __y) - requires random_access_range<_Base<_Const>> - { return __x._M_inner < __y._M_inner; } - - friend constexpr bool - operator>(const _Iterator& __x, const _Iterator& __y) - requires random_access_range<_Base<_Const>> - { return __x._M_inner > __y._M_inner; } - - friend constexpr bool - operator<=(const _Iterator& __x, const _Iterator& __y) - requires random_access_range<_Base<_Const>> - { return __x._M_inner <= __y._M_inner; } - - friend constexpr bool - operator>=(const _Iterator& __x, const _Iterator& __y) - requires random_access_range<_Base<_Const>> - { return __x._M_inner >= __y._M_inner; } - friend constexpr auto operator<=>(const _Iterator& __x, const _Iterator& __y) - requires random_access_range<_Base<_Const>> && three_way_comparable<__ziperator<_Const>> + requires random_access_range<_Base<_Const>> { return __x._M_inner <=> __y._M_inner; } friend constexpr _Iterator