public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r11-8477] libstdc++: Implement P2328 changes to join_view Date: Fri, 28 May 2021 14:38:54 +0000 (GMT) [thread overview] Message-ID: <20210528143854.2EEEB388A83A@sourceware.org> (raw) https://gcc.gnu.org/g:e1489a3d613b6fc9d4ecfe57a809252f78ff8682 commit r11-8477-ge1489a3d613b6fc9d4ecfe57a809252f78ff8682 Author: Patrick Palka <ppalka@redhat.com> Date: Fri Apr 30 18:45:46 2021 -0400 libstdc++: Implement P2328 changes to join_view This implements the wording changes of P2328R0 "join_view should join all views of ranges". libstdc++-v3/ChangeLog: * include/std/ranges (__detail::__non_propating_cache): Define as per P2328. (join_view): Remove constraints on the value and reference types of the wrapped iterator type as per P2328. (join_view::_Iterator::_M_satisfy): Adjust as per P2328. (join_view::_Iterator::operator++): Likewise. (join_view::_M_inner): Use __non_propating_cache as per P2328. Remove now-redundant use of __maybe_present_t. * testsuite/std/ranges/adaptors/join.cc: Include <array>. (test10): New test. (cherry picked from commit 237dde3d03c573eb13c0e765520ee4b713aa2c7e) Diff: --- libstdc++-v3/include/std/ranges | 17 ++++++--------- libstdc++-v3/testsuite/std/ranges/adaptors/join.cc | 24 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 1a57d071069..ae3cd7fbc99 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -2318,8 +2318,6 @@ namespace views::__adaptor template<input_range _Vp> requires view<_Vp> && input_range<range_reference_t<_Vp>> - && (is_reference_v<range_reference_t<_Vp>> - || view<range_value_t<_Vp>>) class join_view : public view_interface<join_view<_Vp>> { private: @@ -2385,17 +2383,16 @@ namespace views::__adaptor constexpr void _M_satisfy() { - auto __update_inner = [this] (range_reference_t<_Base> __x) -> auto& - { + auto __update_inner = [this] (const iterator_t<_Base>& __x) -> auto&& { if constexpr (_S_ref_is_glvalue) - return __x; + return *__x; else - return (_M_parent->_M_inner = views::all(std::move(__x))); + return _M_parent->_M_inner._M_emplace_deref(__x); }; for (; _M_outer != ranges::end(_M_parent->_M_base); ++_M_outer) { - auto& __inner = __update_inner(*_M_outer); + auto&& __inner = __update_inner(_M_outer); _M_inner = ranges::begin(__inner); if (_M_inner != ranges::end(__inner)) return; @@ -2471,7 +2468,7 @@ namespace views::__adaptor if constexpr (_S_ref_is_glvalue) return *_M_outer; else - return _M_parent->_M_inner; + return *_M_parent->_M_inner; }(); if (++_M_inner == ranges::end(__inner_range)) { @@ -2583,10 +2580,8 @@ namespace views::__adaptor friend _Sentinel<!_Const>; }; - // XXX: _M_inner is "present only when !is_reference_v<_InnerRange>" [[no_unique_address]] - __detail::__maybe_present_t<!is_reference_v<_InnerRange>, - views::all_t<_InnerRange>> _M_inner; + __detail::__non_propagating_cache<remove_cv_t<_InnerRange>> _M_inner; _Vp _M_base = _Vp(); public: diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc index e6c71d771de..d774e8d9385 100644 --- a/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc @@ -19,6 +19,7 @@ // { dg-do run { target c++2a } } #include <algorithm> +#include <array> #include <ranges> #include <string> #include <string_view> @@ -170,6 +171,28 @@ test10() VERIFY( ranges::next(v.begin()) == v.end() ); } +void +test11() +{ + // Verify P2328 changes. + int r[] = {1, 2, 3}; + auto v = r + | views::transform([] (int n) { return std::vector{{n, -n}}; }) + | views::join; + VERIFY( ranges::equal(v, (int[]){1, -1, 2, -2, 3, -3}) ); + + struct S { + S() = default; + S(const S&) = delete; + S(S&&) = delete; + }; + auto w = r + | views::transform([] (int) { return std::array<S, 2>{}; }) + | views::join; + for (auto& i : w) + ; +} + int main() { @@ -183,4 +206,5 @@ main() test08(); test09(); test10(); + test11(); }
reply other threads:[~2021-05-28 14:38 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210528143854.2EEEB388A83A@sourceware.org \ --to=ppalka@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).