Skip to content

Commit d517b2a

Browse files
jensmaurerzygoloid
authored andcommitted
P0769R2 Add shift to <algorithm>
1 parent 6ba774f commit d517b2a

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

source/algorithms.tex

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,26 @@
565565
RandomAccessIterator last,
566566
UniformRandomBitGenerator&& g);
567567

568+
// \ref{alg.shift}, shift
569+
template<class ForwardIterator>
570+
constexpr ForwardIterator
571+
shift_left(ForwardIterator first, ForwardIterator last,
572+
typename iterator_traits<ForwardIterator>::difference_type n);
573+
template<class ExecutionPolicy, class ForwardIterator>
574+
ForwardIterator
575+
shift_left(ExecutionPolicy&& exec, // see \ref{algorithms.parallel.overloads}
576+
ForwardIterator first, ForwardIterator last,
577+
typename iterator_traits<ForwardIterator>::difference_type n);
578+
template<class ForwardIterator>
579+
ForwardIterator
580+
shift_right(ForwardIterator first, ForwardIterator last,
581+
typename iterator_traits<ForwardIterator>::difference_type n);
582+
template<class ExecutionPolicy, class ForwardIterator>
583+
ForwardIterator
584+
shift_right(ExecutionPolicy&& exec, // see \ref{algorithms.parallel.overloads}
585+
ForwardIterator first, ForwardIterator last,
586+
typename iterator_traits<ForwardIterator>::difference_type n);
587+
568588
// \ref{alg.partitions}, partitions
569589
template<class InputIterator, class Predicate>
570590
constexpr bool is_partitioned(InputIterator first, InputIterator last, Predicate pred);
@@ -3526,6 +3546,89 @@
35263546

35273547
\end{itemdescr}
35283548

3549+
\rSec2[alg.shift]{Shift}
3550+
3551+
\indexlibrary{\idxcode{shift_left}}%
3552+
\begin{itemdecl}
3553+
template<class ForwardIterator>
3554+
constexpr ForwardIterator
3555+
shift_left(ForwardIterator first, ForwardIterator last,
3556+
typename iterator_traits<ForwardIterator>::difference_type n);
3557+
template<class ExecutionPolicy, class ForwardIterator>
3558+
ForwardIterator
3559+
shift_left(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
3560+
typename iterator_traits<ForwardIterator>::difference_type n);
3561+
\end{itemdecl}
3562+
3563+
\begin{itemdescr}
3564+
\pnum
3565+
\requires
3566+
The type of \tcode{*first} shall satisfy
3567+
the \tcode{MoveAssignable} requirements.
3568+
3569+
\pnum
3570+
\effects
3571+
If \tcode{n <= 0} or \tcode{n >= last - first}, does nothing.
3572+
Otherwise, moves the element
3573+
from position \tcode{first + n + i}
3574+
into position \tcode{first + i}
3575+
for each non-negative integer \tcode{i < (last - first) - n}.
3576+
In the first overload case, does so in order starting
3577+
from \tcode{i = 0} and proceeding to \tcode{i = (last - first) - n - 1}.
3578+
3579+
\pnum
3580+
\returns
3581+
\tcode{first + (last - first) - n}
3582+
if \tcode{n} is positive and \tcode{n < last - first},
3583+
otherwise \tcode{first} if \tcode{n} is positive, otherwise \tcode{last}.
3584+
3585+
\pnum
3586+
\complexity
3587+
At most \tcode{(last - first) - n} assignments.
3588+
\end{itemdescr}
3589+
3590+
\indexlibrary{\idxcode{shift_right}}%
3591+
\begin{itemdecl}
3592+
template<class ForwardIterator>
3593+
ForwardIterator
3594+
shift_right(ForwardIterator first, ForwardIterator last,
3595+
typename iterator_traits<ForwardIterator>::difference_type n);
3596+
template<class ExecutionPolicy, class ForwardIterator>
3597+
ForwardIterator
3598+
shift_right(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last,
3599+
typename iterator_traits<ForwardIterator>::difference_type n);
3600+
\end{itemdecl}
3601+
3602+
\begin{itemdescr}
3603+
\pnum
3604+
\requires
3605+
The type of \tcode{*first} shall satisfy
3606+
the \tcode{MoveAssignable} requirements.
3607+
\tcode{ForwardIterator} shall meet
3608+
the \tcode{BidirectionalIterator} or \tcode{ValueSwappable} requirements.
3609+
3610+
\pnum
3611+
\effects
3612+
If \tcode{n <= 0} or \tcode{n >= last - first}, does nothing.
3613+
Otherwise, moves the element
3614+
from position \tcode{first + i} into \tcode{position first + n + i}
3615+
for each non-negative integer \tcode{i < (last - first) - n}.
3616+
In the first overload case, if \tcode{ForwardIterator} satisfies
3617+
the \tcode{BidirectionalIterator} requirements,
3618+
does so in order starting
3619+
from \tcode{i = (last - first) - n - 1} and proceeding to \tcode{i = 0}.
3620+
3621+
\pnum
3622+
\returns
3623+
\tcode{first + n}
3624+
if \tcode{n} is positive and \tcode{n < last - first},
3625+
otherwise \tcode{last} if \tcode{n} is positive, otherwise \tcode{first}.
3626+
3627+
\pnum
3628+
\complexity
3629+
At most \tcode{(last - first) - n} assignments or swaps.
3630+
\end{itemdescr}
3631+
35293632
\rSec1[alg.sorting]{Sorting and related operations}
35303633

35313634
\pnum

0 commit comments

Comments
 (0)