220 7164 <CAArVCkSwua_Z1oFZ1qEWswO8zTNYSxaA-ZoZCKKfGjwicmPHUA@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: Re: "count_while" and "count_until" algorithms
Date: Tue, 8 Oct 2013 22:28:39 +0200
Lines: 304
Approved: news@gmane.org
Message-ID: <CAArVCkSwua_Z1oFZ1qEWswO8zTNYSxaA-ZoZCKKfGjwicmPHUA@mail.gmail.com>
References: <CAOpASk64dV+3ZUW+Z8wcEqug_oSaztvJp1zsDB_QdAxi+fwcsA@mail.gmail.com>
	<3c5637a3-5760-4825-83e1-c4bfc062e652@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=001a11c37a0832378904e8409dfa
X-Trace: ger.gmane.org 1381264117 28300 80.91.229.3 (8 Oct 2013 20:28:37 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 8 Oct 2013 20:28:37 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBD35NAXJW4GBB6GV2GJAKGQE6W25IHI@isocpp.org Tue Oct 08 22:28:41 2013
Return-path: <std-proposals+bncBD35NAXJW4GBB6GV2GJAKGQE6W25IHI@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+bncBD35NAXJW4GBB6GV2GJAKGQE6W25IHI@isocpp.org>)
	id 1VTdtZ-0000fn-Fu
	for gclcip-std-proposals@m.gmane.org; Tue, 08 Oct 2013 22:28:41 +0200
Original-Received: by mail-ea0-f198.google.com with SMTP id z15sf11890090ead.1
        for <gclcip-std-proposals@m.gmane.org>; Tue, 08 Oct 2013 13:28:41 -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=AU5WvbJ/lLo05PWrnTR4vB4bdqIEpLS+AHdiXSwYciY=;
        b=jmhGbDcoKWfXS5ODpdeHI7ohWsWT1jPgouIFcKNSeuYJUrX013kou7voYMAjKzStZ0
         tMEhvEtnsMiinfi8+S32dY/kVum2sD0AjUb5VLmgoRTJP4/Im44ItiJtlPUoH6x3juLx
         uCUU9ryntODl8mq/dnu9BdBIEniIpKR8t7OG4EHAkjTUfWpJeTjaMuhGzdIBd4v4UCKv
         IhRrdv3CkEw3XIC2MbfVdCZUA3uOlcb+28OtcyZkeHMSZklhqipf3uWP0R4Ce7gH/Tu/
         tgU+187JdWhjOO3+RGlJL5Sza6MUJe04dbyG19XiCgD7V1qceh8b0rI8nuIzBzEdtgA6
         087A==
X-Received: by 10.180.36.97 with SMTP id p1mr1400517wij.3.1381264120847;
        Tue, 08 Oct 2013 13:28:40 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.180.106.6 with SMTP id gq6ls225650wib.34.gmail; Tue, 08 Oct
 2013 13:28:40 -0700 (PDT)
X-Received: by 10.205.15.72 with SMTP id pt8mr3400084bkb.17.1381264120153;
        Tue, 08 Oct 2013 13:28:40 -0700 (PDT)
Original-Received: from mail-la0-x22f.google.com (mail-la0-x22f.google.com [2a00:1450:4010:c03::22f])
        by mx.google.com with ESMTPS id ud6si605358bkb.290.1969.12.31.16.00.00
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Tue, 08 Oct 2013 13:28:40 -0700 (PDT)
Received-SPF: pass (google.com: domain of p.stephani2@gmail.com designates 2a00:1450:4010:c03::22f as permitted sender) client-ip=2a00:1450:4010:c03::22f;
Original-Received: by mail-la0-f47.google.com with SMTP id eo20so7296525lab.20
        for <std-proposals@isocpp.org>; Tue, 08 Oct 2013 13:28:39 -0700 (PDT)
X-Received: by 10.112.14.3 with SMTP id l3mr3904269lbc.27.1381264119705; Tue,
 08 Oct 2013 13:28:39 -0700 (PDT)
Original-Received: by 10.112.213.73 with HTTP; Tue, 8 Oct 2013 13:28:39 -0700 (PDT)
In-Reply-To: <3c5637a3-5760-4825-83e1-c4bfc062e652@isocpp.org>
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::22f 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:7164
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/7164>

--001a11c37a0832378904e8409dfa
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

That doesn't work if you can make only a single pass through the range.


2013/10/8 Vlad from Moscow <vlad.moscow@mail.ru>

> Till now I do not see any great sense in introducing these algorithms. Th=
e
> first algorithm is in fact equivalent to
>
> std::distance( first, std::find_if( first, last, std::not_equal_to<T>() )
> );
>
> The second algorithm is equivalent to
>
> std::distance( first, std::find_if( first, last, std::equal_to<T>() ) );
>
>
> =D1=81=D1=80=D0=B5=D0=B4=D0=B0, 9 =D0=BE=D0=BA=D1=82=D1=8F=D0=B1=D1=80=D1=
=8F 2013 =D0=B3., 0:04:23 UTC+4 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=
=D0=B0=D1=82=D0=B5=D0=BB=D1=8C R=C3=A9my Lefevre =D0=BD=D0=B0=D0=BF=D0=B8=
=D1=81=D0=B0=D0=BB:
>
>> Hi,
>>
>> I thought about two new algorithms, that could be named "count_while" an=
d
>> "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/.

--001a11c37a0832378904e8409dfa
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">That doesn&#39;t work if you can make only a single pass t=
hrough the range.<br><div class=3D"gmail_extra"><br><br><div class=3D"gmail=
_quote">2013/10/8 Vlad from Moscow <span dir=3D"ltr">&lt;<a href=3D"mailto:=
vlad.moscow@mail.ru" target=3D"_blank">vlad.moscow@mail.ru</a>&gt;</span><b=
r>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>Till now=C2=A0I do not=
 see any great sense in introducing these algorithms. The first algorithm i=
s in fact equivalent to</div>
<div>=C2=A0</div><div>std::distance( first, std::find_if( first, last, std:=
:not_equal_to&lt;T&gt;() ) );</div><div>=C2=A0</div><div>The second algorit=
hm is equivalent to</div><div>=C2=A0</div><div>std::distance( first, std::f=
ind_if( first, last, std::equal_to&lt;T&gt;() ) );</div>
<div>=C2=A0</div><div><br>=D1=81=D1=80=D0=B5=D0=B4=D0=B0, 9 =D0=BE=D0=BA=D1=
=82=D1=8F=D0=B1=D1=80=D1=8F 2013=C2=A0=D0=B3., 0:04:23 UTC+4 =D0=BF=D0=BE=
=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C R=C3=A9my Lefe=
vre =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:</div><div><div class=3D"h5"=
><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;paddin=
g-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-=
left-style:solid">
<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"border:1px solid rgb(187,187,187);word-wra=
p:break-word;background-color:rgb(250,250,250)">


<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>


=C2=A0 </span><var><span style=3D"color:rgb(0,0,136)">typename</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)">InputIterator</span><span styl=
e=3D"color:rgb(102,102,0)">&gt;<u></u>::</span><span style>difference_type<=
br>


=C2=A0 =C2=A0 count_while </span><span style=3D"color:rgb(102,102,0)">(</sp=
an><span style=3D"color:rgb(102,0,102)">InputIterator</span><span style> fi=
rst</span><span style=3D"color:rgb(102,102,0)">,</span><span style> </span>=
<span style=3D"color:rgb(102,0,102)">InputIterator</span><span style> </spa=
n><span style=3D"color:rgb(0,0,136)">last</span><span style=3D"color:rgb(10=
2,102,0)">,</span><span style> </span><span style=3D"color:rgb(102,0,102)">=
UnaryPredicate</span><span style> pred</span><span style=3D"color:rgb(102,1=
02,0)">)</span><span style><br>


</span><span style=3D"color:rgb(102,102,0)">{</span><span style><br>=C2=A0 =
</span><var><span style=3D"color:rgb(0,0,136)">typename</span></var><span s=
tyle> 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"co=
lor:rgb(102,102,0)">&gt;<u></u>::</span><span style>difference_type ret </s=
pan><span style=3D"color:rgb(102,102,0)">=3D</span><span style> </span><spa=
n style=3D"color:rgb(0,102,102)">0</span><span style=3D"color:rgb(102,102,0=
)">;</span><span style><br>


=C2=A0 </span><var><span style=3D"color:rgb(0,0,136)">while</span></var><sp=
an style> </span><span style=3D"color:rgb(102,102,0)">(</span><span style>f=
irst</span><span style=3D"color:rgb(102,102,0)">!=3D</span><span style=3D"c=
olor:rgb(0,0,136)">last</span><var><span style> </span><span style=3D"color=
:rgb(102,102,0)">&amp;&amp;</span><span style> </span></var><var></var><spa=
n style>pred</span><span style=3D"color:rgb(102,102,0)">(*</span><span styl=
e>first</span><span style=3D"color:rgb(102,102,0)">))</span><span style> </=
span><span style=3D"color:rgb(102,102,0)">{</span><span style><br>


=C2=A0 =C2=A0 </span><span style=3D"color:rgb(102,102,0)">++</span><span st=
yle>ret</span><span style=3D"color:rgb(102,102,0)">;</span><span style><br>=
=C2=A0 =C2=A0 </span><span style=3D"color:rgb(102,102,0)">++</span><span st=
yle>first</span><span style=3D"color:rgb(102,102,0)">;</span><span style><b=
r>


=C2=A0 </span><span style=3D"color:rgb(102,102,0)">}</span><span style><br>=
=C2=A0 </span><var><span style=3D"color:rgb(0,0,136)">return</span></var><s=
pan style> ret</span><span style=3D"color:rgb(102,102,0)">;</span><span sty=
le><br>

</span><span style=3D"color:rgb(102,102,0)">}</span></code></pre></div></co=
de></div><br><div style=3D"border:1px solid rgb(187,187,187);word-wrap:brea=
k-word;background-color:rgb(250,250,250)">

<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>


=C2=A0 </span><var><span style=3D"color:rgb(0,0,136)">typename</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)">InputIterator</span><span styl=
e=3D"color:rgb(102,102,0)">&gt;<u></u>::</span><span style>difference_type<=
br>


=C2=A0 =C2=A0 count_until </span><span style=3D"color:rgb(102,102,0)">(</sp=
an><span style=3D"color:rgb(102,0,102)">InputIterator</span><span style> fi=
rst</span><span style=3D"color:rgb(102,102,0)">,</span><span style> </span>=
<span style=3D"color:rgb(102,0,102)">InputIterator</span><span style> </spa=
n><span style=3D"color:rgb(0,0,136)">last</span><span style=3D"color:rgb(10=
2,102,0)">,</span><span style> </span><span style=3D"color:rgb(102,0,102)">=
UnaryPredicate</span><span style> pred</span><span style=3D"color:rgb(102,1=
02,0)">)</span><span style><br>


</span><span style=3D"color:rgb(102,102,0)">{</span><span style><br><code><=
pre><code><span style>=C2=A0 </span><var><span style=3D"color:rgb(0,0,136)"=
>typename</span></var><span style> iterator_traits</span><span style=3D"col=
or:rgb(102,102,0)">&lt;</span><span style=3D"color:rgb(102,0,102)">InputIte=
rator</span><span style=3D"color:rgb(102,102,0)">&gt;<u></u>::</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>


=C2=A0 </span><var><span style=3D"color:rgb(0,0,136)">while</span></var><sp=
an style> </span><span style=3D"color:rgb(102,102,0)">(</span><span style>f=
irst</span><span style=3D"color:rgb(102,102,0)">!=3D</span><span style=3D"c=
olor:rgb(0,0,136)">last</span><var><span style> </span><span style=3D"color=
:rgb(102,102,0)">&amp;&amp;</span><span style> </span></var><var></var><spa=
n style>!pred</span><span style=3D"color:rgb(102,102,0)">(*</span><span sty=
le>first</span><span style=3D"color:rgb(102,102,0)">))</span><span style> <=
/span><span style=3D"color:rgb(102,102,0)">{</span><span style><br>


=C2=A0 =C2=A0 </span><span style=3D"color:rgb(102,102,0)">++</span><span st=
yle>ret</span><span style=3D"color:rgb(102,102,0)">;</span><span style><br>=
=C2=A0 =C2=A0 </span><span style=3D"color:rgb(102,102,0)">++</span><span st=
yle>first</span><span style=3D"color:rgb(102,102,0)">;</span><span style><b=
r>


=C2=A0 </span><span style=3D"color:rgb(102,102,0)">}</span><span style><br>=
=C2=A0 </span><var><span style=3D"color:rgb(0,0,136)">return</span></var><s=
pan style> 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>
</blockquote></div></div></div><div class=3D"HOEnZb"><div class=3D"h5">

<p></p>

-- <br>
=C2=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>
</div></div></blockquote></div><br></div></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 />

--001a11c37a0832378904e8409dfa--

.
