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 r13-7157] libstdc++: Fix chunk_by_view when value_type& and reference differ [PR108291] Date: Wed, 12 Apr 2023 16:11:00 +0000 (GMT) [thread overview] Message-ID: <20230412161100.F4039385800A@sourceware.org> (raw) https://gcc.gnu.org/g:ae8f903632c930694640a925b042c87e3bdb7200 commit r13-7157-gae8f903632c930694640a925b042c87e3bdb7200 Author: Patrick Palka <ppalka@redhat.com> Date: Wed Apr 12 12:10:23 2023 -0400 libstdc++: Fix chunk_by_view when value_type& and reference differ [PR108291] PR libstdc++/108291 libstdc++-v3/ChangeLog: * include/std/ranges (chunk_by_view::_M_find_next): Generalize parameter types of the lambda wrapper passed to adjacent_find. (chunk_by_view::_M_find_prev): Likewise. * testsuite/std/ranges/adaptors/chunk_by/1.cc (test04, test05): New tests. Diff: --- libstdc++-v3/include/std/ranges | 8 ++--- .../testsuite/std/ranges/adaptors/chunk_by/1.cc | 35 ++++++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index b230ebefcf5..ba71976df8d 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -6742,8 +6742,8 @@ namespace views::__adaptor _M_find_next(iterator_t<_Vp> __current) { __glibcxx_assert(_M_pred.has_value()); - auto __pred = [this]<typename _Tp>(_Tp&& __x, _Tp&& __y) { - return !bool((*_M_pred)(std::forward<_Tp>(__x), std::forward<_Tp>(__y))); + auto __pred = [this]<typename _Tp, typename _Up>(_Tp&& __x, _Up&& __y) { + return !bool((*_M_pred)(std::forward<_Tp>(__x), std::forward<_Up>(__y))); }; auto __it = ranges::adjacent_find(__current, ranges::end(_M_base), __pred); return ranges::next(__it, 1, ranges::end(_M_base)); @@ -6753,8 +6753,8 @@ namespace views::__adaptor _M_find_prev(iterator_t<_Vp> __current) requires bidirectional_range<_Vp> { __glibcxx_assert(_M_pred.has_value()); - auto __pred = [this]<typename _Tp>(_Tp&& __x, _Tp&& __y) { - return !bool((*_M_pred)(std::forward<_Tp>(__y), std::forward<_Tp>(__x))); + auto __pred = [this]<typename _Tp, typename _Up>(_Tp&& __x, _Up&& __y) { + return !bool((*_M_pred)(std::forward<_Up>(__y), std::forward<_Tp>(__x))); }; auto __rbegin = std::make_reverse_iterator(__current); auto __rend = std::make_reverse_iterator(ranges::begin(_M_base)); diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/chunk_by/1.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/chunk_by/1.cc index f165c7d9a95..a8fceb105e0 100644 --- a/libstdc++-v3/testsuite/std/ranges/adaptors/chunk_by/1.cc +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/chunk_by/1.cc @@ -61,10 +61,45 @@ test03() ranges::chunk_by_view<ranges::empty_view<int>, ranges::equal_to> r; } +constexpr bool +test04() +{ + // PR libstdc++/108291 + using namespace std::literals; + std::string_view s = "hello"; + auto r = s | views::chunk_by(std::less{}); + VERIFY( ranges::equal(r, + (std::string_view[]){"h"sv, "el"sv, "lo"sv}, + ranges::equal) ); + VERIFY( ranges::equal(r | views::reverse, + (std::string_view[]){"lo"sv, "el"sv, "h"sv}, + ranges::equal) ); + + return true; +} + +void +test05() +{ + // PR libstdc++/109474 + std::vector<bool> v = {true, false, true, true, false, false}; + auto r = v | views::chunk_by(std::equal_to{}); + VERIFY( ranges::equal(r, + (std::initializer_list<bool>[]) + {{true}, {false}, {true, true}, {false, false}}, + ranges::equal) ); + VERIFY( ranges::equal(r | views::reverse, + (std::initializer_list<bool>[]) + {{false, false}, {true, true}, {false}, {true}}, + ranges::equal) ); +} + int main() { static_assert(test01()); test02(); test03(); + static_assert(test04()); + test05(); }
reply other threads:[~2023-04-12 16:11 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=20230412161100.F4039385800A@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).