From patchwork Tue Aug 30 17:13:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 845 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp1901481wro; Tue, 30 Aug 2022 10:14:54 -0700 (PDT) X-Google-Smtp-Source: AA6agR51coyK9oiSUSxxFQg7Rr2peDfJZzvnE9QQXDXm2DyGQoFri+C78wPVC5KBI/xVMfdaICSc X-Received: by 2002:a17:907:7f02:b0:73d:dffa:57b3 with SMTP id qf2-20020a1709077f0200b0073ddffa57b3mr15263612ejc.19.1661879694353; Tue, 30 Aug 2022 10:14:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661879694; cv=none; d=google.com; s=arc-20160816; b=0NshcquYc1Yb7qHToA2BT8KIXkWs9raQbApd88CVPJw4OkRvn4qSLiM8DZtM4AUjlm GDSGe/VH/51syMrB0cIx2ESTU49pvc+iux7i3uG3yR5ucwBF64yEuQBzBnUyIFHVWv4n LHEZnd7+qGLkj0f6YRoyBuv0WT2HC7QyvZuffKYc2tFm5VqqAkUYSNldfcMO+KdutvVf u0spp8MBLOis5XgGB/pW2xTRSmg9ZmHvQ2rgiaS5ybEkLiwNz3raBWiw8g84L9Nw9n1h Lqw2+40LPaloVBfe8Lv4HRc9AAYgpP23qsgEEJqKQI2uD4n6z0MpYXLZ+x/0A4qSst/a egTg== 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=CsIaBRq/QLDou+AKhA6xuaJY8k9MTzjX+8a/OJcjiYU=; b=uJvdZBbPKPj7KQ6IBDPMuSM/OtNgztBsdOV29FuddoVYbGGlsgFfqRiqwi0yJ43bHn RrpxaopJaAEa+OJzV0R5RM/GxnuMyqgAEz0SIrL4XHfI9ADosKxtndjl4IxNNsdi2MlO v9HRtJQ+DGJ14AR52M1N3mhCgn7Mjg7SPz1ZcMdpObNaItIdBo4IX0FwoGkF8o3N5MH8 PF+BMDeVlf+jg1fEh2j1c0x2TzlTYDC0gm5iMgO1xJti+Q/MbAPdWXB8Z/JsXB80Fgem 4P1v50DSszg0/ConcA0pNbUOAzOAskhw9Bj9Vyr22KLor5uxXL/3lfx2Cgvcjnc84tiB RcdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=iyQCmlvR; 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 go19-20020a1709070d9300b007416e100f3dsi3147974ejc.986.2022.08.30.10.14.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Aug 2022 10:14:54 -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=iyQCmlvR; 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 1CCA73AA800D for ; Tue, 30 Aug 2022 17:14:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1CCA73AA800D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661879668; bh=CsIaBRq/QLDou+AKhA6xuaJY8k9MTzjX+8a/OJcjiYU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=iyQCmlvRlirMwXv0056YxcNAHTu4ZUTznvwC0N+0z2MoU4NplFMQwMXDhZ3NtSbv/ Y+GQMLq6QGjcpbxevuIC2Sp2PDYWBgrGgFK3s52Enp0U6QnIW8Za9WkTQ+fCPr6qFa LbmQ/clRcPLe8TBfKlch2Y3qZBDcbDjNO6jJ54ZM= 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 4BFF3385C401 for ; Tue, 30 Aug 2022 17:13:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4BFF3385C401 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-440-Zn9NwhtxNT284ixmPSS-Ew-1; Tue, 30 Aug 2022 13:13:40 -0400 X-MC-Unique: Zn9NwhtxNT284ixmPSS-Ew-1 Received: by mail-qk1-f197.google.com with SMTP id j13-20020a05620a288d00b006be7b2a758fso5803425qkp.1 for ; Tue, 30 Aug 2022 10:13:40 -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:subject:date; bh=CsIaBRq/QLDou+AKhA6xuaJY8k9MTzjX+8a/OJcjiYU=; b=I7l1RgVRSaHn/nTcRp4PS9NBm0GYZahKIUQgPSSPD7dOXttCopeEfero/l7DxnFBbu dHo6p/iM1GCjSWDSc7SiC9/mgR/dT+T5LxJnV3jrex56S6533V9f2ljyZ7fLdmZFve7E OvOrYY0wA1NOZHmAoslQvXPSK4DPTuu0kf4ekDfNjvLXTnguFDF5Nul7vFGMmR2hUoz3 QApubdEJqGP1faNiWqegYJF2TxvWuiJOy19smgKZVrp9gd9Ad9XtQ5ECx4VtkPyGe+Of Vh8U0bVuNaDoLqgKsll/cSp+JomoG7U1h88qgilcxm//D5trEo8D8CHdutgJCNmSJGEg 89eA== X-Gm-Message-State: ACgBeo0xtLL1MI3LAldibIUsThD/ulb6GrSH25EjbrcYFJH0qYiz9Vn+ kDfBKmxETim0lkHrRKrML+PA1yyRQ7/Szg3Uj/sWlKW2B5TG9fCM2nXyBCi6NDKIZOsuEDf+u4k SV3616ZjgxYGwbbyo9fTfl4WUm07EdqNGWhBqgHWm4nAkjN9GhHeL6gge7PnEHiZUv2s= X-Received: by 2002:a05:622a:1483:b0:343:7ba3:f60f with SMTP id t3-20020a05622a148300b003437ba3f60fmr15714442qtx.94.1661879619863; Tue, 30 Aug 2022 10:13:39 -0700 (PDT) X-Received: by 2002:a05:622a:1483:b0:343:7ba3:f60f with SMTP id t3-20020a05622a148300b003437ba3f60fmr15714402qtx.94.1661879619422; Tue, 30 Aug 2022 10:13:39 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id k17-20020a05620a415100b006bad7a2964fsm8455222qko.78.2022.08.30.10.13.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Aug 2022 10:13:38 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/2] libstdc++: Implement ranges::adjacent_view from P2321R2 Date: Tue, 30 Aug 2022 13:13:34 -0400 Message-Id: <20220830171335.54110-1-ppalka@redhat.com> X-Mailer: git-send-email 2.37.2.490.g6c8e4ee870 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.7 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_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?1742607162774560888?= X-GMAIL-MSGID: =?utf-8?q?1742607162774560888?= Tested on x86_64-pc-linux-gnu, does this look OK for trunk? libstdc++-v3/ChangeLog: * include/std/ranges (adjacent_view): Define. (enable_borrowed_range): Define. (__detail::__repeated_tuple): Define. (adjacent_view::_Iterator): Define. (adjacent_view::_Sentinel): Define. (views::__detail::__can_adjacent_view): Define. (views::_Adjacent): Define. (views::adjacent): Define. (views::pairwise): Define. * testsuite/std/ranges/adaptors/adjacent/1.cc: New test. --- libstdc++-v3/include/std/ranges | 359 ++++++++++++++++++ .../std/ranges/adaptors/adjacent/1.cc | 110 ++++++ 2 files changed, 469 insertions(+) create mode 100644 libstdc++-v3/testsuite/std/ranges/adaptors/adjacent/1.cc diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 6e2e561ed12..4fb879a088c 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -5081,6 +5081,365 @@ namespace views::__adaptor inline constexpr _ZipTransform zip_transform; } + + template + requires view<_Vp> && (_Nm > 0) + class adjacent_view : public view_interface> + { + _Vp _M_base = _Vp(); + + template class _Iterator; + template class _Sentinel; + + struct __as_sentinel + { }; + + public: + adjacent_view() requires default_initializable<_Vp> = default; + + constexpr explicit + adjacent_view(_Vp __base) + : _M_base(std::move(__base)) + { } + + constexpr auto + begin() requires (!__detail::__simple_view<_Vp>) + { return _Iterator(ranges::begin(_M_base), ranges::end(_M_base)); } + + constexpr auto + begin() const requires range + { return _Iterator(ranges::begin(_M_base), ranges::end(_M_base)); } + + constexpr auto + end() requires (!__detail::__simple_view<_Vp>) + { + if constexpr (common_range<_Vp>) + return _Iterator(__as_sentinel{}, ranges::begin(_M_base), ranges::end(_M_base)); + else + return _Sentinel(ranges::end(_M_base)); + } + + constexpr auto + end() const requires range + { + if constexpr (common_range) + return _Iterator(__as_sentinel{}, ranges::begin(_M_base), ranges::end(_M_base)); + else + return _Sentinel(ranges::end(_M_base)); + } + + constexpr auto + size() requires sized_range<_Vp> + { + using _ST = decltype(ranges::size(_M_base)); + using _CT = common_type_t<_ST, size_t>; + auto __sz = static_cast<_CT>(ranges::size(_M_base)); + __sz -= std::min<_CT>(__sz, _Nm - 1); + return static_cast<_ST>(__sz); + } + + constexpr auto + size() const requires sized_range + { + using _ST = decltype(ranges::size(_M_base)); + using _CT = common_type_t<_ST, size_t>; + auto __sz = static_cast<_CT>(ranges::size(_M_base)); + __sz -= std::min<_CT>(__sz, _Nm - 1); + return static_cast<_ST>(__sz); + } + }; + + template + inline constexpr bool enable_borrowed_range> + = enable_borrowed_range<_Vp>; + + namespace __detail + { + // Yields tuple<_Tp, ..., _Tp> with _Nm elements. + template + using __repeated_tuple = decltype(std::tuple_cat(std::declval>())); + } + + template + requires view<_Vp> && (_Nm > 0) + template + class adjacent_view<_Vp, _Nm>::_Iterator + { + using _Base = __detail::__maybe_const_t<_Const, _Vp>; + array, _Nm> _M_current = array, _Nm>(); + + constexpr + _Iterator(iterator_t<_Base> __first, sentinel_t<_Base> __last) + { + for (auto& __i : _M_current) + { + __i = __first; + ranges::advance(__first, 1, __last); + } + } + + constexpr + _Iterator(__as_sentinel, iterator_t<_Base> __first, iterator_t<_Base> __last) + { + if constexpr (!bidirectional_range<_Base>) + for (auto& __it : _M_current) + __it = __last; + else + for (ssize_t __i = _Nm-1; __i >= 0; --__i) + { + _M_current[__i] = __last; + ranges::advance(__last, -1, __first); + } + } + + static auto + _S_iter_concept() + { + if constexpr (random_access_range<_Base>) + return random_access_iterator_tag{}; + else if constexpr (bidirectional_range<_Base>) + return bidirectional_iterator_tag{}; + else + return forward_iterator_tag{}; + } + + friend class adjacent_view; + + public: + using iterator_category = input_iterator_tag; + using iterator_concept = decltype(_S_iter_concept()); + using value_type = conditional_t<_Nm == 2, + pair, range_value_t<_Base>>, + __detail::__repeated_tuple, _Nm>>; + using difference_type = range_difference_t<_Base>; + + _Iterator() = default; + + constexpr + _Iterator(_Iterator __i) + requires _Const && convertible_to, iterator_t<_Base>> + { + for (size_t __j = 0; __j < _Nm; ++__j) + _M_current[__j] = std::move(__i[__j]); + } + + constexpr auto + operator*() const + { + auto __f = [](auto& __i) -> decltype(auto) { return *__i; }; + return __detail::__tuple_transform(__f, _M_current); + } + + constexpr _Iterator& + operator++() + { + for (auto& __i : _M_current) + ++__i; + return *this; + } + + constexpr _Iterator + operator++(int) + { + auto __tmp = *this; + ++*this; + return __tmp; + } + + constexpr _Iterator& + operator--() requires bidirectional_range<_Base> + { + for (auto& __i : _M_current) + --__i; + return *this; + } + + constexpr _Iterator + operator--(int) requires bidirectional_range<_Base> + { + auto __tmp = *this; + --*this; + return __tmp; + } + + constexpr _Iterator& + operator+=(difference_type __x) + requires random_access_range<_Base> + { + for (auto& __i : _M_current) + __i += __x; + return *this; + } + + constexpr _Iterator& + operator-=(difference_type __x) + requires random_access_range<_Base> + { + for (auto& __i : _M_current) + __i -= __x; + return *this; + } + + constexpr auto + operator[](difference_type __n) const + requires random_access_range<_Base> + { + auto __f = [&](auto& __i) -> decltype(auto) { return __i[__n]; }; + return __detail::__tuple_transform(__f, _M_current); + } + + friend constexpr bool + operator==(const _Iterator& __x, const _Iterator& __y) + { return __x._M_current.back() == __y._M_current.back(); } + + friend constexpr bool + operator<(const _Iterator& __x, const _Iterator& __y) + requires random_access_range<_Base> + { return __x._M_current.back() < __y._M_current.back(); } + + friend constexpr bool + operator>(const _Iterator& __x, const _Iterator& __y) + requires random_access_range<_Base> + { return __y < __x; } + + friend constexpr bool + operator<=(const _Iterator& __x, const _Iterator& __y) + requires random_access_range<_Base> + { return !(__y < __x); } + + friend constexpr bool + operator>=(const _Iterator& __x, const _Iterator& __y) + requires random_access_range<_Base> + { return !(__x < __y); } + + friend constexpr auto + operator<=>(const _Iterator& __x, const _Iterator& __y) + requires random_access_range<_Base> + && three_way_comparable> + { return __x._M_current.back() <=> __y._M_current.back(); } + + friend constexpr _Iterator + operator+(const _Iterator& __i, difference_type __n) + requires random_access_range<_Base> + { + auto __r = __i; + __r += __n; + return __r; + } + + friend constexpr _Iterator + operator+(difference_type __n, const _Iterator& __i) + requires random_access_range<_Base> + { + auto __r = __i; + __r += __n; + return __r; + } + + friend constexpr _Iterator + operator-(const _Iterator& __i, difference_type __n) + requires random_access_range<_Base> + { + auto __r = __i; + __r -= __n; + return __r; + } + + friend constexpr difference_type + operator-(const _Iterator& __x, const _Iterator& __y) + requires sized_sentinel_for, iterator_t<_Base>> + { return __x._M_current.back() - __y._M_current.back(); } + + friend constexpr auto + iter_move(const _Iterator& __i) + { return __detail::__tuple_transform(ranges::iter_move, __i._M_current); } + + friend constexpr void + iter_swap(const _Iterator& __l, const _Iterator& __r) + requires indirectly_swappable> + { + for (size_t __i = 0; __i < _Nm; __i++) + ranges::iter_swap(__l._M_current[__i], __r._M_current[__i]); + } + }; + + template + requires view<_Vp> && (_Nm > 0) + template + class adjacent_view<_Vp, _Nm>::_Sentinel + { + using _Base = __detail::__maybe_const_t<_Const, _Vp>; + + sentinel_t<_Base> _M_end = sentinel_t<_Base>(); + + constexpr explicit + _Sentinel(sentinel_t<_Base> __end) + : _M_end(__end) + { } + + friend class adjacent_view; + + public: + _Sentinel() = default; + + constexpr + _Sentinel(_Sentinel __i) + requires _Const && convertible_to, sentinel_t<_Base>> + : _M_end(std::move(__i._M_end)) + { } + + template + requires sentinel_for, + iterator_t<__detail::__maybe_const_t<_OtherConst, _Vp>>> + friend constexpr bool + operator==(const _Iterator<_OtherConst>& __x, const _Sentinel& __y) + { return __x._M_current.back() == __y._M_end; } + + template + requires sized_sentinel_for, + iterator_t<__detail::__maybe_const_t<_OtherConst, _Vp>>> + friend constexpr range_difference_t<__detail::__maybe_const_t<_OtherConst, _Vp>> + operator-(const _Iterator<_OtherConst>& __x, const _Sentinel& __y) + { return __x._M_current.back() - __y._M_end; } + + template + requires sized_sentinel_for, + iterator_t<__detail::__maybe_const_t<_OtherConst, _Vp>>> + friend constexpr range_difference_t<__detail::__maybe_const_t<_OtherConst, _Vp>> + operator-(const _Sentinel& __y, const _Iterator<_OtherConst>& __x) + { return __y._M_end - __x._M_current.back(); } + }; + + namespace views + { + namespace __detail + { + template + concept __can_adjacent_view + = requires { adjacent_view, _Nm>(std::declval<_Range>()); }; + } + + template + struct _Adjacent : __adaptor::_RangeAdaptorClosure + { + template + requires (_Nm == 0) || __detail::__can_adjacent_view<_Nm, _Range> + [[nodiscard]] + constexpr auto + operator()(_Range&& __r) const + { + if constexpr (_Nm == 0) + return views::empty>; + else + return adjacent_view, _Nm>(std::forward<_Range>(__r)); + } + }; + + template + inline constexpr _Adjacent<_Nm> adjacent; + + inline constexpr auto pairwise = adjacent<2>; + } #endif // C++23 } // namespace ranges diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/adjacent/1.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/adjacent/1.cc new file mode 100644 index 00000000000..9829f79364f --- /dev/null +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/adjacent/1.cc @@ -0,0 +1,110 @@ +// { 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(std::array{1, 2, 3} | views::adjacent<0>)); + + auto v1 = std::array{1, 2} | views::adjacent<1>; + const auto i0 = v1.begin(), i1 = v1.begin() + 1; + VERIFY( i0 + 1 - 1 == i0 ); + VERIFY( i0 < i1 ); + VERIFY( i1 < v1.end() ); + VERIFY( i1 - i0 == 1 ); + VERIFY( i0 - i1 == -1 ); + VERIFY( v1.end() - i1 == 1 ); + VERIFY( i1 - v1.end() == -1 ); + ranges::iter_swap(i0, i1); + VERIFY( ranges::equal(std::move(v1) | views::keys, (int[]){2, 1}) ); + + int x[] = {1, 2, 3, 4}; + auto v2 = x | views::pairwise; + auto i2 = v2.begin(); + i2 += 2; + i2 -= -1; + VERIFY( i2 == v2.end() ); + VERIFY( ranges::size(v2) == 3 ); + VERIFY( ranges::size(std::as_const(v2)) == 3 ); + VERIFY( ranges::equal(v2 | views::keys, (int[]){1, 2, 3}) ); + VERIFY( ranges::equal(v2 | views::values, (int[]){2, 3, 4}) ); + + int y[] = {1, 2, 3, 4, 5}; + const auto v3 = y | views::adjacent<3>; + VERIFY( ranges::size(v3) == 3 ); + for (unsigned i = 0; i < ranges::size(x); i++) + { + VERIFY( &std::get<0>(v3[i]) == &y[i] + 0 ); + VERIFY( &std::get<1>(v3[i]) == &y[i] + 1 ); + VERIFY( &std::get<2>(v3[i]) == &y[i] + 2 ); + } + + const auto v5 = y | views::adjacent<5>; + VERIFY( ranges::equal(v5, views::single(std::make_tuple(1, 2, 3, 4, 5))) ); + + const auto v6 = y | views::adjacent<6>; + VERIFY( ranges::empty(v6) ); + + const auto v0 = y | views::adjacent<0>; + VERIFY( ranges::empty(v0) ); + + 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::adjacent_view>, 2>; + static_assert(ranges::forward_range); + static_assert(!ranges::bidirectional_range); + static_assert(!ranges::sized_range); + + using ty2 = ranges::adjacent_view>, 3>; + static_assert(ranges::random_access_range); + static_assert(ranges::sized_range); + + return true; +} + +constexpr bool +test03() +{ + auto v = views::iota(0, 4) | views::filter([](auto) { return true; }) | views::pairwise; + using ty = decltype(v); + static_assert(ranges::forward_range); + static_assert(ranges::common_range); + static_assert(!ranges::sized_range); + VERIFY( v.begin() == v.begin() ); + VERIFY( v.begin() != v.end() ); + VERIFY( ranges::next(v.begin(), 3) == v.end() ); + auto it = v.begin(); + ++it; + it++; + VERIFY( ranges::next(it) == v.end() ); + it--; + --it; + VERIFY( it == v.begin() ); + + return true; +} + +int +main() +{ + static_assert(test01()); + static_assert(test02()); + static_assert(test03()); +}