Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions source/algorithms.tex
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,29 @@
find_if_not(R&& r, Pred pred, Proj proj = {});
}

// \ref{alg.find.last}, find last
namespace ranges {
template<@\libconcept{forward_iterator}@ I, @\libconcept{sentinel_for}@<I> S, class T, class Proj = identity>
requires @\libconcept{indirect_binary_predicate}@<ranges::equal_to, projected<I, Proj>, const T*>
constexpr subrange<I> find_last(I first, S last, const T& value, Proj proj = {});
template<@\libconcept{forward_range}@ R, class T, class Proj = identity>
requires
@\libconcept{indirect_binary_predicate}@<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
constexpr borrowed_subrange_t<R> find_last(R&& r, const T& value, Proj proj = {});
template<@\libconcept{forward_iterator}@ I, @\libconcept{sentinel_for}@<I> S, class Proj = identity,
@\libconcept{indirect_unary_predicate}@<projected<I, Proj>> Pred>
constexpr subrange<I> find_last_if(I first, S last, Pred pred, Proj proj = {});
template<@\libconcept{forward_range}@ R, class Proj = identity,
@\libconcept{indirect_unary_predicate}@<projected<iterator_t<R>, Proj>> Pred>
constexpr borrowed_subrange_t<R> find_last_if(R&& r, Pred pred, Proj proj = {});
template<@\libconcept{forward_iterator}@ I, @\libconcept{sentinel_for}@<I> S, class Proj = identity,
@\libconcept{indirect_unary_predicate}@<projected<I, Proj>> Pred>
constexpr subrange<I> find_last_if_not(I first, S last, Pred pred, Proj proj = {});
template<@\libconcept{forward_range}@ R, class Proj = identity,
@\libconcept{indirect_unary_predicate}@<projected<iterator_t<R>, Proj>> Pred>
constexpr borrowed_subrange_t<R> find_last_if_not(R&& r, Pred pred, Proj proj = {});
}

// \ref{alg.find.end}, find end
template<class ForwardIterator1, class ForwardIterator2>
constexpr ForwardIterator1
Expand Down Expand Up @@ -3514,6 +3537,55 @@
of the corresponding predicate and any projection.
\end{itemdescr}

\rSec2[alg.find.last]{Find last}

\indexlibraryglobal{find_last}%
\begin{itemdecl}
template<@\libconcept{forward_iterator}@ I, @\libconcept{sentinel_for}@<I> S, class T, class Proj = identity>
requires @\libconcept{indirect_binary_predicate}@<ranges::equal_to, projected<I, Proj>, const T*>
constexpr subrange<I> ranges::find_last(I first, S last, const T& value, Proj proj = {});
template<@\libconcept{forward_range}@ R, class T, class Proj = identity>
requires @\libconcept{indirect_binary_predicate}@<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
constexpr borrowed_subrange_t<R> ranges::find_last(R&& r, const T& value, Proj proj = {});
template<@\libconcept{forward_iterator}@ I, @\libconcept{sentinel_for}@<I> S, class Proj = identity,
@\libconcept{indirect_unary_predicate}@<projected<I, Proj>> Pred>
constexpr subrange<I> ranges::find_last_if(I first, S last, Pred pred, Proj proj = {});
template<@\libconcept{forward_range}@ R, class Proj = identity,
@\libconcept{indirect_unary_predicate}@<projected<iterator_t<R>, Proj>> Pred>
constexpr borrowed_subrange_t<R> ranges::find_last_if(R&& r, Pred pred, Proj proj = {});
template<@\libconcept{forward_iterator}@ I, @\libconcept{sentinel_for}@<I> S, class Proj = identity,
@\libconcept{indirect_unary_predicate}@<projected<I, Proj>> Pred>
constexpr subrange<I> ranges::find_last_if_not(I first, S last, Pred pred, Proj proj = {});
template<@\libconcept{forward_range}@ R, class Proj = identity,
@\libconcept{indirect_unary_predicate}@<projected<iterator_t<R>, Proj>> Pred>
constexpr borrowed_subrange_t<R> ranges::find_last_if_not(R&& r, Pred pred, Proj proj = {});
\end{itemdecl}

\begin{itemdescr}
\pnum
Let $E$ be:
\begin{itemize}
\item
\tcode{bool(invoke(proj, *i) == value)} for \tcode{ranges::find_last};
\item
\tcode{bool(invoke(pred, invoke(proj, *i)))} for \tcode{ranges::find_last_if};
\item
\tcode{bool(!invoke(pred, invoke(proj, *i)))} for \tcode{ranges::find_last_if_not}.
\end{itemize}

\pnum
\returns
Let \tcode{i} be the last iterator in the range \range{first}{last}
for which $E$ is \tcode{true}.
Returns \tcode{\{i, last\}}, or
\tcode{\{last, last\}} if no such iterator is found.

\pnum
\complexity
At most \tcode{last - first} applications of
the corresponding predicate and projection.
\end{itemdescr}

\rSec2[alg.find.end]{Find end}

\indexlibraryglobal{find_end}%
Expand Down
1 change: 1 addition & 0 deletions source/support.tex
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@
#define @\defnlibxname{cpp_lib_execution}@ 201902L // also in \libheader{execution}
#define @\defnlibxname{cpp_lib_expected}@ 202202L // also in \libheader{expected}
#define @\defnlibxname{cpp_lib_filesystem}@ 201703L // also in \libheader{filesystem}
#define @\defnlibxname{cpp_lib_find_last}@ 202207L // also in \libheader{algorithm}
#define @\defnlibxname{cpp_lib_flat_map}@ 202207L // also in \libheader{flat_map}
#define @\defnlibxname{cpp_lib_format}@ 202110L // also in \libheader{format}
#define @\defnlibxname{cpp_lib_gcd_lcm}@ 201606L // also in \libheader{numeric}
Expand Down