From: Stephan Bergmann <sbergman@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: Patrick Palka <ppalka@redhat.com>,
libstdc++@gcc.gnu.org, jwakely@redhat.com
Subject: Re: [PATCH] libstdc++: P0769R2 Add shift to <algorithm>
Date: Mon, 02 Mar 2020 09:03:00 -0000 [thread overview]
Message-ID: <697d3b3e-684c-794d-8784-3a23c1b81701@redhat.com> (raw)
In-Reply-To: <20200221192922.2412286-1-ppalka@redhat.com>
On 21/02/2020 20:29, Patrick Palka wrote:
> diff --git a/libstdc++-v3/include/bits/ranges_algo.h b/libstdc++-v3/include/bits/ranges_algo.h
> index 7de1072abf0..c36afc6e19b 100644
> --- a/libstdc++-v3/include/bits/ranges_algo.h
> +++ b/libstdc++-v3/include/bits/ranges_algo.h
> @@ -3683,6 +3683,54 @@ namespace ranges
> inline constexpr __prev_permutation_fn prev_permutation{};
>
> } // namespace ranges
> +
> + template<class ForwardIterator>
> + constexpr ForwardIterator
> + shift_left(ForwardIterator __first, ForwardIterator __last,
> + typename iterator_traits<ForwardIterator>::difference_type __n)
> + {
> + __glibcxx_assert(__n >= 0);
> + if (__n == 0)
> + return __last;
> +
> + auto __mid = ranges::next(__first, __n, __last);
> + if (__mid == __last)
> + return __first;
> + return std::move(std::move(__mid), std::move(__last), std::move(__first));
> + }
> +
> + template<class ForwardIterator>
> + constexpr ForwardIterator
> + shift_right(ForwardIterator __first, ForwardIterator __last,
> + typename iterator_traits<ForwardIterator>::difference_type __n)
> + {
> + __glibcxx_assert(__n >= 0);
> + if (__n == 0)
> + return __first;
> +
> + using _Cat = iterator_traits<ForwardIterator>::iterator_category;
^ FYI, the above line causes recent Clang 10 trunk with -std=c++20 to
fail due to a "missing" typedef
> + if constexpr (derived_from<_Cat, bidirectional_iterator_tag>)
> + {
> + auto __mid = ranges::next(__last, -__n, __first);
> + if (__mid == __first)
> + return __last;
> + return std::move_backward(std::move(__first), std::move(__mid),
> + std::move(__last));
> + }
> + else
> + {
> + auto __result = ranges::next(__first, __n, __last);
> + if (__result == __last)
> + return __last;
> + auto __dest = __result;
> + do
> + __dest = ranges::swap_ranges(__first, __result,
> + std::move(__dest), __last).in2;
> + while (__dest != __last);
> + return __result;
> + }
> + }
> +
> _GLIBCXX_END_NAMESPACE_VERSION
> } // namespace std
> #endif // concepts
next prev parent reply other threads:[~2020-03-02 9:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-21 19:29 Patrick Palka
2020-02-21 21:12 ` Patrick Palka
2020-02-24 13:47 ` Jonathan Wakely
2020-02-24 14:12 ` Patrick Palka
2020-02-24 14:16 ` Daniel Krügler
2020-02-24 14:28 ` Jonathan Wakely
2020-03-02 9:03 ` Stephan Bergmann [this message]
2020-03-02 12:20 ` Jonathan Wakely
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=697d3b3e-684c-794d-8784-3a23c1b81701@redhat.com \
--to=sbergman@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jwakely@redhat.com \
--cc=libstdc++@gcc.gnu.org \
--cc=ppalka@redhat.com \
/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: link
Be 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).