Skip to content

Commit 0375835

Browse files
committed
[alg.min.max] Reword min/max/minmax in modern style
... to clarify the meaning of "smaller"/"smallest"/"larger"/"largest" with a custom comparison predicate and/or projection.
1 parent 8410aac commit 0375835

File tree

1 file changed

+58
-31
lines changed

1 file changed

+58
-31
lines changed

source/algorithms.tex

Lines changed: 58 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8724,19 +8724,20 @@
87248724
\end{itemdecl}
87258725

87268726
\begin{itemdescr}
8727+
\pnum
8728+
Let \tcode{comp} be \tcode{less\{\}}
8729+
and \tcode{proj} be \tcode{identity\{\}}
8730+
for the overloads with no parameters by those names.
8731+
87278732
\pnum
87288733
\expects
87298734
For the first form, \tcode{T} meets the
87308735
\oldconcept{LessThanComparable} requirements (\tref{cpp17.lessthancomparable}).
87318736

87328737
\pnum
8733-
\returns
8734-
The smaller value.
8735-
Returns the first argument when the arguments are equivalent.
8736-
8737-
\pnum
8738-
\complexity
8739-
Exactly one comparison and two applications of the projection, if any.
8738+
\effects
8739+
Equivalent to:
8740+
\tcode{return invoke(comp, invoke(proj, b), invoke(proj, a)) ? b : a;}
87408741

87418742
\pnum
87428743
\remarks
@@ -8763,6 +8764,11 @@
87638764
\end{itemdecl}
87648765

87658766
\begin{itemdescr}
8767+
\pnum
8768+
Let \tcode{comp} be \tcode{less\{\}}
8769+
and \tcode{proj} be \tcode{identity\{\}}
8770+
for the overloads with no parameters by those names.
8771+
87668772
\pnum
87678773
\expects
87688774
\tcode{ranges::distance(r) > 0}.
@@ -8773,14 +8779,14 @@
87738779

87748780
\pnum
87758781
\returns
8776-
The smallest value in the input range.
8777-
Returns a copy of the leftmost element
8778-
when several elements are equivalent to the smallest.
8782+
Returns a copy of the leftmost element \tcode{e} in the input range \tcode{r}
8783+
for which \tcode{bool(invoke(comp, invoke(proj, x), invoke(proj, e)))}
8784+
is \tcode{false} for all elements \tcode{x} in \tcode{r}.
87798785

87808786
\pnum
87818787
\complexity
87828788
Exactly \tcode{ranges::distance(r) - 1} comparisons
8783-
and twice as many applications of the projection, if any.
8789+
and twice as many applications of the projection.
87848790

87858791
\pnum
87868792
\remarks
@@ -8802,19 +8808,20 @@
88028808
\end{itemdecl}
88038809

88048810
\begin{itemdescr}
8811+
\pnum
8812+
Let \tcode{comp} be \tcode{less\{\}}
8813+
and \tcode{proj} be \tcode{identity\{\}}
8814+
for the overloads with no parameters by those names.
8815+
88058816
\pnum
88068817
\expects
88078818
For the first form, \tcode{T} meets the
88088819
\oldconcept{LessThanComparable} requirements (\tref{cpp17.lessthancomparable}).
88098820

88108821
\pnum
8811-
\returns
8812-
The larger value.
8813-
Returns the first argument when the arguments are equivalent.
8814-
8815-
\pnum
8816-
\complexity
8817-
Exactly one comparison and two applications of the projection, if any.
8822+
\effects
8823+
Equivalent to:
8824+
\tcode{return invoke(comp, invoke(proj, a), invoke(proj, b)) ? b : a;}
88188825

88198826
\pnum
88208827
\remarks
@@ -8841,6 +8848,11 @@
88418848
\end{itemdecl}
88428849

88438850
\begin{itemdescr}
8851+
\pnum
8852+
Let \tcode{comp} be \tcode{less\{\}}
8853+
and \tcode{proj} be \tcode{identity\{\}}
8854+
for the overloads with no parameters by those names.
8855+
88448856
\pnum
88458857
\expects
88468858
\tcode{ranges::distance(r) > 0}.
@@ -8851,14 +8863,14 @@
88518863

88528864
\pnum
88538865
\returns
8854-
The largest value in the input range.
8855-
Returns a copy of the leftmost element
8856-
when several elements are equivalent to the largest.
8866+
Returns a copy of the leftmost element \tcode{e} in the input range \tcode{r}
8867+
for which \tcode{bool(invoke(comp, invoke(proj, e), invoke(proj, x)))}
8868+
is \tcode{false} for all elements \tcode{x} in \tcode{r}.
88578869

88588870
\pnum
88598871
\complexity
88608872
Exactly \tcode{ranges::distance(r) - 1} comparisons
8861-
and twice as many applications of the projection, if any.
8873+
and twice as many applications of the projection.
88628874

88638875
\pnum
88648876
\remarks
@@ -8882,19 +8894,25 @@
88828894

88838895

88848896
\begin{itemdescr}
8897+
\pnum
8898+
Let \tcode{comp} be \tcode{less\{\}}
8899+
and \tcode{proj} be \tcode{identity\{\}}
8900+
for the overloads with no parameters by those names.
8901+
88858902
\pnum
88868903
\expects
88878904
For the first form, \tcode{T} meets the
88888905
\oldconcept{LessThanComparable} requirements (\tref{cpp17.lessthancomparable}).
88898906

88908907
\pnum
88918908
\returns
8892-
\tcode{\{b, a\}} if \tcode{b} is smaller than \tcode{a}, and
8893-
\tcode{\{a, b\}} otherwise.
8909+
\tcode{\{b, a\}} if
8910+
\tcode{bool(invoke(comp, invoke(proj, b), invoke(proj, a)))} is \tcode{true},
8911+
and \tcode{\{a, b\}} otherwise.
88948912

88958913
\pnum
88968914
\complexity
8897-
Exactly one comparison and two applications of the projection, if any.
8915+
Exactly one comparison and two applications of the projection.
88988916

88998917
\pnum
89008918
\remarks
@@ -8922,6 +8940,11 @@
89228940
\end{itemdecl}
89238941

89248942
\begin{itemdescr}
8943+
\pnum
8944+
Let \tcode{comp} be \tcode{less\{\}}
8945+
and \tcode{proj} be \tcode{identity\{\}}
8946+
for the overloads with no parameters by those names.
8947+
89258948
\pnum
89268949
\expects
89278950
\tcode{ranges::distance(r) > 0}.
@@ -8934,15 +8957,19 @@
89348957
\returns
89358958
Let \tcode{X} be the return type.
89368959
Returns \tcode{X\{x, y\}},
8937-
where \tcode{x} is a copy of the leftmost element with the smallest value and
8938-
\tcode{y} a copy of the rightmost element with the largest value
8939-
in the input range.
8960+
where \tcode{x} is a copy of
8961+
the leftmost element in the input range \tcode{r} for which
8962+
\tcode{bool(invoke(comp, invoke(proj, e), invoke(proj, x)))}
8963+
is \tcode{false} for all elements \tcode{e} in \tcode{r}
8964+
and \tcode{y} is a copy of
8965+
the rightmost element in \tcode{r} for which
8966+
\tcode{bool(invoke(comp, invoke(proj, y), invoke(proj, e)))}
8967+
is \tcode{false} for all elements \tcode{e} in \tcode{r}.
89408968

89418969
\pnum
89428970
\complexity
8943-
At most $(3/2)\tcode{ranges::distance(r)}$ applications
8944-
of the corresponding predicate
8945-
and twice as many applications of the projection, if any.
8971+
At most $(3/2)\tcode{ranges::distance(r)}$ comparisons
8972+
and twice as many applications of the projection.
89468973

89478974
\pnum
89488975
\remarks

0 commit comments

Comments
 (0)