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()); +}