Skip to content

Commit b097af4

Browse files
authored
Merge 2022-07 LWG Motion 16
P2302R4 std::ranges::contains
2 parents 0a9cfa5 + 231ba17 commit b097af4

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

source/algorithms.tex

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,29 @@
695695
constexpr bool none_of(R&& r, Pred pred, Proj proj = {});
696696
}
697697

698+
// \ref{alg.contains}, contains
699+
namespace ranges {
700+
template<@\libconcept{input_iterator}@ I, @\libconcept{sentinel_for}@<I> S, class T, class Proj = identity>
701+
requires @\libconcept{indirect_binary_predicate}@<ranges::equal_to, projected<I, Proj>, const T*>
702+
constexpr bool contains(I first, S last, const T& value, Proj proj = {});
703+
template<@\libconcept{input_range}@ R, class T, class Proj = identity>
704+
requires
705+
@\libconcept{indirect_binary_predicate}@<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
706+
constexpr bool contains(R&& r, const T& value, Proj proj = {});
707+
708+
template<@\libconcept{forward_iterator}@ I1, @\libconcept{sentinel_for}@<I1> S1,
709+
@\libconcept{forward_iterator}@ I2, @\libconcept{sentinel_for}@<I2> S2,
710+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
711+
requires @\libconcept{indirectly_comparable}@<I1, I2, Pred, Proj1, Proj2>
712+
constexpr bool contains_subrange(I1 first1, S1 last1, I2 first2, S2 last2,
713+
Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
714+
template<@\libconcept{forward_range}@ R1, @\libconcept{forward_range}@ R2,
715+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
716+
requires @\libconcept{indirectly_comparable}@<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
717+
constexpr bool contains_subrange(R1&& r1, R2&& r2,
718+
Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
719+
}
720+
698721
// \ref{alg.foreach}, for each
699722
template<class InputIterator, class Function>
700723
constexpr Function for_each(InputIterator first, InputIterator last, Function f);
@@ -3223,6 +3246,45 @@
32233246
At most \tcode{last - first} applications of the predicate and any projection.
32243247
\end{itemdescr}
32253248

3249+
\rSec2[alg.contains]{Contains}
3250+
3251+
\indexlibraryglobal{contains}%
3252+
\begin{itemdecl}
3253+
template<@\libconcept{input_iterator}@ I, @\libconcept{sentinel_for}@<I> S, class T, class Proj = identity>
3254+
requires @\libconcept{indirect_binary_predicate}@<ranges::equal_to, projected<I, Proj>, const T*>
3255+
constexpr bool ranges::contains(I first, S last, const T& value, Proj proj = {});
3256+
template<@\libconcept{input_range}@ R, class T, class Proj = identity>
3257+
requires @\libconcept{indirect_binary_predicate}@<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
3258+
constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {});
3259+
\end{itemdecl}
3260+
3261+
\begin{itemdescr}
3262+
\pnum
3263+
\returns
3264+
\tcode{ranges::find(std::move(first), last, value, proj) != last}.
3265+
\end{itemdescr}
3266+
3267+
\indexlibraryglobal{contains_subrange}%
3268+
\begin{itemdecl}
3269+
template<@\libconcept{forward_iterator}@ I1, @\libconcept{sentinel_for}@<I1> S1,
3270+
@\libconcept{forward_iterator}@ I2, @\libconcept{sentinel_for}@<I2> S2,
3271+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
3272+
requires @\libconcept{indirectly_comparable}@<I1, I2, Pred, Proj1, Proj2>
3273+
constexpr bool ranges::contains_subrange(I1 first1, S1 last1, I2 first2, S2 last2,
3274+
Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});
3275+
template<@\libconcept{forward_range}@ R1, @\libconcept{forward_range}@ R2,
3276+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
3277+
requires @\libconcept{indirectly_comparable}@<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
3278+
constexpr bool ranges::contains_subrange(R1&& r1, R2&& r2, Pred pred = {},
3279+
Proj1 proj1 = {}, Proj2 proj2 = {});
3280+
\end{itemdecl}
3281+
3282+
\begin{itemdescr}
3283+
\pnum
3284+
\returns
3285+
\tcode{first2 == last2 || !ranges::search(first1, last1, first2, last2, pred, proj1, proj2).empty()}.
3286+
\end{itemdescr}
3287+
32263288
\rSec2[alg.foreach]{For each}
32273289

32283290
\indexlibraryglobal{for_each}%

source/support.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@
680680
#define @\defnlibxname{cpp_lib_ranges_as_const}@ 202207L // also in \libheader{ranges}
681681
#define @\defnlibxname{cpp_lib_ranges_chunk}@ 202202L // also in \libheader{ranges}
682682
#define @\defnlibxname{cpp_lib_ranges_chunk_by}@ 202202L // also in \libheader{ranges}
683+
#define @\defnlibxname{cpp_lib_ranges_contains}@ 202207L // also in \libheader{algorithm}
683684
#define @\defnlibxname{cpp_lib_ranges_iota}@ 202202L // also in \libheader{numeric}
684685
#define @\defnlibxname{cpp_lib_ranges_join_with}@ 202202L // also in \libheader{ranges}
685686
#define @\defnlibxname{cpp_lib_ranges_slide}@ 202202L // also in \libheader{ranges}

0 commit comments

Comments
 (0)