diff --git a/source/algorithms.tex b/source/algorithms.tex index 04cb156bc8..04273a3283 100644 --- a/source/algorithms.tex +++ b/source/algorithms.tex @@ -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}@ S, class T, class Proj = identity> + requires @\libconcept{indirect_binary_predicate}@, const T*> + constexpr subrange 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}@, Proj>, const T*> + constexpr borrowed_subrange_t find_last(R&& r, const T& value, Proj proj = {}); + template<@\libconcept{forward_iterator}@ I, @\libconcept{sentinel_for}@ S, class Proj = identity, + @\libconcept{indirect_unary_predicate}@> Pred> + constexpr subrange find_last_if(I first, S last, Pred pred, Proj proj = {}); + template<@\libconcept{forward_range}@ R, class Proj = identity, + @\libconcept{indirect_unary_predicate}@, Proj>> Pred> + constexpr borrowed_subrange_t find_last_if(R&& r, Pred pred, Proj proj = {}); + template<@\libconcept{forward_iterator}@ I, @\libconcept{sentinel_for}@ S, class Proj = identity, + @\libconcept{indirect_unary_predicate}@> Pred> + constexpr subrange find_last_if_not(I first, S last, Pred pred, Proj proj = {}); + template<@\libconcept{forward_range}@ R, class Proj = identity, + @\libconcept{indirect_unary_predicate}@, Proj>> Pred> + constexpr borrowed_subrange_t find_last_if_not(R&& r, Pred pred, Proj proj = {}); + } + // \ref{alg.find.end}, find end template constexpr ForwardIterator1 @@ -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}@ S, class T, class Proj = identity> + requires @\libconcept{indirect_binary_predicate}@, const T*> + constexpr subrange 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}@, Proj>, const T*> + constexpr borrowed_subrange_t ranges::find_last(R&& r, const T& value, Proj proj = {}); +template<@\libconcept{forward_iterator}@ I, @\libconcept{sentinel_for}@ S, class Proj = identity, + @\libconcept{indirect_unary_predicate}@> Pred> + constexpr subrange ranges::find_last_if(I first, S last, Pred pred, Proj proj = {}); +template<@\libconcept{forward_range}@ R, class Proj = identity, + @\libconcept{indirect_unary_predicate}@, Proj>> Pred> + constexpr borrowed_subrange_t ranges::find_last_if(R&& r, Pred pred, Proj proj = {}); +template<@\libconcept{forward_iterator}@ I, @\libconcept{sentinel_for}@ S, class Proj = identity, + @\libconcept{indirect_unary_predicate}@> Pred> + constexpr subrange 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}@, Proj>> Pred> + constexpr borrowed_subrange_t 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}% diff --git a/source/support.tex b/source/support.tex index cdcdaf1bbe..181fdf754f 100644 --- a/source/support.tex +++ b/source/support.tex @@ -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}