220 17663 <f967abc1-2415-47f1-aba3-8fbb8df60a75@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Vlad from Moscow <vlad.moscow@mail.ru>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Overloading the family of minmax algorithms
Date: Fri, 1 May 2015 07:43:43 -0700 (PDT)
Lines: 176
Approved: news@gmane.org
Message-ID: <f967abc1-2415-47f1-aba3-8fbb8df60a75@isocpp.org>
References: <558876f0-141f-49ca-bece-7215ec173d1d@isocpp.org>
 <4A07A10E-B668-447F-A6FA-776D6C3BD7D5@gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1087_1086688575.1430491423174"
X-Trace: ger.gmane.org 1430491428 23458 80.91.229.3 (1 May 2015 14:43:48 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Fri, 1 May 2015 14:43:48 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCXLLRHD7IDRBIFCR2VAKGQEGK6JTSQ@isocpp.org Fri May 01 16:43:48 2015
Return-path: <std-proposals+bncBCXLLRHD7IDRBIFCR2VAKGQEGK6JTSQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qk0-f197.google.com ([209.85.220.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCXLLRHD7IDRBIFCR2VAKGQEGK6JTSQ@isocpp.org>)
	id 1YoCAL-0004A3-NV
	for gclcip-std-proposals@m.gmane.org; Fri, 01 May 2015 16:43:45 +0200
Original-Received: by qkac3 with SMTP id c3sf68531563qka.0
        for <gclcip-std-proposals@m.gmane.org>; Fri, 01 May 2015 07:43:44 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:content-type:x-original-sender:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=aokVTQYSCIuEU0gDiNHDMpiFwa7mzQLtq7MmZKgzdxQ=;
        b=HqELsCZm8AMZ0u9aDntG40HqmCepl9KL+1bbUns2rpYVP+eQgmAoSfUuRl4ufG+jRc
         KXUeiXDWWDaxVnPps8+EgbDBahcY7tOF5IRwoXEVIek7vPEHgxDZoI9VlywxXFxsZV7T
         L50I1uu7+tYOLh5uDBhQ39NXCpWZ9GUD4M+TOgZ3d81+1VGWCEjgD4lLuigU5i/dnaRr
         aOj1MLnAUFmYkpnbIAC7zGv8cHlahTlx3+vYI0Juvkfm4RZRgvBNZoxVJHFF+dAGO3k/
         ud1s930pBqYE11d8yXOmsl+LBwM0/gyJNZt8cy1VBMiiuu1SjU9CU7WEUu0m9qRJ5yem
         dWWQ==
X-Gm-Message-State: ALoCoQniR0rI8x8qNAMkYrdG6MjZDqtN9iODW1lVltyMJQbRMFohzpcjJXnbzw/fg4UrP2Cj5wY1
X-Received: by 10.140.132.73 with SMTP id 70mr16567580qhe.6.1430491424463;
        Fri, 01 May 2015 07:43:44 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.41.169 with SMTP id z38ls1576097qgz.54.gmail; Fri, 01 May
 2015 07:43:43 -0700 (PDT)
X-Received: by 10.140.93.14 with SMTP id c14mr106392qge.42.1430491423832;
        Fri, 01 May 2015 07:43:43 -0700 (PDT)
In-Reply-To: <4A07A10E-B668-447F-A6FA-776D6C3BD7D5@gmail.com>
X-Original-Sender: vlad.moscow@mail.ru
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:17663
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/17663>

------=_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 &lt;<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>&gt; 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&nbsp;last minimum elements or the first and =
last maximum elements in the given sequence?</div><div><br></div><div>This&=
nbsp;task&nbsp;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.&nbsp;</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 &lt;class ForwardIterator, c=
lass Compare1, class Compare2&gt;</div><div>std::pair&lt;ForwardIterator, F=
orwardIterator&gt;<br>minmax_element( ForwardIterator first, <br>&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp; ForwardIterator last,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::pair&lt;Compare1, Compa=
re2&gt; 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 &lt;class ForwardIterator,&nbsp;</font><span st=
yle=3D"font-family: Courier;">class Compare =3D less&lt;&gt; &gt;</span></d=
iv><div><font face=3D"Courier">pair&lt;ForwardIterator, ForwardIterator&gt;=
<br>firstlast_min_element( ForwardIterator first,&nbsp;<br>&nbsp; &nbsp; &n=
bsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ForwardI=
terator last,</font></div><div><font face=3D"Courier">&nbsp; &nbsp; &nbsp; =
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;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&nbsp;bad. It introduces a new name when it is not required and the algor=
ithm I&nbsp;proposed does not imply that only&nbsp;predicates I showed&nbsp=
;are used. So my algorithm is&nbsp;very flexible&nbsp; In fact it does not =
mean for example that the first and last minimum elements are searched&nbsp=
;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>&nbsp;&nbsp;&nbsp; auto p =3D ::minmax_element( s=
td::begin( a ), std::end( a ),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::make_=
pair( std::less&lt;&gt;(), std::greater&lt;&gt;() ) );</div><div><br></div>=
<div>Or to find for example the first and last&nbsp;maximum elements for th=
e given sequence it is enough to write</div><div><br>&nbsp;&nbsp;&nbsp; aut=
o p =3D ::minmax_element( std::begin( a ), std::end( a ),<br>&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp; std::make_pair( std::greater&lt;&gt;(), std::less&lt;&gt;(=
) ) );</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&nbsp;and the order of comparators in the parameter of&nbsp;type pair=
..&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&quot; 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--

.
