220 7165 <15c8d7a7-0547-466a-846a-e5f4656b62cd@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: "count_while" and "count_until" algorithms
Date: Tue, 8 Oct 2013 13:28:49 -0700 (PDT)
Lines: 291
Approved: news@gmane.org
Message-ID: <15c8d7a7-0547-466a-846a-e5f4656b62cd@isocpp.org>
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="----=_Part_74_30897740.1381264129783"
X-Trace: ger.gmane.org 1381264129 28399 80.91.229.3 (8 Oct 2013 20:28:49 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 8 Oct 2013 20:28:49 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCXLLRHD7IDRBA6W2GJAKGQE7ANICXA@isocpp.org Tue Oct 08 22:28:53 2013
Return-path: <std-proposals+bncBCXLLRHD7IDRBA6W2GJAKGQE7ANICXA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ob0-f200.google.com ([209.85.214.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCXLLRHD7IDRBA6W2GJAKGQE7ANICXA@isocpp.org>)
	id 1VTdtk-0000lh-Sq
	for gclcip-std-proposals@m.gmane.org; Tue, 08 Oct 2013 22:28:53 +0200
Original-Received: by mail-ob0-f200.google.com with SMTP id wo20sf4435810obc.7
        for <gclcip-std-proposals@m.gmane.org>; Tue, 08 Oct 2013 13:28:52 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe
         :content-type;
        bh=ehWy/MU1cscNNhMA9fpmVP6KE2oLOqCpIitozBhlpHU=;
        b=eJCBTc6PoTuGvvkiD+cGIleWKpXXe3XcZu2tJPvLhGLdabKM+IReQAp3V52cdv7Hkh
         2NdQuZr4t6jVAbWVQJS6hDNfzh798ucXkmC5t0dlY4jgo8rNvjUjuV5cSosZSxZGPj0W
         oPv7nOOHBMkR6PMoUNwf4HsRyjWSW5qpw8p4GRJ3gMWtk7ZzJILNFMJPtwerOfcIQ/tc
         kGZZ5k/HO3b4NLcnHSWaSqiSIkSewwIbR/evt+c4BDnFlEyROCni5QcI1HDjMVLsAEL9
         /6KGuvdt7lPStdk5bKzgJFfz1sJbi/o9fZnll46t8h4+KZOgvZMO+Z2RIdrNK323EFLX
         Wqhw==
X-Received: by 10.43.14.4 with SMTP id po4mr1998729icb.18.1381264131930;
        Tue, 08 Oct 2013 13:28:51 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.92.69 with SMTP id ck5ls3716340igb.20.canary; Tue, 08 Oct
 2013 13:28:51 -0700 (PDT)
X-Received: by 10.50.87.71 with SMTP id v7mr168296igz.11.1381264131380;
        Tue, 08 Oct 2013 13:28:51 -0700 (PDT)
In-Reply-To: <3c5637a3-5760-4825-83e1-c4bfc062e652@isocpp.org>
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: <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:7165
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/7165>

------=_Part_74_30897740.1381264129783
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Though maybe I am mistaken because the equivalent code does not work for=20
iterators that have std::input_iterator_tag.

=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:26:47 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 Vlad from Moscow=20
=D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:

> Till now I do not see any great sense in introducing these algorithms. Th=
e=20
> first algorithm is in fact equivalent to
> =20
> std::distance( first, std::find_if( first, last, std::not_equal_to<T>() )=
=20
> );
> =20
> The second algorithm is equivalent to
> =20
> std::distance( first, std::find_if( first, last, std::equal_to<T>() ) );
> =20
>
> =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=20
>> "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=20
>> library ?
>>
>

--=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_74_30897740.1381264129783
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Though maybe I am mistaken because the equivalent cod=
e does not work for iterators that have std::input_iterator_tag.</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&nbsp;=D0=B3., 0:26:47 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 Vlad from Moscow =D0=BD=D0=B0=D0=BF=
=D0=B8=D1=81=D0=B0=D0=BB:</div><blockquote class=3D"gmail_quote" style=3D"m=
argin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 20=
4, 204); border-left-width: 1px; border-left-style: solid;"><div dir=3D"ltr=
"><div>Till now&nbsp;I do not see any great sense in introducing these algo=
rithms. The first algorithm is in fact equivalent to</div><div>&nbsp;</div>=
<div>std::distance( first, std::find_if( first, last, std::not_equal_to&lt;=
T&gt;() ) );</div><div>&nbsp;</div><div>The second algorithm is equivalent =
to</div><div>&nbsp;</div><div>std::distance( first, std::find_if( first, la=
st, std::equal_to&lt;T&gt;() ) );</div><div>&nbsp;</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&nb=
sp;=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:</div><blockquote class=3D"gmail_quote" style=3D"margin: 0px 0=
px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); bor=
der-left-width: 1px; border-left-style: solid;"><div dir=3D"ltr">Hi,<br><br=
>I thought about two new algorithms, that could be named "count_while" and =
"count_until". Here are their behavior:<br><br><div style=3D"border: 1px so=
lid rgb(187, 187, 187); word-wrap: break-word; background-color: rgb(250, 2=
50, 250);">

<code><div><pre><code><var><span style=3D"color: rgb(0, 0, 136);">template<=
/span></var><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"col=
or: rgb(102, 102, 0);">&lt;</span><var><span style=3D"color: rgb(0, 0, 136)=
;">class</span></var><span style=3D"color: rgb(0, 0, 0);"> </span><span sty=
le=3D"color: rgb(102, 0, 102);">InputIterator</span><span style=3D"color: r=
gb(102, 102, 0);">,</span><span style=3D"color: rgb(0, 0, 0);"> </span><var=
><span style=3D"color: rgb(0, 0, 136);">class</span></var><span style=3D"co=
lor: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 0, 102);">UnaryP=
redicate</span><span style=3D"color: rgb(102, 102, 0);">&gt;</span><span st=
yle=3D"color: rgb(0, 0, 0);"><br>

&nbsp; </span><var><span style=3D"color: rgb(0, 0, 136);">typename</span></=
var><span style=3D"color: rgb(0, 0, 0);"> 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;<wb=
r>::</span><span style=3D"color: rgb(0, 0, 0);">difference_type<br>

&nbsp; &nbsp; count_while </span><span style=3D"color: rgb(102, 102, 0);">(=
</span><span style=3D"color: rgb(102, 0, 102);">InputIterator</span><span s=
tyle=3D"color: rgb(0, 0, 0);"> first</span><span style=3D"color: rgb(102, 1=
02, 0);">,</span><span style=3D"color: rgb(0, 0, 0);"> </span><span style=
=3D"color: rgb(102, 0, 102);">InputIterator</span><span style=3D"color: rgb=
(0, 0, 0);"> </span><span style=3D"color: rgb(0, 0, 136);">last</span><span=
 style=3D"color: rgb(102, 102, 0);">,</span><span style=3D"color: rgb(0, 0,=
 0);"> </span><span style=3D"color: rgb(102, 0, 102);">UnaryPredicate</span=
><span style=3D"color: rgb(0, 0, 0);"> pred</span><span style=3D"color: rgb=
(102, 102, 0);">)</span><span style=3D"color: rgb(0, 0, 0);"><br>

</span><span style=3D"color: rgb(102, 102, 0);">{</span><span style=3D"colo=
r: rgb(0, 0, 0);"><br>&nbsp; </span><var><span style=3D"color: rgb(0, 0, 13=
6);">typename</span></var><span style=3D"color: rgb(0, 0, 0);"> iterator_tr=
aits</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;<wbr>::</span><span style=3D"color: rgb(0, 0, 0);">diff=
erence_type ret </span><span style=3D"color: rgb(102, 102, 0);">=3D</span><=
span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(0, 10=
2, 102);">0</span><span style=3D"color: rgb(102, 102, 0);">;</span><span st=
yle=3D"color: rgb(0, 0, 0);"><br>

&nbsp; </span><var><span style=3D"color: rgb(0, 0, 136);">while</span></var=
><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102=
, 102, 0);">(</span><span style=3D"color: rgb(0, 0, 0);">first</span><span =
style=3D"color: rgb(102, 102, 0);">!=3D</span><span style=3D"color: rgb(0, =
0, 136);">last</span><var><span style=3D"color: rgb(0, 0, 0);"> </span><spa=
n style=3D"color: rgb(102, 102, 0);">&amp;&amp;</span><span style=3D"color:=
 rgb(0, 0, 0);"> </span></var><var></var><span style=3D"color: rgb(0, 0, 0)=
;">pred</span><span style=3D"color: rgb(102, 102, 0);">(*</span><span style=
=3D"color: rgb(0, 0, 0);">first</span><span style=3D"color: rgb(102, 102, 0=
);">))</span><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"co=
lor: rgb(102, 102, 0);">{</span><span style=3D"color: rgb(0, 0, 0);"><br>

&nbsp; &nbsp; </span><span style=3D"color: rgb(102, 102, 0);">++</span><spa=
n style=3D"color: rgb(0, 0, 0);">ret</span><span style=3D"color: rgb(102, 1=
02, 0);">;</span><span style=3D"color: rgb(0, 0, 0);"><br>&nbsp; &nbsp; </s=
pan><span style=3D"color: rgb(102, 102, 0);">++</span><span style=3D"color:=
 rgb(0, 0, 0);">first</span><span style=3D"color: rgb(102, 102, 0);">;</spa=
n><span style=3D"color: rgb(0, 0, 0);"><br>

&nbsp; </span><span style=3D"color: rgb(102, 102, 0);">}</span><span style=
=3D"color: rgb(0, 0, 0);"><br>&nbsp; </span><var><span style=3D"color: rgb(=
0, 0, 136);">return</span></var><span style=3D"color: rgb(0, 0, 0);"> ret</=
span><span style=3D"color: rgb(102, 102, 0);">;</span><span style=3D"color:=
 rgb(0, 0, 0);"><br>

</span><span style=3D"color: rgb(102, 102, 0);">}</span></code></pre></div>=
</code></div><br><div style=3D"border: 1px solid rgb(187, 187, 187); word-w=
rap: break-word; background-color: rgb(250, 250, 250);">

<code><div><pre><code><var><span style=3D"color: rgb(0, 0, 136);">template<=
/span></var><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"col=
or: rgb(102, 102, 0);">&lt;</span><var><span style=3D"color: rgb(0, 0, 136)=
;">class</span></var><span style=3D"color: rgb(0, 0, 0);"> </span><span sty=
le=3D"color: rgb(102, 0, 102);">InputIterator</span><span style=3D"color: r=
gb(102, 102, 0);">,</span><span style=3D"color: rgb(0, 0, 0);"> </span><var=
><span style=3D"color: rgb(0, 0, 136);">class</span></var><span style=3D"co=
lor: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 0, 102);">UnaryP=
redicate</span><span style=3D"color: rgb(102, 102, 0);">&gt;</span><span st=
yle=3D"color: rgb(0, 0, 0);"><br>

&nbsp; </span><var><span style=3D"color: rgb(0, 0, 136);">typename</span></=
var><span style=3D"color: rgb(0, 0, 0);"> 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;<wb=
r>::</span><span style=3D"color: rgb(0, 0, 0);">difference_type<br>

&nbsp; &nbsp; count_until </span><span style=3D"color: rgb(102, 102, 0);">(=
</span><span style=3D"color: rgb(102, 0, 102);">InputIterator</span><span s=
tyle=3D"color: rgb(0, 0, 0);"> first</span><span style=3D"color: rgb(102, 1=
02, 0);">,</span><span style=3D"color: rgb(0, 0, 0);"> </span><span style=
=3D"color: rgb(102, 0, 102);">InputIterator</span><span style=3D"color: rgb=
(0, 0, 0);"> </span><span style=3D"color: rgb(0, 0, 136);">last</span><span=
 style=3D"color: rgb(102, 102, 0);">,</span><span style=3D"color: rgb(0, 0,=
 0);"> </span><span style=3D"color: rgb(102, 0, 102);">UnaryPredicate</span=
><span style=3D"color: rgb(0, 0, 0);"> pred</span><span style=3D"color: rgb=
(102, 102, 0);">)</span><span style=3D"color: rgb(0, 0, 0);"><br>

</span><span style=3D"color: rgb(102, 102, 0);">{</span><span style=3D"colo=
r: rgb(0, 0, 0);"><br><code><pre><code><span style=3D"color: rgb(0, 0, 0);"=
>&nbsp; </span><var><span style=3D"color: rgb(0, 0, 136);">typename</span><=
/var><span style=3D"color: rgb(0, 0, 0);"> iterator_traits</span><span styl=
e=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;<w=
br>::</span><span style=3D"color: rgb(0, 0, 0);">difference_type ret </span=
><span style=3D"color: rgb(102, 102, 0);">=3D</span><span style=3D"color: r=
gb(0, 0, 0);"> </span><span style=3D"color: rgb(0, 102, 102);">0</span><spa=
n style=3D"color: rgb(102, 102, 0);">;</span><span style=3D"color: rgb(0, 0=
, 0);"><br>

&nbsp; </span><var><span style=3D"color: rgb(0, 0, 136);">while</span></var=
><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102=
, 102, 0);">(</span><span style=3D"color: rgb(0, 0, 0);">first</span><span =
style=3D"color: rgb(102, 102, 0);">!=3D</span><span style=3D"color: rgb(0, =
0, 136);">last</span><var><span style=3D"color: rgb(0, 0, 0);"> </span><spa=
n style=3D"color: rgb(102, 102, 0);">&amp;&amp;</span><span style=3D"color:=
 rgb(0, 0, 0);"> </span></var><var></var><span style=3D"color: rgb(0, 0, 0)=
;">!pred</span><span style=3D"color: rgb(102, 102, 0);">(*</span><span styl=
e=3D"color: rgb(0, 0, 0);">first</span><span style=3D"color: rgb(102, 102, =
0);">))</span><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"c=
olor: rgb(102, 102, 0);">{</span><span style=3D"color: rgb(0, 0, 0);"><br>

&nbsp; &nbsp; </span><span style=3D"color: rgb(102, 102, 0);">++</span><spa=
n style=3D"color: rgb(0, 0, 0);">ret</span><span style=3D"color: rgb(102, 1=
02, 0);">;</span><span style=3D"color: rgb(0, 0, 0);"><br>&nbsp; &nbsp; </s=
pan><span style=3D"color: rgb(102, 102, 0);">++</span><span style=3D"color:=
 rgb(0, 0, 0);">first</span><span style=3D"color: rgb(102, 102, 0);">;</spa=
n><span style=3D"color: rgb(0, 0, 0);"><br>

&nbsp; </span><span style=3D"color: rgb(102, 102, 0);">}</span><span style=
=3D"color: rgb(0, 0, 0);"><br>&nbsp; </span><var><span style=3D"color: rgb(=
0, 0, 136);">return</span></var><span style=3D"color: rgb(0, 0, 0);"> ret;<=
br>

}</span><span style=3D"color: rgb(102, 102, 0);"></span></code></pre></code=
></span></code><code><span style=3D"color: rgb(0, 0, 0);"></span><span styl=
e=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></blockquote></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 />

------=_Part_74_30897740.1381264129783--

.
