Skip to content

Commit b686c6e

Browse files
authored
Merge 2021-06 LWG Motion 10
P1659R3 starts_with and ends_with
2 parents 95e04be + 9418a95 commit b686c6e

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

source/algorithms.tex

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,36 @@
11311131
constexpr ForwardIterator
11321132
search(ForwardIterator first, ForwardIterator last, const Searcher& searcher);
11331133

1134+
namespace ranges {
1135+
// \ref{alg.starts.with}, starts with
1136+
template<@\libconcept{input_iterator}@ I1, @\libconcept{sentinel_for}@<I1> S1, @\libconcept{input_iterator}@ I2, @\libconcept{sentinel_for}@<I2> S2,
1137+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
1138+
requires @\libconcept{indirectly_comparable}@<I1, I2, Pred, Proj1, Proj2>
1139+
constexpr bool starts_with(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
1140+
Proj1 proj1 = {}, Proj2 proj2 = {});
1141+
template<@\libconcept{input_range}@ R1, @\libconcept{input_range}@ R2, class Pred = ranges::equal_to,
1142+
class Proj1 = identity, class Proj2 = identity>
1143+
requires @\libconcept{indirectly_comparable}@<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
1144+
constexpr bool starts_with(R1&& r1, R2&& r2, Pred pred = {},
1145+
Proj1 proj1 = {}, Proj2 proj2 = {});
1146+
1147+
// \ref{alg.ends.with}, ends with
1148+
template<@\libconcept{input_iterator}@ I1, @\libconcept{sentinel_for}@<I1> S1, @\libconcept{input_iterator}@ I2, @\libconcept{sentinel_for}@<I2> S2,
1149+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
1150+
requires (@\libconcept{forward_iterator}@<I1> || @\libconcept{sized_sentinel_for}@<S1, I1>) &&
1151+
(@\libconcept{forward_iterator}@<I2> || @\libconcept{sized_sentinel_for}@<S2, I2>) &&
1152+
@\libconcept{indirectly_comparable}@<I1, I2, Pred, Proj1, Proj2>
1153+
constexpr bool ends_with(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
1154+
Proj1 proj1 = {}, Proj2 proj2 = {});
1155+
template<@\libconcept{input_range}@ R1, @\libconcept{input_range}@ R2, class Pred = ranges::equal_to,
1156+
class Proj1 = identity, class Proj2 = identity>
1157+
requires (@\libconcept{forward_range}@<R1> || @\libconcept{sized_range}@<R1>) &&
1158+
(@\libconcept{forward_range}@<R2> || @\libconcept{sized_range}@<R2>) &&
1159+
@\libconcept{indirectly_comparable}@<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
1160+
constexpr bool ends_with(R1&& r1, R2&& r2, Pred pred = {},
1161+
Proj1 proj1 = {}, Proj2 proj2 = {});
1162+
}
1163+
11341164
// \ref{alg.modifying.operations}, mutating sequence operations
11351165
// \ref{alg.copy}, copy
11361166
template<class InputIterator, class OutputIterator>
@@ -4219,6 +4249,81 @@
42194249
\tcode{Searcher} need not meet the \oldconcept{CopyConstructible} requirements.
42204250
\end{itemdescr}
42214251

4252+
\rSec2[alg.starts.with]{Starts with}
4253+
4254+
\indexlibraryglobal{starts_with}%
4255+
\begin{itemdecl}
4256+
template<@\libconcept{input_iterator}@ I1, @\libconcept{sentinel_for}@<I1> S1, @\libconcept{input_iterator}@ I2, @\libconcept{sentinel_for}@<I2> S2,
4257+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
4258+
requires @\libconcept{indirectly_comparable}@<I1, I2, Pred, Proj1, Proj2>
4259+
constexpr bool ranges::starts_with(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
4260+
Proj1 proj1 = {}, Proj2 proj2 = {});
4261+
template<@\libconcept{input_range}@ R1, @\libconcept{input_range}@ R2, class Pred = ranges::equal_to, class Proj1 = identity,
4262+
class Proj2 = identity>
4263+
requires @\libconcept{indirectly_comparable}@<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
4264+
constexpr bool ranges::starts_with(R1&& r1, R2&& r2, Pred pred = {},
4265+
Proj1 proj1 = {}, Proj2 proj2 = {});
4266+
\end{itemdecl}
4267+
4268+
\begin{itemdescr}
4269+
\pnum
4270+
\returns
4271+
\begin{codeblock}
4272+
ranges::mismatch(std::move(first1), last1, std::move(first2), last2,
4273+
pred, proj1, proj2).in2 == last2
4274+
\end{codeblock}
4275+
\end{itemdescr}
4276+
4277+
\rSec2[alg.ends.with]{Ends with}
4278+
4279+
\indexlibraryglobal{ends_with}%
4280+
\begin{itemdecl}
4281+
template<@\libconcept{input_iterator}@ I1, @\libconcept{sentinel_for}@<I1> S1, @\libconcept{input_iterator}@ I2, @\libconcept{sentinel_for}@<I2> S2,
4282+
class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity>
4283+
requires (@\libconcept{forward_iterator}@<I1> || @\libconcept{sized_sentinel_for}@<S1, I1>) &&
4284+
(@\libconcept{forward_iterator}@<I2> || @\libconcept{sized_sentinel_for}@<S2, I2>) &&
4285+
@\libconcept{indirectly_comparable}@<I1, I2, Pred, Proj1, Proj2>
4286+
constexpr bool ranges::ends_with(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {},
4287+
Proj1 proj1 = {}, Proj2 proj2 = {});
4288+
\end{itemdecl}
4289+
4290+
\begin{itemdescr}
4291+
\pnum
4292+
Let \tcode{N1} be \tcode{last1 - first1} and
4293+
\tcode{N2} be \tcode{last2 - first2}.
4294+
4295+
\pnum
4296+
\returns
4297+
\tcode{false} if $\tcode{N1} < \tcode{N2}$, otherwise
4298+
\begin{codeblock}
4299+
ranges::equal(std::move(first1) + (N1 - N2), last1, std::move(first2), last2,
4300+
pred, proj1, proj2)
4301+
\end{codeblock}
4302+
\end{itemdescr}
4303+
4304+
\begin{itemdecl}
4305+
template<@\libconcept{input_range}@ R1, @\libconcept{input_range}@ R2, class Pred = ranges::equal_to, class Proj1 = identity,
4306+
class Proj2 = identity>
4307+
requires (@\libconcept{forward_range}@<R1> || @\libconcept{sized_range}@<R1>) &&
4308+
(@\libconcept{forward_range}@<R2> || @\libconcept{sized_range}@<R2>) &&
4309+
@\libconcept{indirectly_comparable}@<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
4310+
constexpr bool ranges::ends_with(R1&& r1, R2&& r2, Pred pred = {},
4311+
Proj1 proj1 = {}, Proj2 proj2 = {});
4312+
\end{itemdecl}
4313+
4314+
\begin{itemdescr}
4315+
\pnum
4316+
Let \tcode{N1} be \tcode{ranges::distance(r1)} and
4317+
\tcode{N2} be \tcode{ranges::distance(r2)}.
4318+
4319+
\pnum
4320+
\returns
4321+
\tcode{false} if $\tcode{N1} < \tcode{N2}$, otherwise
4322+
\begin{codeblock}
4323+
ranges::equal(ranges::drop_view(ranges::ref_view(r1), N1 - N2), r2, pred, proj1, proj2)
4324+
\end{codeblock}
4325+
\end{itemdescr}
4326+
42224327
\rSec1[alg.modifying.operations]{Mutating sequence operations}
42234328

42244329
\rSec2[alg.copy]{Copy}

source/support.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@
661661
#define @\defnlibxname{cpp_lib_quoted_string_io}@ 201304L // also in \libheader{iomanip}
662662
#define @\defnlibxname{cpp_lib_ranges}@ 201911L
663663
// also in \libheader{algorithm}, \libheader{functional}, \libheader{iterator}, \libheader{memory}, \libheader{ranges}
664+
#define @\defnlibxname{cpp_lib_ranges_starts_ends_with}@ 202106L // also in \libheader{algorithm}
664665
#define @\defnlibxname{cpp_lib_raw_memory_algorithms}@ 201606L // also in \libheader{memory}
665666
#define @\defnlibxname{cpp_lib_remove_cvref}@ 201711L // also in \libheader{type_traits}
666667
#define @\defnlibxname{cpp_lib_result_of_sfinae}@ 201210L // also in \libheader{functional}, \libheader{type_traits}

0 commit comments

Comments
 (0)