220 17662 <4A07A10E-B668-447F-A6FA-776D6C3BD7D5@gmail.com> article
Path: news.gmane.org!not-for-mail
From: David Krauss <potswa@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Overloading the family of minmax algorithms
Date: Fri, 1 May 2015 22:10:50 +0800
Lines: 132
Approved: news@gmane.org
Message-ID: <4A07A10E-B668-447F-A6FA-776D6C3BD7D5@gmail.com>
References: <558876f0-141f-49ca-bece-7215ec173d1d@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2098\))
Content-Type: multipart/alternative; boundary="Apple-Mail=_B0CDF983-15B2-4B05-9F94-BC709AAB0CD0"
X-Trace: ger.gmane.org 1430489474 22106 80.91.229.3 (1 May 2015 14:11:14 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Fri, 1 May 2015 14:11:14 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCW25A7E3QCRB7USR2VAKGQEKW4W4HY@isocpp.org Fri May 01 16:11:13 2015
Return-path: <std-proposals+bncBCW25A7E3QCRB7USR2VAKGQEKW4W4HY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pa0-f70.google.com ([209.85.220.70])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCW25A7E3QCRB7USR2VAKGQEKW4W4HY@isocpp.org>)
	id 1YoBeq-000547-IE
	for gclcip-std-proposals@m.gmane.org; Fri, 01 May 2015 16:11:12 +0200
Original-Received: by pavx7 with SMTP id x7sf164928231pav.1
        for <gclcip-std-proposals@m.gmane.org>; Fri, 01 May 2015 07:11:11 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:content-type:message-id:mime-version
         :subject:date:references:to:in-reply-to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=y7r9aS3MOmCX8wXYBNa9ZSq2VR9AGpJJOCIqg7YHPro=;
        b=S8YrpQ6IPn3W/S+DZWSSWhorlJHDsUbBjGOmz8B+y/E8h6j3Zul9Gd4s+fNDra8q67
         quXw9OOamob6xyUuTHROkD7Oz1DUpC/mhGWgZcWx3WNbn958WaffGE/A+E6G3XoYfMF0
         PyisyQLif04/Zv9e4nDrQllgiVumnsADjD/kGHWCk/oMCmunKBNv3n8IZUeyUdmtF8xj
         ziVEHprxst/v8win5oFMke8j+xaQPBa8xu/2oh4J+geePTFT15kuad31xvu1x9zDzGk1
         JSZQc8/Xg9iKHkAc3vlLg9WYaRAtPMHkrkYnMzo1lkpvEIzc81Lj1xTHBVnXTn7CrVY6
         LurA==
X-Gm-Message-State: ALoCoQktDXudb6ayyEKrZGIewiqQ7qj7CRev0WfRhezWUYXl7R5UeK3valXdpBKCO4AldQaJ1Cjo
X-Received: by 10.66.145.225 with SMTP id sx1mr16894649pab.21.1430489471619;
        Fri, 01 May 2015 07:11:11 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.51.17.3 with SMTP id ga3ls459978igd.20.canary; Fri, 01 May
 2015 07:11:10 -0700 (PDT)
X-Received: by 10.66.250.131 with SMTP id zc3mr15960449pac.136.1430489470790;
        Fri, 01 May 2015 07:11:10 -0700 (PDT)
Original-Received: from mail-pd0-x22a.google.com (mail-pd0-x22a.google.com. [2607:f8b0:400e:c02::22a])
        by mx.google.com with ESMTPS id x16si8174871pdi.8.2015.05.01.07.11.10
        for <std-proposals@isocpp.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Fri, 01 May 2015 07:11:10 -0700 (PDT)
Received-SPF: pass (google.com: domain of potswa@gmail.com designates 2607:f8b0:400e:c02::22a as permitted sender) client-ip=2607:f8b0:400e:c02::22a;
Original-Received: by pdbnk13 with SMTP id nk13so93324398pdb.0
        for <std-proposals@isocpp.org>; Fri, 01 May 2015 07:11:10 -0700 (PDT)
X-Received: by 10.66.150.196 with SMTP id uk4mr18274039pab.54.1430489470419;
        Fri, 01 May 2015 07:11:10 -0700 (PDT)
Original-Received: from [172.20.10.2] ([121.54.44.91])
        by mx.google.com with ESMTPSA id j10sm4997174pdp.83.2015.05.01.07.11.04
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Fri, 01 May 2015 07:11:09 -0700 (PDT)
In-Reply-To: <558876f0-141f-49ca-bece-7215ec173d1d@isocpp.org>
X-Mailer: Apple Mail (2.2098)
X-Original-Sender: potswa@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of potswa@gmail.com designates 2607:f8b0:400e:c02::22a as permitted
 sender) smtp.mail=potswa@gmail.com;       dkim=pass header.i=@gmail.com;
       dmarc=pass (p=NONE dis=NONE) header.from=gmail.com
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:17662
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/17662>

--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 &lt;<a href=3D"mailto:vlad.moscow=
@mail.ru" class=3D"">vlad.moscow@mail.ru</a>&gt; 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&nbsp;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&nbsp;task&nbsp;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 &lt;class ForwardIterator, class Compare1, class Compare2&gt;</div><di=
v class=3D"">std::pair&lt;ForwardIterator, ForwardIterator&gt;<br class=3D"=
">minmax_element( ForwardIterator first, <br class=3D"">&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For=
wardIterator last,<br class=3D"">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::pair&lt;Compare1, Com=
pare2&gt; 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 &lt;class Fo=
rwardIterator,&nbsp;</font><span style=3D"font-family: Courier;" class=3D""=
>class Compare =3D less&lt;&gt; &gt;</span></div><div><font face=3D"Courier=
" class=3D"">pair&lt;ForwardIterator, ForwardIterator&gt;<br class=3D"">fir=
stlast_min_element( ForwardIterator first,&nbsp;<br class=3D"">&nbsp; &nbsp=
; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Forw=
ardIterator last,</font></div><div><font face=3D"Courier" class=3D"">&nbsp;=
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &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"">&nbsp;&nbsp;&nbsp=
; auto p =3D ::minmax_element( std::begin( a ), std::end( a ),<br class=3D"=
">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::make_pair( std::less&lt;&gt;(), std::=
greater&lt;&gt;() ) );</div><div class=3D""><br class=3D""></div><div class=
=3D"">Or to find for example the first and last&nbsp;maximum elements for t=
he given sequence it is enough to write</div><div class=3D""><br class=3D""=
>&nbsp;&nbsp;&nbsp; auto p =3D ::minmax_element( std::begin( a ), std::end(=
 a ),<br class=3D"">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::make_pair( std::gre=
ater&lt;&gt;(), std::less&lt;&gt;() ) );</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&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 />

--Apple-Mail=_B0CDF983-15B2-4B05-9F94-BC709AAB0CD0--

.
