220 7156 <CAOpASk64dV+3ZUW+Z8wcEqug_oSaztvJp1zsDB_QdAxi+fwcsA@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: =?ISO-8859-1?Q?R=E9my_Lefevre?= <lefevreremy@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: "count_while" and "count_until" algorithms
Date: Tue, 8 Oct 2013 22:04:23 +0200
Lines: 240
Approved: news@gmane.org
Message-ID: <CAOpASk64dV+3ZUW+Z8wcEqug_oSaztvJp1zsDB_QdAxi+fwcsA@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=e89a8f502fead519f604e84048bd
X-Trace: ger.gmane.org 1381262703 11031 80.91.229.3 (8 Oct 2013 20:05:03 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 8 Oct 2013 20:05:03 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCN7B34JVEARB4GK2GJAKGQEWVTZGXY@isocpp.org Tue Oct 08 22:05:07 2013
Return-path: <std-proposals+bncBCN7B34JVEARB4GK2GJAKGQEWVTZGXY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lb0-f198.google.com ([209.85.217.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCN7B34JVEARB4GK2GJAKGQEWVTZGXY@isocpp.org>)
	id 1VTdWk-0004Yq-3p
	for gclcip-std-proposals@m.gmane.org; Tue, 08 Oct 2013 22:05:06 +0200
Original-Received: by mail-lb0-f198.google.com with SMTP id u14sf12133524lbd.5
        for <gclcip-std-proposals@m.gmane.org>; Tue, 08 Oct 2013 13:05:05 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=mime-version:from:date:message-id:subject: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:content-type;
        bh=arZdxNLjWN/a3kERkj6lKED9pe0joa3+qwRjYUbNMf8=;
        b=G/Rfy6DdUDRrXCz5VP6+2BPNnEbXmB7/5LCGkJHKnSmaS+fyThc7auBCDMdqtUt9pc
         q1fYDKwLckLL2D5DjFv+VZhouAWM2V0sa2baC6KTHlOf/LRh8TmIQN5iQ+ZDnohrsiKE
         l1Z9DjYlQQ3O9bg7vIQ4XxriVr5psqAPW7vHuoY3OVeFIUen3HPNcOOyTMj04JfGp0Dc
         rtAH/dCIUv6JAVN51D2Fgp5i901FoeMxWMCKyqcPzDbmT9P99Q0tjvB79kdIOdjAke+S
         u6jPWgT/LF1zSzthSXFC0t9hwEQc5W0ELfb0I3wHRxin1VNecvQVPg59Xnq+FjL4GoIE
         mrHA==
X-Received: by 10.180.189.137 with SMTP id gi9mr1355917wic.1.1381262705465;
        Tue, 08 Oct 2013 13:05:05 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.180.13.232 with SMTP id k8ls223149wic.54.gmail; Tue, 08 Oct
 2013 13:05:04 -0700 (PDT)
X-Received: by 10.180.39.212 with SMTP id r20mr25346178wik.13.1381262704445;
        Tue, 08 Oct 2013 13:05:04 -0700 (PDT)
Original-Received: from mail-wg0-x234.google.com (mail-wg0-x234.google.com [2a00:1450:400c:c00::234])
        by mx.google.com with ESMTPS id lz5si14470320wjb.7.1969.12.31.16.00.00
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Tue, 08 Oct 2013 13:05:04 -0700 (PDT)
Received-SPF: pass (google.com: domain of lefevreremy@gmail.com designates 2a00:1450:400c:c00::234 as permitted sender) client-ip=2a00:1450:400c:c00::234;
Original-Received: by mail-wg0-f52.google.com with SMTP id m15so9539164wgh.31
        for <std-proposals@isocpp.org>; Tue, 08 Oct 2013 13:05:04 -0700 (PDT)
X-Received: by 10.180.36.36 with SMTP id n4mr3197320wij.62.1381262704275; Tue,
 08 Oct 2013 13:05:04 -0700 (PDT)
Original-Received: by 10.194.192.33 with HTTP; Tue, 8 Oct 2013 13:04:23 -0700 (PDT)
X-Original-Sender: lefevreremy@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of lefevreremy@gmail.com designates 2a00:1450:400c:c00::234 as
 permitted sender) smtp.mail=lefevreremy@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: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:7156
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/7156>

--e89a8f502fead519f604e84048bd
Content-Type: text/plain; charset=ISO-8859-1

Hi,

I thought about two new algorithms, that could be named "count_while" and
"count_until". Here are their behavior:

template <class InputIterator, class UnaryPredicate>

  typename iterator_traits<InputIterator>::difference_type

    count_while (InputIterator first, InputIterator last, UnaryPredicate pred)
{
  typename iterator_traits<InputIterator>::difference_type ret = 0;

  while (first!=last && pred(*first)) {

    ++ret;
    ++first;

  }
  return ret;
}


template <class InputIterator, class UnaryPredicate>

  typename iterator_traits<InputIterator>::difference_type

    count_until (InputIterator first, InputIterator last, UnaryPredicate pred)
{

  typename iterator_traits<InputIterator>::difference_type ret = 0;

  while (first!=last && !pred(*first)) {

    ++ret;
    ++first;

  }
  return ret;

}


What do you think about adding these two components to the algorithms
library ?

-- 

--- 
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/.

--e89a8f502fead519f604e84048bd
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi,<br><br>I thought about two new algorithms, that could =
be named &quot;count_while&quot; and &quot;count_until&quot;. Here are thei=
r behavior:<br><br><div class=3D"" style=3D"background-color:rgb(250,250,25=
0);border-color:rgb(187,187,187);border-style:solid;border-width:1px;word-w=
rap:break-word">

<code class=3D""><div class=3D""><pre><code><var><span style=3D"color:rgb(0=
,0,136)" class=3D"">template</span></var><span style=3D"color:rgb(0,0,0)" c=
lass=3D""> </span><span style=3D"color:rgb(102,102,0)" class=3D"">&lt;</spa=
n><var><span style=3D"color:rgb(0,0,136)" class=3D"">class</span></var><spa=
n style=3D"color:rgb(0,0,0)" class=3D""> </span><span style=3D"color:rgb(10=
2,0,102)" class=3D"">InputIterator</span><span style=3D"color:rgb(102,102,0=
)" class=3D"">,</span><span style=3D"color:rgb(0,0,0)" class=3D""> </span><=
var><span style=3D"color:rgb(0,0,136)" class=3D"">class</span></var><span s=
tyle=3D"color:rgb(0,0,0)" class=3D""> </span><span style=3D"color:rgb(102,0=
,102)" class=3D"">UnaryPredicate</span><span style=3D"color:rgb(102,102,0)"=
 class=3D"">&gt;</span><span style=3D"color:rgb(0,0,0)" class=3D""><br>

=A0 </span><var><span style=3D"color:rgb(0,0,136)" class=3D"">typename</spa=
n></var><span style=3D"color:rgb(0,0,0)" class=3D""> iterator_traits</span>=
<span style=3D"color:rgb(102,102,0)" class=3D"">&lt;</span><span style=3D"c=
olor:rgb(102,0,102)" class=3D"">InputIterator</span><span style=3D"color:rg=
b(102,102,0)" class=3D"">&gt;::</span><span style=3D"color:rgb(0,0,0)" clas=
s=3D"">difference_type<br>

=A0 =A0 count_while </span><span style=3D"color:rgb(102,102,0)" class=3D"">=
(</span><span style=3D"color:rgb(102,0,102)" class=3D"">InputIterator</span=
><span style=3D"color:rgb(0,0,0)" class=3D""> first</span><span style=3D"co=
lor:rgb(102,102,0)" class=3D"">,</span><span style=3D"color:rgb(0,0,0)" cla=
ss=3D""> </span><span style=3D"color:rgb(102,0,102)" class=3D"">InputIterat=
or</span><span style=3D"color:rgb(0,0,0)" class=3D""> </span><span style=3D=
"color:rgb(0,0,136)" class=3D"">last</span><span style=3D"color:rgb(102,102=
,0)" class=3D"">,</span><span style=3D"color:rgb(0,0,0)" class=3D""> </span=
><span style=3D"color:rgb(102,0,102)" class=3D"">UnaryPredicate</span><span=
 style=3D"color:rgb(0,0,0)" class=3D""> pred</span><span style=3D"color:rgb=
(102,102,0)" class=3D"">)</span><span style=3D"color:rgb(0,0,0)" class=3D""=
><br>

</span><span style=3D"color:rgb(102,102,0)" class=3D"">{</span><span style=
=3D"color:rgb(0,0,0)" class=3D""><br>=A0 </span><var><span style=3D"color:r=
gb(0,0,136)" class=3D"">typename</span></var><span style=3D"color:rgb(0,0,0=
)" class=3D""> iterator_traits</span><span style=3D"color:rgb(102,102,0)" c=
lass=3D"">&lt;</span><span style=3D"color:rgb(102,0,102)" class=3D"">InputI=
terator</span><span style=3D"color:rgb(102,102,0)" class=3D"">&gt;::</span>=
<span style=3D"color:rgb(0,0,0)" class=3D"">difference_type ret </span><spa=
n style=3D"color:rgb(102,102,0)" class=3D"">=3D</span><span style=3D"color:=
rgb(0,0,0)" class=3D""> </span><span style=3D"color:rgb(0,102,102)" class=
=3D"">0</span><span style=3D"color:rgb(102,102,0)" class=3D"">;</span><span=
 style=3D"color:rgb(0,0,0)" class=3D""><br>

=A0 </span><var><span style=3D"color:rgb(0,0,136)" class=3D"">while</span><=
/var><span style=3D"color:rgb(0,0,0)" class=3D""> </span><span style=3D"col=
or:rgb(102,102,0)" class=3D"">(</span><span style=3D"color:rgb(0,0,0)" clas=
s=3D"">first</span><span style=3D"color:rgb(102,102,0)" class=3D"">!=3D</sp=
an><span style=3D"color:rgb(0,0,136)" class=3D"">last</span><var><span styl=
e=3D"color:rgb(0,0,0)" class=3D""> </span><span style=3D"color:rgb(102,102,=
0)" class=3D"">&amp;&amp;</span><span style=3D"color:rgb(0,0,0)" class=3D""=
> </span></var><var></var><span style=3D"color:rgb(0,0,0)" class=3D"">pred<=
/span><span style=3D"color:rgb(102,102,0)" class=3D"">(*</span><span style=
=3D"color:rgb(0,0,0)" class=3D"">first</span><span style=3D"color:rgb(102,1=
02,0)" class=3D"">))</span><span style=3D"color:rgb(0,0,0)" class=3D""> </s=
pan><span style=3D"color:rgb(102,102,0)" class=3D"">{</span><span style=3D"=
color:rgb(0,0,0)" class=3D""><br>

=A0 =A0 </span><span style=3D"color:rgb(102,102,0)" class=3D"">++</span><sp=
an style=3D"color:rgb(0,0,0)" class=3D"">ret</span><span style=3D"color:rgb=
(102,102,0)" class=3D"">;</span><span style=3D"color:rgb(0,0,0)" class=3D""=
><br>=A0 =A0 </span><span style=3D"color:rgb(102,102,0)" class=3D"">++</spa=
n><span style=3D"color:rgb(0,0,0)" class=3D"">first</span><span style=3D"co=
lor:rgb(102,102,0)" class=3D"">;</span><span style=3D"color:rgb(0,0,0)" cla=
ss=3D""><br>

=A0 </span><span style=3D"color:rgb(102,102,0)" class=3D"">}</span><span st=
yle=3D"color:rgb(0,0,0)" class=3D""><br>=A0 </span><var><span style=3D"colo=
r:rgb(0,0,136)" class=3D"">return</span></var><span style=3D"color:rgb(0,0,=
0)" class=3D""> ret</span><span style=3D"color:rgb(102,102,0)" class=3D"">;=
</span><span style=3D"color:rgb(0,0,0)" class=3D""><br>

</span><span style=3D"color:rgb(102,102,0)" class=3D"">}</span></code></pre=
></div></code></div><br><div class=3D"" style=3D"background-color:rgb(250,2=
50,250);border-color:rgb(187,187,187);border-style:solid;border-width:1px;w=
ord-wrap:break-word">

<code class=3D""><div class=3D""><pre><code><var><span style=3D"color:rgb(0=
,0,136)" class=3D"">template</span></var><span style=3D"color:rgb(0,0,0)" c=
lass=3D""> </span><span style=3D"color:rgb(102,102,0)" class=3D"">&lt;</spa=
n><var><span style=3D"color:rgb(0,0,136)" class=3D"">class</span></var><spa=
n style=3D"color:rgb(0,0,0)" class=3D""> </span><span style=3D"color:rgb(10=
2,0,102)" class=3D"">InputIterator</span><span style=3D"color:rgb(102,102,0=
)" class=3D"">,</span><span style=3D"color:rgb(0,0,0)" class=3D""> </span><=
var><span style=3D"color:rgb(0,0,136)" class=3D"">class</span></var><span s=
tyle=3D"color:rgb(0,0,0)" class=3D""> </span><span style=3D"color:rgb(102,0=
,102)" class=3D"">UnaryPredicate</span><span style=3D"color:rgb(102,102,0)"=
 class=3D"">&gt;</span><span style=3D"color:rgb(0,0,0)" class=3D""><br>

=A0 </span><var><span style=3D"color:rgb(0,0,136)" class=3D"">typename</spa=
n></var><span style=3D"color:rgb(0,0,0)" class=3D""> iterator_traits</span>=
<span style=3D"color:rgb(102,102,0)" class=3D"">&lt;</span><span style=3D"c=
olor:rgb(102,0,102)" class=3D"">InputIterator</span><span style=3D"color:rg=
b(102,102,0)" class=3D"">&gt;::</span><span style=3D"color:rgb(0,0,0)" clas=
s=3D"">difference_type<br>

=A0 =A0 count_until </span><span style=3D"color:rgb(102,102,0)" class=3D"">=
(</span><span style=3D"color:rgb(102,0,102)" class=3D"">InputIterator</span=
><span style=3D"color:rgb(0,0,0)" class=3D""> first</span><span style=3D"co=
lor:rgb(102,102,0)" class=3D"">,</span><span style=3D"color:rgb(0,0,0)" cla=
ss=3D""> </span><span style=3D"color:rgb(102,0,102)" class=3D"">InputIterat=
or</span><span style=3D"color:rgb(0,0,0)" class=3D""> </span><span style=3D=
"color:rgb(0,0,136)" class=3D"">last</span><span style=3D"color:rgb(102,102=
,0)" class=3D"">,</span><span style=3D"color:rgb(0,0,0)" class=3D""> </span=
><span style=3D"color:rgb(102,0,102)" class=3D"">UnaryPredicate</span><span=
 style=3D"color:rgb(0,0,0)" class=3D""> pred</span><span style=3D"color:rgb=
(102,102,0)" class=3D"">)</span><span style=3D"color:rgb(0,0,0)" class=3D""=
><br>

</span><span style=3D"color:rgb(102,102,0)" class=3D"">{</span><span style=
=3D"color:rgb(0,0,0)" class=3D""><br><code class=3D""><pre><code><span styl=
e=3D"color:rgb(0,0,0)" class=3D"">=A0 </span><var><span style=3D"color:rgb(=
0,0,136)" class=3D"">typename</span></var><span style=3D"color:rgb(0,0,0)" =
class=3D""> iterator_traits</span><span style=3D"color:rgb(102,102,0)" clas=
s=3D"">&lt;</span><span style=3D"color:rgb(102,0,102)" class=3D"">InputIter=
ator</span><span style=3D"color:rgb(102,102,0)" class=3D"">&gt;::</span><sp=
an style=3D"color:rgb(0,0,0)" class=3D"">difference_type ret </span><span s=
tyle=3D"color:rgb(102,102,0)" class=3D"">=3D</span><span style=3D"color:rgb=
(0,0,0)" class=3D""> </span><span style=3D"color:rgb(0,102,102)" class=3D""=
>0</span><span style=3D"color:rgb(102,102,0)" class=3D"">;</span><span styl=
e=3D"color:rgb(0,0,0)" class=3D""><br>

=A0 </span><var><span style=3D"color:rgb(0,0,136)" class=3D"">while</span><=
/var><span style=3D"color:rgb(0,0,0)" class=3D""> </span><span style=3D"col=
or:rgb(102,102,0)" class=3D"">(</span><span style=3D"color:rgb(0,0,0)" clas=
s=3D"">first</span><span style=3D"color:rgb(102,102,0)" class=3D"">!=3D</sp=
an><span style=3D"color:rgb(0,0,136)" class=3D"">last</span><var><span styl=
e=3D"color:rgb(0,0,0)" class=3D""> </span><span style=3D"color:rgb(102,102,=
0)" class=3D"">&amp;&amp;</span><span style=3D"color:rgb(0,0,0)" class=3D""=
> </span></var><var></var><span style=3D"color:rgb(0,0,0)" class=3D"">!pred=
</span><span style=3D"color:rgb(102,102,0)" class=3D"">(*</span><span style=
=3D"color:rgb(0,0,0)" class=3D"">first</span><span style=3D"color:rgb(102,1=
02,0)" class=3D"">))</span><span style=3D"color:rgb(0,0,0)" class=3D""> </s=
pan><span style=3D"color:rgb(102,102,0)" class=3D"">{</span><span style=3D"=
color:rgb(0,0,0)" class=3D""><br>

=A0 =A0 </span><span style=3D"color:rgb(102,102,0)" class=3D"">++</span><sp=
an style=3D"color:rgb(0,0,0)" class=3D"">ret</span><span style=3D"color:rgb=
(102,102,0)" class=3D"">;</span><span style=3D"color:rgb(0,0,0)" class=3D""=
><br>=A0 =A0 </span><span style=3D"color:rgb(102,102,0)" class=3D"">++</spa=
n><span style=3D"color:rgb(0,0,0)" class=3D"">first</span><span style=3D"co=
lor:rgb(102,102,0)" class=3D"">;</span><span style=3D"color:rgb(0,0,0)" cla=
ss=3D""><br>

=A0 </span><span style=3D"color:rgb(102,102,0)" class=3D"">}</span><span st=
yle=3D"color:rgb(0,0,0)" class=3D""><br>=A0 </span><var><span style=3D"colo=
r:rgb(0,0,136)" class=3D"">return</span></var><span style=3D"color:rgb(0,0,=
0)" class=3D""> ret;<br>

}</span><span style=3D"color:rgb(102,102,0)" class=3D""></span></code></pre=
></code></span></code><code><span style=3D"color:rgb(0,0,0)" class=3D""></s=
pan><span style=3D"color:rgb(102,102,0)" class=3D""></span></code></pre></d=
iv></code></div>

<br>What do you think about adding these two components to the algorithms l=
ibrary ?</div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />

--e89a8f502fead519f604e84048bd--

.
