Topic: Overloading the family of minmax algorithms
Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Fri, 1 May 2015 06:47:56 -0700 (PDT)
Raw View
------=_Part_1031_1686269933.1430488076203
Content-Type: multipart/alternative;
boundary="----=_Part_1032_797074472.1430488076203"
------=_Part_1032_797074472.1430488076203
Content-Type: text/plain; charset=UTF-8
As it is known for example standard algorithm std::minmax_element returns a
pair of iterators where the first element of the pair points to the first
minimum element in the given sequence while the second element of the pair
points to the last maximum element in the given sequence.
A natural question arises how to apply the algorithm that to find for
example the first and last minimum elements or the first and last maximum
elements in the given sequence?
This task othen occurs in practice.
It can be resolved very simple if to introduce an overloaded algorithm that
accepts a pair of comparators.
It looks the following way
template <class ForwardIterator, class Compare1, class Compare2>
std::pair<ForwardIterator, ForwardIterator>
minmax_element( ForwardIterator first,
ForwardIterator last,
std::pair<Compare1, Compare2> comp );
In this case to find for example the first and last minimum elements for
the given sequence it is enough to write
auto p = ::minmax_element( std::begin( a ), std::end( a ),
std::make_pair( std::less<>(),
std::greater<>() ) );
Or to find for example the first and last maximum elements for the given
sequence it is enough to write
auto p = ::minmax_element( std::begin( a ), std::end( a ),
std::make_pair( std::greater<>(),
std::less<>() ) );
If you will run the following demonstrative program (to write the
implementation of the algorithm is your homework :) )
#include <iostream>
#include <algorithm>
#include <iterator>
#include <functional>
template <class ForwardIterator, class Compare1, class Compare2>
std::pair<ForwardIterator, ForwardIterator>
minmax_element( ForwardIterator first,
ForwardIterator last,
std::pair<Compare1, Compare2> comp )
{
// ...
}
int main()
{
int a[] = { 5, 3, 1, 6, 2, 6, 1 };
auto p = std::minmax_element( std::begin( a ), std::end( a ) );
std::cout << "min: " << std::distance( std::begin( a ), p.first ) <<
std::endl;
std::cout << "max: " << std::distance( std::begin( a ), p.second ) <<
std::endl;
std::cout << std::endl;
p = ::minmax_element( std::begin( a ), std::end( a ),
std::make_pair( std::less<>(), std::greater<>() )
);
std::cout << "min: " << std::distance( std::begin( a ), p.first ) <<
std::endl;
std::cout << "min: " << std::distance( std::begin( a ), p.second ) <<
std::endl;
std::cout << std::endl;
p = ::minmax_element( std::begin( a ), std::end( a ),
std::make_pair( std::greater<>(), std::less<>() )
);
std::cout << "max: " << std::distance( std::begin( a ), p.first ) <<
std::endl;
std::cout << "max: " << std::distance( std::begin( a ), p.second ) <<
std::endl;
}
you get the following output
min: 2
max: 5
min: 2
min: 6
max: 3
max: 5
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_1032_797074472.1430488076203
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>As it is known for example standard algorithm std::mi=
nmax_element returns a pair of iterators where the first element of the pai=
r points to the first minimum element in the given sequence while the secon=
d element of the pair points to the last maximum element in the given seque=
nce.</div><div><br></div><div>A natural question arises how to apply the al=
gorithm that to find for example the first and last minimum elements o=
r the first and last maximum elements in the given sequence?</div><div><br>=
</div><div>This task othen occurs in practice. </div><div><br></d=
iv><div>It can be resolved very simple if to introduce an overloaded a=
lgorithm that accepts a pair of comparators.</div><div><br></div><div>It lo=
oks the following way</div><div><br></div><div>template <class ForwardIt=
erator, class Compare1, class Compare2><br>std::pair<ForwardIterator,=
ForwardIterator><br>minmax_element( ForwardIterator first, <br> &n=
bsp;  =
; ForwardIterator last,<br> =
std::pair<Compare1, Com=
pare2> comp );</div><div><br></div><div>In this case to find for example=
the first and last minimum elements for the given sequence it is enough to=
write</div><div><br></div><div> auto p =3D ::minmax_elem=
ent( std::begin( a ), std::end( a ),<br>  =
; &n=
bsp; std:=
:make_pair( std::less<>(), std::greater<>() ) );</div><div><br>=
</div><div>Or to find for example the first and last maximum elements =
for the given sequence it is enough to write</div><div><br> &nbs=
p; auto p =3D ::minmax_element( std::begin( a ), std::end( a ),<br> &n=
bsp;  =
; &n=
bsp; std::make_pair( std::greater<>(), std::less<=
;>() ) );</div><div><br></div><div>If you will run the following de=
monstrative program (to write the implementation of the algorithm is your h=
omework :) )</div><div><br></div><div>#include <iostream><br>#include=
<algorithm><br>#include <iterator><br>#include <functional&=
gt;</div><div><br></div><div>template <class ForwardIterator, class Comp=
are1, class Compare2><br>std::pair<ForwardIterator, ForwardIterator&g=
t;<br>minmax_element( ForwardIterator first, <br> &n=
bsp; ForwardIte=
rator last,<br> =
std::pair<Compare1, Compare2> comp )<b=
r>{<br> // ...<br>}</div><div> &nbs=
p; </div>=
<div>int main()<br>{<br> int a[] =3D { 5, 3, 1, 6, 2, 6, =
1 };<br> <br> auto p =3D std::minmax_el=
ement( std::begin( a ), std::end( a ) );<br> <br> &n=
bsp; std::cout << "min: " << std::distance( std::begin( a=
), p.first ) << std::endl;<br> std::cout << =
"max: " << std::distance( std::begin( a ), p.second ) << std::e=
ndl;<br> <br> std::cout << std::e=
ndl;<br> <br> p =3D ::minmax_element( s=
td::begin( a ), std::end( a ),<br>  =
; &n=
bsp; std::make_pair( std::less<>(), std=
::greater<>() ) );</div><div> std::cout << "m=
in: " << std::distance( std::begin( a ), p.first ) << std::endl=
;<br> std::cout << "min: " << std::distance( =
std::begin( a ), p.second ) << std::endl;<br> <br>&=
nbsp; std::cout << std::endl;<br> <br>&=
nbsp; p =3D ::minmax_element( std::begin( a ), std::end( a ),<b=
r> &=
nbsp; &nbs=
p; std::make_pair( std::greater<>(), std::less<>() ) );</div><d=
iv> std::cout << "max: " << std::distance( st=
d::begin( a ), p.first ) << std::endl;<br> std::cou=
t << "max: " << std::distance( std::begin( a ), p.second ) <=
< std::endl;<br> <br>}<br><br>you get the following ou=
tput</div><div><br></div><div>min: 2</div><div>max: 5</div><div><br></div><=
div>min: 2</div><div>min: 6</div><div><br></div><div>max: 3</div><div>max: =
5<br><br></div><div><br></div><div><br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_1032_797074472.1430488076203--
------=_Part_1031_1686269933.1430488076203--
.
Author: David Krauss <potswa@gmail.com>
Date: Fri, 1 May 2015 22:10:50 +0800
Raw View
--Apple-Mail=_B0CDF983-15B2-4B05-9F94-BC709AAB0CD0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
> On 2015=E2=80=9305=E2=80=9301, at 9:47 PM, Vlad from Moscow <vlad.moscow@=
mail.ru> wrote:
>=20
> A natural question arises how to apply the algorithm that to find for exa=
mple the first and last minimum elements or the first and last maximum elem=
ents in the given sequence?
>=20
> This task othen occurs in practice.
In practice of what? ;)
> template <class ForwardIterator, class Compare1, class Compare2>
> std::pair<ForwardIterator, ForwardIterator>
> minmax_element( ForwardIterator first,=20
> ForwardIterator last,
> std::pair<Compare1, Compare2> comp );
Is there another application of this template? Why not
template <class ForwardIterator, class Compare =3D less<> >
pair<ForwardIterator, ForwardIterator>
firstlast_min_element( ForwardIterator first,=20
ForwardIterator last,
Compare comp =3D {} );
This only needs one comparator and as little as half the comparisons.
> In this case to find for example the first and last minimum elements for =
the given sequence it is enough to write
>=20
> auto p =3D ::minmax_element( std::begin( a ), std::end( a ),
> std::make_pair( std::less<>(), std::greate=
r<>() ) );
>=20
> Or to find for example the first and last maximum elements for the given =
sequence it is enough to write
>=20
> auto p =3D ::minmax_element( std::begin( a ), std::end( a ),
> std::make_pair( std::greater<>(), std::les=
s<>() ) );
It=E2=80=99s far from clear which of these is which.
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--Apple-Mail=_B0CDF983-15B2-4B05-9F94-BC709AAB0CD0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9305=
=E2=80=9301, at 9:47 PM, Vlad from Moscow <<a href=3D"mailto:vlad.moscow=
@mail.ru" class=3D"">vlad.moscow@mail.ru</a>> wrote:</div><br class=3D"A=
pple-interchange-newline"><div class=3D""><div dir=3D"ltr" class=3D""><div =
class=3D"">A natural question arises how to apply the algorithm that to fin=
d for example the first and last minimum elements or the first and las=
t maximum elements in the given sequence?</div><div class=3D""><br class=3D=
""></div><div class=3D"">This task othen occurs in practice. </di=
v><div class=3D""></div></div></div></blockquote><div><br class=3D""></div>=
<div>In practice of what? ;)</div><br class=3D""><blockquote type=3D"cite" =
class=3D""><div class=3D""><div dir=3D"ltr" class=3D""><div class=3D"">temp=
late <class ForwardIterator, class Compare1, class Compare2></div><di=
v class=3D"">std::pair<ForwardIterator, ForwardIterator><br class=3D"=
">minmax_element( ForwardIterator first, <br class=3D""> &=
nbsp; For=
wardIterator last,<br class=3D""> =
std::pair<Compare1, Com=
pare2> comp );</div></div></div></blockquote><div><br class=3D""></div><=
div>Is there another application of this template? Why not</div><div><br cl=
ass=3D""></div><div><font face=3D"Courier" class=3D"">template <class Fo=
rwardIterator, </font><span style=3D"font-family: Courier;" class=3D""=
>class Compare =3D less<> ></span></div><div><font face=3D"Courier=
" class=3D"">pair<ForwardIterator, ForwardIterator><br class=3D"">fir=
stlast_min_element( ForwardIterator first, <br class=3D"">  =
; Forw=
ardIterator last,</font></div><div><font face=3D"Courier" class=3D""> =
&nbs=
p;Compare comp =3D {} );<br class=3D""></font><br class=3D""></div><div>Thi=
s only needs one comparator and as little as half the comparisons.</div><br=
class=3D""><blockquote type=3D"cite" class=3D""><div class=3D""><div dir=
=3D"ltr" class=3D""><div class=3D"">In this case to find for example the fi=
rst and last minimum elements for the given sequence it is enough to write<=
/div><div class=3D""><br class=3D""></div><div class=3D"">  =
; auto p =3D ::minmax_element( std::begin( a ), std::end( a ),<br class=3D"=
"> &=
nbsp; &nbs=
p; std::make_pair( std::less<>(), std::=
greater<>() ) );</div><div class=3D""><br class=3D""></div><div class=
=3D"">Or to find for example the first and last maximum elements for t=
he given sequence it is enough to write</div><div class=3D""><br class=3D""=
> auto p =3D ::minmax_element( std::begin( a ), std::end(=
a ),<br class=3D""> &=
nbsp; &nbs=
p; std::make_pair( std::gre=
ater<>(), std::less<>() ) );</div><div class=3D""></div></div><=
/div></blockquote><div><br class=3D""></div><div>It=E2=80=99s far from clea=
r which of these is which.</div></div></body></html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--Apple-Mail=_B0CDF983-15B2-4B05-9F94-BC709AAB0CD0--
.
Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Fri, 1 May 2015 07:43:43 -0700 (PDT)
Raw View
------=_Part_1087_1086688575.1430491423174
Content-Type: multipart/alternative;
boundary="----=_Part_1088_1773945937.1430491423174"
------=_Part_1088_1773945937.1430491423174
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Friday, May 1, 2015 at 5:11:11 PM UTC+3, David Krauss wrote:
>
>
> On 2015=E2=80=9305=E2=80=9301, at 9:47 PM, Vlad from Moscow <vlad....@mai=
l.ru=20
> <javascript:>> wrote:
>
> A natural question arises how to apply the algorithm that to find for=20
> example the first and last minimum elements or the first and last maximum=
=20
> elements in the given sequence?
>
> This task othen occurs in practice.=20
>
>
> In practice of what? ;)
>
> In the practice of programming.=20
> template <class ForwardIterator, class Compare1, class Compare2>
> std::pair<ForwardIterator, ForwardIterator>
> minmax_element( ForwardIterator first,=20
> ForwardIterator last,
> std::pair<Compare1, Compare2> comp );
>
>
> Is there another application of this template? Why not
>
> template <class ForwardIterator, class Compare =3D less<> >
> pair<ForwardIterator, ForwardIterator>
> firstlast_min_element( ForwardIterator first,=20
> ForwardIterator last,
> Compare comp =3D {} );
>
> This only needs one comparator and as little as half the comparisons.
>
> It looks bad. It introduces a new name when it is not required and the=20
algorithm I proposed does not imply that only predicates I showed are used.=
=20
So my algorithm is very flexible In fact it does not mean for example that=
=20
the first and last minimum elements are searched It is simply a partial=20
case of using the algorithm.
> In this case to find for example the first and last minimum elements for=
=20
> the given sequence it is enough to write
>
> auto p =3D ::minmax_element( std::begin( a ), std::end( a ),
> std::make_pair( std::less<>(),=20
> std::greater<>() ) );
>
> Or to find for example the first and last maximum elements for the given=
=20
> sequence it is enough to write
>
> auto p =3D ::minmax_element( std::begin( a ), std::end( a ),
> std::make_pair( std::greater<>(),=20
> std::less<>() ) );
>
>
> It=E2=80=99s far from clear which of these is which.
>
It is enough clear because the algorithm is named minmax. So there is no=20
difference between the order of iterators in the return pair and the order=
=20
of comparators in the parameter of type pair.=20
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
------=_Part_1088_1773945937.1430491423174
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Friday, May 1, 2015 at 5:11:11 PM UTC+3, David =
Krauss wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px=
0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-le=
ft-width: 1px; border-left-style: solid;"><div style=3D"-ms-word-wrap: brea=
k-word;"><br><div><blockquote type=3D"cite"><div>On 2015=E2=80=9305=E2=80=
=9301, at 9:47 PM, Vlad from Moscow <<a onmousedown=3D"this.href=3D'java=
script:';return true;" onclick=3D"this.href=3D'javascript:';return true;" h=
ref=3D"javascript:" target=3D"_blank" rel=3D"nofollow" gdf-obfuscated-mailt=
o=3D"Uajm3BaC41cJ">vlad....@mail.ru</a>> wrote:</div><br><div><div dir=
=3D"ltr"><div>A natural question arises how to apply the algorithm that to =
find for example the first and last minimum elements or the first and =
last maximum elements in the given sequence?</div><div><br></div><div>This&=
nbsp;task othen occurs in practice. </div><div></div></div></div></blo=
ckquote><div><br></div><div>In practice of what? ;)</div><br></div></div></=
blockquote><div>In the practice of programming. </div><blockquote clas=
s=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; bo=
rder-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-st=
yle: solid;"><div style=3D"-ms-word-wrap: break-word;"><div><blockquote typ=
e=3D"cite"><div><div dir=3D"ltr"><div>template <class ForwardIterator, c=
lass Compare1, class Compare2></div><div>std::pair<ForwardIterator, F=
orwardIterator><br>minmax_element( ForwardIterator first, <br> &nbs=
p; &=
nbsp; ForwardIterator last,<br> &n=
bsp; std::pair<Compare1, Compa=
re2> comp );</div></div></div></blockquote><div><br></div><div>Is there =
another application of this template? Why not</div><div><br></div><div><fon=
t face=3D"Courier">template <class ForwardIterator, </font><span st=
yle=3D"font-family: Courier;">class Compare =3D less<> ></span></d=
iv><div><font face=3D"Courier">pair<ForwardIterator, ForwardIterator>=
<br>firstlast_min_element( ForwardIterator first, <br> &n=
bsp; ForwardI=
terator last,</font></div><div><font face=3D"Courier"> =
Compare comp =
=3D {} );<br></font><br></div><div>This only needs one comparator and as li=
ttle as half the comparisons.</div><br></div></div></blockquote><div>It loo=
ks bad. It introduces a new name when it is not required and the algor=
ithm I proposed does not imply that only predicates I showed =
;are used. So my algorithm is very flexible In fact it does not =
mean for example that the first and last minimum elements are searched =
;It is simply a partial case of using the algorithm.</div><blockquote class=
=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; bor=
der-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-sty=
le: solid;"><div style=3D"-ms-word-wrap: break-word;"><div><blockquote type=
=3D"cite"><div><div dir=3D"ltr"><div>In this case to find for example the f=
irst and last minimum elements for the given sequence it is enough to write=
</div><div><br></div><div> auto p =3D ::minmax_element( s=
td::begin( a ), std::end( a ),<br>  =
; &n=
bsp; std::make_=
pair( std::less<>(), std::greater<>() ) );</div><div><br></div>=
<div>Or to find for example the first and last maximum elements for th=
e given sequence it is enough to write</div><div><br> aut=
o p =3D ::minmax_element( std::begin( a ), std::end( a ),<br> &n=
bsp;  =
; &n=
bsp; std::make_pair( std::greater<>(), std::less<>(=
) ) );</div><div></div></div></div></blockquote><div><br></div><div>It=E2=
=80=99s far from clear which of these is which.</div></div></div></blockquo=
te><div><br></div><div>It is enough clear because the algorithm is named mi=
nmax. So there is no difference between the order of iterators in the retur=
n pair and the order of comparators in the parameter of type pair=
.. </div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_1088_1773945937.1430491423174--
------=_Part_1087_1086688575.1430491423174--
.
Author: David Krauss <potswa@gmail.com>
Date: Fri, 1 May 2015 22:51:04 +0800
Raw View
> On 2015=E2=80=9305=E2=80=9301, at 10:43 PM, Vlad from Moscow <vlad.moscow=
@mail.ru> wrote:
>=20
> the algorithm I proposed does not imply that only predicates I showed are=
used.
Yes, what is the other application?
> So my algorithm is very flexible In fact it does not mean for example th=
at the first and last minimum elements are searched It is simply a partial =
case of using the algorithm.
It=E2=80=99s also about twice as slow as a dedicated algorithm.
> It is enough clear because the algorithm is named minmax. So there is no =
difference between the order of iterators in the return pair and the order =
of comparators in the parameter of type pair.=20
Given the XOR-like sensibility that min + less =3D min, min + greater =3D m=
ax, max + less =3D max, and max + greater =3D min, the interface makes perf=
ect sense.
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
.
Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Fri, 1 May 2015 08:14:40 -0700 (PDT)
Raw View
------=_Part_1135_1373702123.1430493280365
Content-Type: multipart/alternative;
boundary="----=_Part_1136_214892364.1430493280365"
------=_Part_1136_214892364.1430493280365
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Friday, May 1, 2015 at 5:51:16 PM UTC+3, David Krauss wrote:
>
>
> > On 2015=E2=80=9305=E2=80=9301, at 10:43 PM, Vlad from Moscow <vlad....@=
mail.ru=20
> <javascript:>> wrote:=20
> >=20
> > the algorithm I proposed does not imply that only predicates I showed=
=20
> are used.=20
>
> Yes, what is the other application?=20
>
> General use of the algorithm is when you are required to find the first=
=20
element that satisfies one predicate and the last element that=20
satisfies another predicate. You can use either these elements themselves=
=20
or use the range they provide for some next operation.
=20
> > So my algorithm is very flexible In fact it does not mean for example=
=20
> that the first and last minimum elements are searched It is simply a=20
> partial case of using the algorithm.=20
>
> It=E2=80=99s also about twice as slow as a dedicated algorithm.=20
>
You may write a separate algorithm for any partial case and invent a new=20
name for each such an algorithm but as for me I do not think that it is=20
always a good idea.=20
>
> > It is enough clear because the algorithm is named minmax. So there is n=
o=20
> difference between the order of iterators in the return pair and the orde=
r=20
> of comparators in the parameter of type pair.=20
>
> Given the XOR-like sensibility that min + less =3D min, min + greater =3D=
max,=20
> max + less =3D max, and max + greater =3D min, the interface makes perfec=
t=20
> sense.
It is enough to know that the first predicate corresponds to the first=20
returned iterator that is close to the beginner of the given sequence and=
=20
that the second predicate corresponds to the second returned iterator that=
=20
is close to the end of the given sequence. You can consider even word min=
=20
as begining and max as end.=20
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
------=_Part_1136_214892364.1430493280365
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Friday, May 1, 2015 at 5:51:16 PM UTC+3, David =
Krauss wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px=
0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-le=
ft-width: 1px; border-left-style: solid;">
<br>> On 2015=E2=80=9305=E2=80=9301, at 10:43 PM, Vlad from Moscow <<=
a onmousedown=3D"this.href=3D'javascript:';return true;" onclick=3D"this.hr=
ef=3D'javascript:';return true;" href=3D"javascript:" target=3D"_blank" rel=
=3D"nofollow" gdf-obfuscated-mailto=3D"5MdBNIb8-VEJ">vlad....@mail.ru</a>&g=
t; wrote:
<br>>=20
<br>> the algorithm I proposed does not imply that only predicates I sho=
wed are used.
<br>
<br>Yes, what is the other application?
<br>
<br></blockquote><div>General use of the algorithm is when you are required=
to find the first element that satisfies one predicate and the last elemen=
t that satisfies another predicate. You can use either these elements =
themselves or use the range they provide for some next operation.</div><div=
><br></div><div> </div><blockquote class=3D"gmail_quote" style=
=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(20=
4, 204, 204); border-left-width: 1px; border-left-style: solid;">> So my=
algorithm is very flexible In fact it does not mean for example that=
the first and last minimum elements are searched It is simply a partial ca=
se of using the algorithm.
<br>
<br>It=E2=80=99s also about twice as slow as a dedicated algorithm.
<br></blockquote><div><br></div><div>You may write a separate algorith=
m for any partial case and invent a new name for each such an alg=
orithm but as for me I do not think that it is always a good idea.&nbs=
p;</div><blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8e=
x; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-wi=
dth: 1px; border-left-style: solid;">
<br>> It is enough clear because the algorithm is named minmax. So there=
is no difference between the order of iterators in the return pair and the=
order of comparators in the parameter of type pair.=20
<br>
<br>Given the XOR-like sensibility that min + less =3D min, min + greater =
=3D max, max + less =3D max, and max + greater =3D min, the interface makes=
perfect sense.</blockquote><div><br></div><div>It is enough to know that t=
he first predicate corresponds to the first returned iterator that is =
close to the beginner of the given sequence and that the second predicate c=
orresponds to the second returned iterator that is close to the end of the =
given sequence. You can consider even word min as begining and max as end.&=
nbsp;</div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_1136_214892364.1430493280365--
------=_Part_1135_1373702123.1430493280365--
.