220 7158 <CAArVCkRXVXvquXcBYRwwh6wWHUJ4sw48DTM0CtgMAHke6YMVDg@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Philipp Stephani <p.stephani2@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: "count_while" and "count_until" algorithms
Date: Tue, 8 Oct 2013 22:16:30 +0200
Lines: 273
Approved: news@gmane.org
Message-ID: <CAArVCkRXVXvquXcBYRwwh6wWHUJ4sw48DTM0CtgMAHke6YMVDg@mail.gmail.com>
References: <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=001a11c37ababadd5f04e840718e
X-Trace: ger.gmane.org 1381263389 19206 80.91.229.3 (8 Oct 2013 20:16:29 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 8 Oct 2013 20:16:29 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBD35NAXJW4GBBH6Q2GJAKGQE5L7OBWA@isocpp.org Tue Oct 08 22:16:33 2013
Return-path: <std-proposals+bncBD35NAXJW4GBBH6Q2GJAKGQE5L7OBWA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ea0-f198.google.com ([209.85.215.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBD35NAXJW4GBBH6Q2GJAKGQE5L7OBWA@isocpp.org>)
	id 1VTdho-0002NH-B1
	for gclcip-std-proposals@m.gmane.org; Tue, 08 Oct 2013 22:16:32 +0200
Original-Received: by mail-ea0-f198.google.com with SMTP id z15sf11874528ead.1
        for <gclcip-std-proposals@m.gmane.org>; Tue, 08 Oct 2013 13:16:32 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=mime-version:in-reply-to:references:date:message-id:subject:from: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=19kZIqtEpQbdmoiPZz46g6HZ1ml+mEk9A4vtgL9k9HE=;
        b=X0XjWWY36Cs3e2wGElcooBZwnWaky5wy0cVb0ojWN1xBJr0J9pvqT1hvsYa002RK8K
         dp83UqfrrqihrCJ/egSov1R2CYxXAiqgZ5qT3kDby8bs1xHVkb5ExKhBQbIKYPhTGfcq
         g2AIBY5kYBZnNXEQqcnh2DJWODZ18sRq9WB271BKO96WZh47oyU+0d86fuxM7KALJO75
         j4e24BdXMu3nSW4MBU30ixL+Ckx2bwcfVOcCRgVcIannpTCuQd08w1pugd0C55nKloCp
         C0atiFScp8E2Gd/QWLiv3Dn3+oljojcd13eQ16gi1nKh9XCrC1s6TEUKRE9aYIF2mmQX
         ++1A==
X-Received: by 10.180.21.137 with SMTP id v9mr11714864wie.7.1381263391721;
        Tue, 08 Oct 2013 13:16:31 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.180.107.74 with SMTP id ha10ls1311528wib.42.canary; Tue, 08
 Oct 2013 13:16:31 -0700 (PDT)
X-Received: by 10.205.14.69 with SMTP id pp5mr3403512bkb.14.1381263390916;
        Tue, 08 Oct 2013 13:16:30 -0700 (PDT)
Original-Received: from mail-la0-x229.google.com (mail-la0-x229.google.com [2a00:1450:4010:c03::229])
        by mx.google.com with ESMTPS id ub7si5501073bkb.115.1969.12.31.16.00.00
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Tue, 08 Oct 2013 13:16:30 -0700 (PDT)
Received-SPF: pass (google.com: domain of p.stephani2@gmail.com designates 2a00:1450:4010:c03::229 as permitted sender) client-ip=2a00:1450:4010:c03::229;
Original-Received: by mail-la0-f41.google.com with SMTP id ec20so7564100lab.0
        for <std-proposals@isocpp.org>; Tue, 08 Oct 2013 13:16:30 -0700 (PDT)
X-Received: by 10.112.14.102 with SMTP id o6mr3910799lbc.28.1381263390464;
 Tue, 08 Oct 2013 13:16:30 -0700 (PDT)
Original-Received: by 10.112.213.73 with HTTP; Tue, 8 Oct 2013 13:16:30 -0700 (PDT)
In-Reply-To: <CAOpASk64dV+3ZUW+Z8wcEqug_oSaztvJp1zsDB_QdAxi+fwcsA@mail.gmail.com>
X-Original-Sender: p.stephani2@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of p.stephani2@gmail.com designates 2a00:1450:4010:c03::229 as
 permitted sender) smtp.mail=p.stephani2@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:7158
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/7158>

--001a11c37ababadd5f04e840718e
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

I like the idea, they are simple and solve a generic problem that otherwise
requires a for loop (unless you have at least a forward iterator, then you
can use count_if + distance).


2013/10/8 R=E9my Lefevre <lefevreremy@gmail.com>

> 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 =3D 0;
>
>
>   while (first!=3Dlast && 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 =3D 0;
>
>
>   while (first!=3Dlast && !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/.
>

--=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/.

--001a11c37ababadd5f04e840718e
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I like the idea, they are simple and solve a generic probl=
em that otherwise requires a for loop (unless you have at least a forward i=
terator, then you can use count_if + distance).</div><div class=3D"gmail_ex=
tra">
<br><br><div class=3D"gmail_quote">2013/10/8 R=E9my Lefevre <span dir=3D"lt=
r">&lt;<a href=3D"mailto:lefevreremy@gmail.com" target=3D"_blank">lefevrere=
my@gmail.com</a>&gt;</span><br><blockquote class=3D"gmail_quote" style=3D"m=
argin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<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 style=3D"background-color:rgb(250,250,250);border-c=
olor:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:break-w=
ord">


<code><div><pre><code><var><span style=3D"color:rgb(0,0,136)">template</spa=
n></var><span style> </span><span style=3D"color:rgb(102,102,0)">&lt;</span=
><var><span style=3D"color:rgb(0,0,136)">class</span></var><span style> </s=
pan><span style=3D"color:rgb(102,0,102)">InputIterator</span><span style=3D=
"color:rgb(102,102,0)">,</span><span style> </span><var><span style=3D"colo=
r:rgb(0,0,136)">class</span></var><span style> </span><span style=3D"color:=
rgb(102,0,102)">UnaryPredicate</span><span style=3D"color:rgb(102,102,0)">&=
gt;</span><span style><br>


=A0 </span><var><span style=3D"color:rgb(0,0,136)">typename</span></var><sp=
an style> iterator_traits</span><span style=3D"color:rgb(102,102,0)">&lt;</=
span><span style=3D"color:rgb(102,0,102)">InputIterator</span><span style=
=3D"color:rgb(102,102,0)">&gt;::</span><span style>difference_type<br>


=A0 =A0 count_while </span><span style=3D"color:rgb(102,102,0)">(</span><sp=
an style=3D"color:rgb(102,0,102)">InputIterator</span><span style> first</s=
pan><span style=3D"color:rgb(102,102,0)">,</span><span style> </span><span =
style=3D"color:rgb(102,0,102)">InputIterator</span><span style> </span><spa=
n style=3D"color:rgb(0,0,136)">last</span><span style=3D"color:rgb(102,102,=
0)">,</span><span style> </span><span style=3D"color:rgb(102,0,102)">UnaryP=
redicate</span><span style> pred</span><span style=3D"color:rgb(102,102,0)"=
>)</span><span style><br>


</span><span style=3D"color:rgb(102,102,0)">{</span><span style><br>=A0 </s=
pan><var><span style=3D"color:rgb(0,0,136)">typename</span></var><span styl=
e> iterator_traits</span><span style=3D"color:rgb(102,102,0)">&lt;</span><s=
pan style=3D"color:rgb(102,0,102)">InputIterator</span><span style=3D"color=
:rgb(102,102,0)">&gt;::</span><span style>difference_type ret </span><span =
style=3D"color:rgb(102,102,0)">=3D</span><span style> </span><span style=3D=
"color:rgb(0,102,102)">0</span><span style=3D"color:rgb(102,102,0)">;</span=
><span style><br>


=A0 </span><var><span style=3D"color:rgb(0,0,136)">while</span></var><span =
style> </span><span style=3D"color:rgb(102,102,0)">(</span><span style>firs=
t</span><span style=3D"color:rgb(102,102,0)">!=3D</span><span style=3D"colo=
r:rgb(0,0,136)">last</span><var><span style> </span><span style=3D"color:rg=
b(102,102,0)">&amp;&amp;</span><span style> </span></var><var></var><span s=
tyle>pred</span><span style=3D"color:rgb(102,102,0)">(*</span><span style>f=
irst</span><span style=3D"color:rgb(102,102,0)">))</span><span style> </spa=
n><span style=3D"color:rgb(102,102,0)">{</span><span style><br>


=A0 =A0 </span><span style=3D"color:rgb(102,102,0)">++</span><span style>re=
t</span><span style=3D"color:rgb(102,102,0)">;</span><span style><br>=A0 =
=A0 </span><span style=3D"color:rgb(102,102,0)">++</span><span style>first<=
/span><span style=3D"color:rgb(102,102,0)">;</span><span style><br>


=A0 </span><span style=3D"color:rgb(102,102,0)">}</span><span style><br>=A0=
 </span><var><span style=3D"color:rgb(0,0,136)">return</span></var><span st=
yle> ret</span><span style=3D"color:rgb(102,102,0)">;</span><span style><br=
>

</span><span style=3D"color:rgb(102,102,0)">}</span></code></pre></div></co=
de></div><br><div style=3D"background-color:rgb(250,250,250);border-color:r=
gb(187,187,187);border-style:solid;border-width:1px;word-wrap:break-word">


<code><div><pre><code><var><span style=3D"color:rgb(0,0,136)">template</spa=
n></var><span style> </span><span style=3D"color:rgb(102,102,0)">&lt;</span=
><var><span style=3D"color:rgb(0,0,136)">class</span></var><span style> </s=
pan><span style=3D"color:rgb(102,0,102)">InputIterator</span><span style=3D=
"color:rgb(102,102,0)">,</span><span style> </span><var><span style=3D"colo=
r:rgb(0,0,136)">class</span></var><span style> </span><span style=3D"color:=
rgb(102,0,102)">UnaryPredicate</span><span style=3D"color:rgb(102,102,0)">&=
gt;</span><span style><br>


=A0 </span><var><span style=3D"color:rgb(0,0,136)">typename</span></var><sp=
an style> iterator_traits</span><span style=3D"color:rgb(102,102,0)">&lt;</=
span><span style=3D"color:rgb(102,0,102)">InputIterator</span><span style=
=3D"color:rgb(102,102,0)">&gt;::</span><span style>difference_type<br>


=A0 =A0 count_until </span><span style=3D"color:rgb(102,102,0)">(</span><sp=
an style=3D"color:rgb(102,0,102)">InputIterator</span><span style> first</s=
pan><span style=3D"color:rgb(102,102,0)">,</span><span style> </span><span =
style=3D"color:rgb(102,0,102)">InputIterator</span><span style> </span><spa=
n style=3D"color:rgb(0,0,136)">last</span><span style=3D"color:rgb(102,102,=
0)">,</span><span style> </span><span style=3D"color:rgb(102,0,102)">UnaryP=
redicate</span><span style> pred</span><span style=3D"color:rgb(102,102,0)"=
>)</span><span style><br>


</span><span style=3D"color:rgb(102,102,0)">{</span><span style><br><code><=
pre><code><span style>=A0 </span><var><span style=3D"color:rgb(0,0,136)">ty=
pename</span></var><span style> iterator_traits</span><span style=3D"color:=
rgb(102,102,0)">&lt;</span><span style=3D"color:rgb(102,0,102)">InputIterat=
or</span><span style=3D"color:rgb(102,102,0)">&gt;::</span><span style>diff=
erence_type ret </span><span style=3D"color:rgb(102,102,0)">=3D</span><span=
 style> </span><span style=3D"color:rgb(0,102,102)">0</span><span style=3D"=
color:rgb(102,102,0)">;</span><span style><br>


=A0 </span><var><span style=3D"color:rgb(0,0,136)">while</span></var><span =
style> </span><span style=3D"color:rgb(102,102,0)">(</span><span style>firs=
t</span><span style=3D"color:rgb(102,102,0)">!=3D</span><span style=3D"colo=
r:rgb(0,0,136)">last</span><var><span style> </span><span style=3D"color:rg=
b(102,102,0)">&amp;&amp;</span><span style> </span></var><var></var><span s=
tyle>!pred</span><span style=3D"color:rgb(102,102,0)">(*</span><span style>=
first</span><span style=3D"color:rgb(102,102,0)">))</span><span style> </sp=
an><span style=3D"color:rgb(102,102,0)">{</span><span style><br>


=A0 =A0 </span><span style=3D"color:rgb(102,102,0)">++</span><span style>re=
t</span><span style=3D"color:rgb(102,102,0)">;</span><span style><br>=A0 =
=A0 </span><span style=3D"color:rgb(102,102,0)">++</span><span style>first<=
/span><span style=3D"color:rgb(102,102,0)">;</span><span style><br>


=A0 </span><span style=3D"color:rgb(102,102,0)">}</span><span style><br>=A0=
 </span><var><span style=3D"color:rgb(0,0,136)">return</span></var><span st=
yle> ret;<br>

}</span><span style=3D"color:rgb(102,102,0)"></span></code></pre></code></s=
pan></code><code><span style></span><span style=3D"color:rgb(102,102,0)"></=
span></code></pre></div></code></div>

<br>What do you think about adding these two components to the algorithms l=
ibrary ?</div><span class=3D"HOEnZb"><font color=3D"#888888">

<p></p>

-- <br>
=A0<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%2Bunsubscribe@isocpp.org" target=3D=
"_blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</font></span></blockquote></div><br></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 />

--001a11c37ababadd5f04e840718e--

.
