Skip to content

Commit e23f977

Browse files
authored
Merge 2022-07 LWG Motion 8
P1223R5 find_last
2 parents d02577e + 10bab7b commit e23f977

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

source/algorithms.tex

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,29 @@
780780
find_if_not(R&& r, Pred pred, Proj proj = {});
781781
}
782782

783+
// \ref{alg.find.last}, find last
784+
namespace ranges {
785+
template<@\libconcept{forward_iterator}@ I, @\libconcept{sentinel_for}@<I> S, class T, class Proj = identity>
786+
requires @\libconcept{indirect_binary_predicate}@<ranges::equal_to, projected<I, Proj>, const T*>
787+
constexpr subrange<I> find_last(I first, S last, const T& value, Proj proj = {});
788+
template<@\libconcept{forward_range}@ R, class T, class Proj = identity>
789+
requires
790+
@\libconcept{indirect_binary_predicate}@<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
791+
constexpr borrowed_subrange_t<R> find_last(R&& r, const T& value, Proj proj = {});
792+
template<@\libconcept{forward_iterator}@ I, @\libconcept{sentinel_for}@<I> S, class Proj = identity,
793+
@\libconcept{indirect_unary_predicate}@<projected<I, Proj>> Pred>
794+
constexpr subrange<I> find_last_if(I first, S last, Pred pred, Proj proj = {});
795+
template<@\libconcept{forward_range}@ R, class Proj = identity,
796+
@\libconcept{indirect_unary_predicate}@<projected<iterator_t<R>, Proj>> Pred>
797+
constexpr borrowed_subrange_t<R> find_last_if(R&& r, Pred pred, Proj proj = {});
798+
template<@\libconcept{forward_iterator}@ I, @\libconcept{sentinel_for}@<I> S, class Proj = identity,
799+
@\libconcept{indirect_unary_predicate}@<projected<I, Proj>> Pred>
800+
constexpr subrange<I> find_last_if_not(I first, S last, Pred pred, Proj proj = {});
801+
template<@\libconcept{forward_range}@ R, class Proj = identity,
802+
@\libconcept{indirect_unary_predicate}@<projected<iterator_t<R>, Proj>> Pred>
803+
constexpr borrowed_subrange_t<R> find_last_if_not(R&& r, Pred pred, Proj proj = {});
804+
}
805+
783806
// \ref{alg.find.end}, find end
784807
template<class ForwardIterator1, class ForwardIterator2>
785808
constexpr ForwardIterator1
@@ -3514,6 +3537,55 @@
35143537
of the corresponding predicate and any projection.
35153538
\end{itemdescr}
35163539

3540+
\rSec2[alg.find.last]{Find last}
3541+
3542+
\indexlibraryglobal{find_last}%
3543+
\begin{itemdecl}
3544+
template<@\libconcept{forward_iterator}@ I, @\libconcept{sentinel_for}@<I> S, class T, class Proj = identity>
3545+
requires @\libconcept{indirect_binary_predicate}@<ranges::equal_to, projected<I, Proj>, const T*>
3546+
constexpr subrange<I> ranges::find_last(I first, S last, const T& value, Proj proj = {});
3547+
template<@\libconcept{forward_range}@ R, class T, class Proj = identity>
3548+
requires @\libconcept{indirect_binary_predicate}@<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
3549+
constexpr borrowed_subrange_t<R> ranges::find_last(R&& r, const T& value, Proj proj = {});
3550+
template<@\libconcept{forward_iterator}@ I, @\libconcept{sentinel_for}@<I> S, class Proj = identity,
3551+
@\libconcept{indirect_unary_predicate}@<projected<I, Proj>> Pred>
3552+
constexpr subrange<I> ranges::find_last_if(I first, S last, Pred pred, Proj proj = {});
3553+
template<@\libconcept{forward_range}@ R, class Proj = identity,
3554+
@\libconcept{indirect_unary_predicate}@<projected<iterator_t<R>, Proj>> Pred>
3555+
constexpr borrowed_subrange_t<R> ranges::find_last_if(R&& r, Pred pred, Proj proj = {});
3556+
template<@\libconcept{forward_iterator}@ I, @\libconcept{sentinel_for}@<I> S, class Proj = identity,
3557+
@\libconcept{indirect_unary_predicate}@<projected<I, Proj>> Pred>
3558+
constexpr subrange<I> ranges::find_last_if_not(I first, S last, Pred pred, Proj proj = {});
3559+
template<@\libconcept{forward_range}@ R, class Proj = identity,
3560+
@\libconcept{indirect_unary_predicate}@<projected<iterator_t<R>, Proj>> Pred>
3561+
constexpr borrowed_subrange_t<R> ranges::find_last_if_not(R&& r, Pred pred, Proj proj = {});
3562+
\end{itemdecl}
3563+
3564+
\begin{itemdescr}
3565+
\pnum
3566+
Let $E$ be:
3567+
\begin{itemize}
3568+
\item
3569+
\tcode{bool(invoke(proj, *i) == value)} for \tcode{ranges::find_last};
3570+
\item
3571+
\tcode{bool(invoke(pred, invoke(proj, *i)))} for \tcode{ranges::find_last_if};
3572+
\item
3573+
\tcode{bool(!invoke(pred, invoke(proj, *i)))} for \tcode{ranges::find_last_if_not}.
3574+
\end{itemize}
3575+
3576+
\pnum
3577+
\returns
3578+
Let \tcode{i} be the last iterator in the range \range{first}{last}
3579+
for which $E$ is \tcode{true}.
3580+
Returns \tcode{\{i, last\}}, or
3581+
\tcode{\{last, last\}} if no such iterator is found.
3582+
3583+
\pnum
3584+
\complexity
3585+
At most \tcode{last - first} applications of
3586+
the corresponding predicate and projection.
3587+
\end{itemdescr}
3588+
35173589
\rSec2[alg.find.end]{Find end}
35183590

35193591
\indexlibraryglobal{find_end}%

source/support.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@
616616
#define @\defnlibxname{cpp_lib_execution}@ 201902L // also in \libheader{execution}
617617
#define @\defnlibxname{cpp_lib_expected}@ 202202L // also in \libheader{expected}
618618
#define @\defnlibxname{cpp_lib_filesystem}@ 201703L // also in \libheader{filesystem}
619+
#define @\defnlibxname{cpp_lib_find_last}@ 202207L // also in \libheader{algorithm}
619620
#define @\defnlibxname{cpp_lib_flat_map}@ 202207L // also in \libheader{flat_map}
620621
#define @\defnlibxname{cpp_lib_format}@ 202110L // also in \libheader{format}
621622
#define @\defnlibxname{cpp_lib_gcd_lcm}@ 201606L // also in \libheader{numeric}

0 commit comments

Comments
 (0)