Topic: New algorithm split


Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Fri, 11 Jan 2013 07:22:53 -0800 (PST)
Raw View
------=_Part_578_16124983.1357917773777
Content-Type: text/plain; charset=ISO-8859-1

It is interesting to note that the standard library has several algorithms
that build a new sequence from given two sequences as for example
std::merge or the family of algorithms dealing with sets and there is no
algorithm that does the reverse operation that is splits a sequence into
two new sequences.

So maybe it would be useful to consider something as

template <class InputIterator,
    class OutputIterator1,
    class OutputIterator2,
          class UnaryPredicate>
std::pair<OutputIterator1, OutputIterator2> split( InputIterator first,
InputIterator last,
                     OutputIterator1 out1, OutputIterator2 out2,
      UnaryPredicate unary_predicate )
{
 for ( ; first != last; ++first )
 {
  if ( unary_predicate( *first ) ) *out1++ = *first;
  else *out2++ = *first;
 }
 return ( std::make_pair( out1, out2 ) );
}

--




------=_Part_578_16124983.1357917773777
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div>It is interesting to note that the standard library has several algori=
thms that build a new sequence from given two sequences as for example std:=
:merge or the family of algorithms dealing with sets and there is no algori=
thm that does the reverse operation that is splits a sequence into two new =
sequences.</div><div>&nbsp;</div><div>So maybe it would be useful to consid=
er something as</div><div>&nbsp;</div><div>template &lt;class InputIterator=
, <br>&nbsp;&nbsp;&nbsp; class OutputIterator1, <br>&nbsp;&nbsp;&nbsp; clas=
s OutputIterator2,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
; class UnaryPredicate&gt;<br>std::pair&lt;OutputIterator1, OutputIterator2=
&gt; split( InputIterator first, InputIterator last,<br>&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp; OutputIterator1 out1, OutputIterator2 out2,<br>&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UnaryPredicate unary_predicate )<br>{<br>&nbs=
p;for ( ; first !=3D last; ++first )<br>&nbsp;{<br>&nbsp;&nbsp;if ( unary_p=
redicate( *first ) ) *out1++ =3D *first;<br>&nbsp;&nbsp;else *out2++ =3D *f=
irst;<br>&nbsp;}</div><div>&nbsp;return ( std::make_pair( out1, out2 ) );<b=
r>}<br></div>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_578_16124983.1357917773777--

.


Author: Scott Prager <splinterofchaos@gmail.com>
Date: Fri, 11 Jan 2013 08:24:30 -0800 (PST)
Raw View
------=_Part_30_29357053.1357921470789
Content-Type: text/plain; charset=ISO-8859-1



On Friday, January 11, 2013 10:22:53 AM UTC-5, Vlad from Moscow wrote:
>
> It is interesting to note that the standard library has several algorithms
> that build a new sequence from given two sequences as for example
> std::merge or the family of algorithms dealing with sets and there is no
> algorithm that does the reverse operation that is splits a sequence into
> two new sequences.
>

I think this is equivalent:

http://en.cppreference.com/w/cpp/algorithm/partition_copy


>
> So maybe it would be useful to consider something as
>
> template <class InputIterator,
>     class OutputIterator1,
>     class OutputIterator2,
>           class UnaryPredicate>
> std::pair<OutputIterator1, OutputIterator2> split( InputIterator first,
> InputIterator last,
>                      OutputIterator1 out1, OutputIterator2 out2,
>       UnaryPredicate unary_predicate )
> {
>  for ( ; first != last; ++first )
>  {
>   if ( unary_predicate( *first ) ) *out1++ = *first;
>   else *out2++ = *first;
>  }
>  return ( std::make_pair( out1, out2 ) );
> }
>

--




------=_Part_30_29357053.1357921470789
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<br><br>On Friday, January 11, 2013 10:22:53 AM UTC-5, Vlad from Moscow wro=
te:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;=
border-left: 1px #ccc solid;padding-left: 1ex;"><div>It is interesting to n=
ote that the standard library has several algorithms that build a new seque=
nce from given two sequences as for example std::merge or the family of alg=
orithms dealing with sets and there is no algorithm that does the reverse o=
peration that is splits a sequence into two new sequences.</div></blockquot=
e><div><br>I think this is equivalent:<br><br>http://en.cppreference.com/w/=
cpp/algorithm/partition_copy<br>&nbsp;</div><blockquote class=3D"gmail_quot=
e" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;paddin=
g-left: 1ex;"><div>&nbsp;</div><div>So maybe it would be useful to consider=
 something as</div><div>&nbsp;</div><div>template &lt;class InputIterator, =
<br>&nbsp;&nbsp;&nbsp; class OutputIterator1, <br>&nbsp;&nbsp;&nbsp; class =
OutputIterator2,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
class UnaryPredicate&gt;<br>std::pair&lt;OutputIterator1, OutputIterator2&g=
t; split( InputIterator first, InputIterator last,<br>&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp; OutputIterator1 out1, OutputIterator2 out2,<br>&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp; UnaryPredicate unary_predicate )<br>{<br>&nbsp;=
for ( ; first !=3D last; ++first )<br>&nbsp;{<br>&nbsp;&nbsp;if ( unary_pre=
dicate( *first ) ) *out1++ =3D *first;<br>&nbsp;&nbsp;else *out2++ =3D *fir=
st;<br>&nbsp;}</div><div>&nbsp;return ( std::make_pair( out1, out2 ) );<br>=
}<br></div></blockquote>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_30_29357053.1357921470789--

.


Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Fri, 11 Jan 2013 08:35:30 -0800 (PST)
Raw View
------=_Part_216_23968020.1357922130979
Content-Type: text/plain; charset=KOI8-R
Content-Transfer-Encoding: quoted-printable


=D0=D1=D4=CE=C9=C3=C1, 11 =D1=CE=D7=C1=D2=D1 2013 =C7., 20:24:30 UTC+4 =D0=
=CF=CC=D8=DA=CF=D7=C1=D4=C5=CC=D8 Scott Prager=20
=CE=C1=D0=C9=D3=C1=CC:
>
>
>
> On Friday, January 11, 2013 10:22:53 AM UTC-5, Vlad from Moscow wrote:
>>
>> It is interesting to note that the standard library has several=20
>> algorithms that build a new sequence from given two sequences as for=20
>> example std::merge or the family of algorithms dealing with sets and the=
re=20
>> is no algorithm that does the reverse operation that is splits a sequenc=
e=20
>> into two new sequences.
>>
>
> I think this is equivalent:
>
> http://en.cppreference.com/w/cpp/algorithm/partition_copy
> =20
>
>> =20
>> So maybe it would be useful to consider something as
>> =20
>> template <class InputIterator,=20
>>     class OutputIterator1,=20
>>     class OutputIterator2,
>>           class UnaryPredicate>
>> std::pair<OutputIterator1, OutputIterator2> split( InputIterator first,=
=20
>> InputIterator last,
>>                      OutputIterator1 out1, OutputIterator2 out2,
>>       UnaryPredicate unary_predicate )
>> {
>>  for ( ; first !=3D last; ++first )
>>  {
>>   if ( unary_predicate( *first ) ) *out1++ =3D *first;
>>   else *out2++ =3D *first;
>>  }
>>  return ( std::make_pair( out1, out2 ) );
>> }
>>
> =20
=20
Thanks. I did not even know that such algorithm already exists in the=20
standard library. :)  It seems that it was included only in C++ 11.=20

--=20




------=_Part_216_23968020.1357922130979
Content-Type: text/html; charset=KOI8-R
Content-Transfer-Encoding: quoted-printable

<br>=D0=D1=D4=CE=C9=C3=C1, 11 =D1=CE=D7=C1=D2=D1 2013&nbsp;=C7., 20:24:30 U=
TC+4 =D0=CF=CC=D8=DA=CF=D7=C1=D4=C5=CC=D8 Scott Prager =CE=C1=D0=C9=D3=C1=
=CC:<blockquote style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; bord=
er-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-styl=
e: solid;" class=3D"gmail_quote"><br><br>On Friday, January 11, 2013 10:22:=
53 AM UTC-5, Vlad from Moscow wrote:<blockquote style=3D"margin: 0px 0px 0p=
x 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-l=
eft-width: 1px; border-left-style: solid;" class=3D"gmail_quote"><div>It is=
 interesting to note that the standard library has several algorithms that =
build a new sequence from given two sequences as for example std::merge or =
the family of algorithms dealing with sets and there is no algorithm that d=
oes the reverse operation that is splits a sequence into two new sequences.=
</div></blockquote><div><br>I think this is equivalent:<br><br><a href=3D"h=
ttp://en.cppreference.com/w/cpp/algorithm/partition_copy" target=3D"_blank"=
>http://en.cppreference.com/w/<wbr>cpp/algorithm/partition_copy</a><br>&nbs=
p;</div><blockquote style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; =
border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-=
style: solid;" class=3D"gmail_quote"><div>&nbsp;</div><div>So maybe it woul=
d be useful to consider something as</div><div>&nbsp;</div><div>template &l=
t;class InputIterator, <br>&nbsp;&nbsp;&nbsp; class OutputIterator1, <br>&n=
bsp;&nbsp;&nbsp; class OutputIterator2,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp; class UnaryPredicate&gt;<br>std::pair&lt;OutputItera=
tor1, OutputIterator2&gt; split( InputIterator first, InputIterator last,<b=
r>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OutputIterator1 out1, Outpu=
tIterator2 out2,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UnaryPredicate unary_pre=
dicate )<br>{<br>&nbsp;for ( ; first !=3D last; ++first )<br>&nbsp;{<br>&nb=
sp;&nbsp;if ( unary_predicate( *first ) ) *out1++ =3D *first;<br>&nbsp;&nbs=
p;else *out2++ =3D *first;<br>&nbsp;}</div><div>&nbsp;return ( std::make_pa=
ir( out1, out2 ) );<br>}<br></div></blockquote></blockquote><div>&nbsp;</di=
v><div>&nbsp;</div><div>Thanks. I did not even know that such algorithm alr=
eady exists in the standard library. :) &nbsp;It seems that it was included=
&nbsp;only in C++ 11.&nbsp;</div>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_216_23968020.1357922130979--

.


Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@gmail.com>
Date: Fri, 11 Jan 2013 17:43:12 +0100
Raw View
2013/1/11 Vlad from Moscow <vlad.moscow@mail.ru>:
>
> =D0=D1=D4=CE=C9=C3=C1, 11 =D1=CE=D7=C1=D2=D1 2013 =C7., 20:24:30 UTC+4 =
=D0=CF=CC=D8=DA=CF=D7=C1=D4=C5=CC=D8 Scott Prager
> =CE=C1=D0=C9=D3=C1=CC:
>> I think this is equivalent:
>>
>> http://en.cppreference.com/w/cpp/algorithm/partition_copy
>>
[..]
>
> Thanks. I did not even know that such algorithm already exists in the
> standard library. :)  It seems that it was included only in C++ 11.

Yes, that is correct, it was added by acceptance of:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2666.pdf

- Daniel

--=20




.


Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Tue, 19 Feb 2013 02:59:54 -0800 (PST)
Raw View
------=_Part_833_7199664.1361271594736
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable


On Friday, January 11, 2013 8:43:12 PM UTC+4, Daniel Kr=C3=BCgler wrote:
>
> 2013/1/11 Vlad from Moscow <vlad....@mail.ru <javascript:>>:=20
> >=20
> > =D0=BF=D1=8F=D1=82=D0=BD=D0=B8=D1=86=D0=B0, 11 =D1=8F=D0=BD=D0=B2=D0=B0=
=D1=80=D1=8F 2013 =D0=B3., 20:24:30 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 Scott Prager=20
> > =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:=20
> >> I think this is equivalent:=20
> >>=20
> >> http://en.cppreference.com/w/cpp/algorithm/partition_copy=20
> >>=20
> [..]=20
> >=20
> > Thanks. I did not even know that such algorithm already exists in the=
=20
> > standard library. :)  It seems that it was included only in C++ 11.=20
>
> Yes, that is correct, it was added by acceptance of:=20
>
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2666.pdf=20
>
> - Daniel=20
>
=20
=20
Well, there is no problem.   In this case the thread can be renamed as=20
=20
"New algorithm partition_copy".:)
=20
Let consider a simple task: split a sequence of integers into two=20
sequences.The first one shall contain only positive numbers and the second=
=20
one shall contain only negative numbers. This simple task can not be done=
=20
by means of the current algorithm std::partition_copy because it is unknown=
=20
how to exclude elements of the original sequence that are equal to zero. So=
=20
the possibilities of the current algorithm std::partition_copy is very=20
restrictive.
=20
I am suggesting to append this algorithm with a new modification which is=
=20
more flexible and will allow to do more complex task.  Here is its=20
definition
=20
template <class InputIterator,=20
          class OutputIterator1,=20
          class OutputIterator2,
          class UnaryPredicate1,
          class UnaryPredicate2>
std::pair<OutputIterator1, OutputIterator2>=20
partition_copy( InputIterator first, InputIterator last,
                OutputIterator1 out1, OutputIterator2 out2,
                UnaryPredicate1 unary_predicate1,
                UnaryPredicate2 unary_predicate2 )
{
 for ( ; first !=3D last; ++first )
 {
  if ( unary_predicate1( *first ) ) *out1++ =3D *first;
  if ( unary_predicate2( *first ) ) *out2++ =3D *first;
 }
 return ( std::make_pair( out1, out2 ) );
}

Take into account that instead of statement

  else if ( unary_predicate2( *first ) ) *out2++ =3D *first;

there is=20

  if ( unary_predicate2( *first ) ) *out2++ =3D *first;

This will allow to place an element of the original sequence in two result=
=20
sequences simultaneously.

In fact this algorithm includes two algorithms std::copy_if that deal with=
=20
the same original sequence. But it is more effective than to apply=20
std::copy_if two times sequentially.

--=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/?hl=3Den.



------=_Part_833_7199664.1361271594736
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<br>On Friday, January 11, 2013 8:43:12 PM UTC+4, Daniel Kr=C3=BCgler wrote=
:<blockquote style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-=
left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: =
solid;" class=3D"gmail_quote">2013/1/11 Vlad from Moscow &lt;<a href=3D"jav=
ascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"OkSpVUdUtosJ">vlad....=
@mail.ru</a>&gt;:
<br>&gt;
<br>&gt; =D0=BF=D1=8F=D1=82=D0=BD=D0=B8=D1=86=D0=B0, 11 =D1=8F=D0=BD=D0=B2=
=D0=B0=D1=80=D1=8F 2013 =D0=B3., 20:24:30 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 Scott Prager
<br>&gt; =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:
<br>&gt;&gt; I think this is equivalent:
<br>&gt;&gt;
<br>&gt;&gt; <a href=3D"http://en.cppreference.com/w/cpp/algorithm/partitio=
n_copy" target=3D"_blank">http://en.cppreference.com/w/<wbr>cpp/algorithm/p=
artition_copy</a>
<br>&gt;&gt;
<br>[..]
<br>&gt;
<br>&gt; Thanks. I did not even know that such algorithm already exists in =
the
<br>&gt; standard library. :) &nbsp;It seems that it was included only in C=
++ 11.
<br>
<br>Yes, that is correct, it was added by acceptance of:
<br>
<br><a href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n266=
6.pdf" target=3D"_blank">http://www.open-std.org/jtc1/<wbr>sc22/wg21/docs/p=
apers/2008/<wbr>n2666.pdf</a>
<br>
<br>- Daniel
<br></blockquote><div>&nbsp;</div><div>&nbsp;</div><div>Well, there is no p=
roblem. &nbsp; In this case the thread can be renamed as </div><div>&nbsp;<=
/div><div>"New algorithm partition_copy".:)</div><div>&nbsp;</div><div>Let =
consider a simple task: split a sequence of integers into two sequences.The=
 first one shall contain only positive numbers and the second one shall con=
tain only negative numbers. This simple task can not be done by means of th=
e current algorithm std::partition_copy because it is unknown how to exclud=
e elements of the original sequence that are equal to zero. So the possibil=
ities of the current algorithm std::partition_copy is very restrictive.</di=
v><div>&nbsp;</div><div>I&nbsp;am suggesting to append this algorithm with&=
nbsp;a new modification which&nbsp;is more flexible and&nbsp;will allow to =
do more complex task.&nbsp; Here is its definition</div><div><font size=3D"=
2" face=3D"Consolas"><font size=3D"2" face=3D"Consolas"></font></font>&nbsp=
;</div><div><font size=3D"2" face=3D"Consolas"><font size=3D"2" face=3D"Con=
solas">template &lt;class InputIterator, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp; class OutputIterator1, <br>&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; class OutputIterator2,<br>&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; class UnaryPredicate1,<br>&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; class UnaryPredicate2&gt;<br>st=
d::pair&lt;OutputIterator1, OutputIterator2&gt; <br>partition_copy( InputIt=
erator first, InputIterator last,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OutputIterator1 out1, =
OutputIterator2 out2,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UnaryPredicate1 unary_predicate1,<=
br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;UnaryPredicate2 unary_predicate2 )<br>{<br>&nbsp;fo=
r ( ; first !=3D last; ++first )<br>&nbsp;{<br>&nbsp;&nbsp;if ( unary_predi=
cate1( *first ) ) *out1++ =3D *first;<br>&nbsp;&nbsp;if ( unary_predicate2(=
 *first ) ) *out2++ =3D *first;<br>&nbsp;}</font></font></div><div><font si=
ze=3D"2" face=3D"Consolas"><font size=3D"2" face=3D"Consolas">&nbsp;return =
( std::make_pair( out1, out2 ) );<br>}<br></font></font></div><font size=3D=
"2" face=3D"Consolas"><font size=3D"2" face=3D"Consolas"><p>Take into accou=
nt that instead of&nbsp;statement</p><p>&nbsp;&nbsp;else if ( unary_predica=
te2( *first ) ) *out2++ =3D *first;<br></p><p>there is </p><p><font size=3D=
"2">&nbsp; if ( unary_predicate2( *first ) ) *out2++ =3D *first;</font><br>=
</p><p>This will allow to place an element of the original sequence in two =
result sequences simultaneously.</p><p>In fact this algorithm includes two =
algorithms std::copy_if&nbsp;that deal with the same original sequence. But=
 it is more effective than to apply std::copy_if two times sequentially.</p=
>
</font></font>

<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/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_833_7199664.1361271594736--

.


Author: Marshall Clow <mclow.lists@gmail.com>
Date: Tue, 19 Feb 2013 09:08:23 -0800
Raw View
--Apple-Mail=_4D60ED7E-182A-4EE6-AF68-BBD7998B1BCE
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8

On Feb 19, 2013, at 2:59 AM, Vlad from Moscow <vlad.moscow@mail.ru> wrote:
> On Friday, January 11, 2013 8:43:12 PM UTC+4, Daniel Kr=C3=BCgler wrote:
> 2013/1/11 Vlad from Moscow <vlad....@mail.ru>:=20
> >=20
> > =D0=BF=D1=8F=D1=82=D0=BD=D0=B8=D1=86=D0=B0, 11 =D1=8F=D0=BD=D0=B2=D0=B0=
=D1=80=D1=8F 2013 =D0=B3., 20:24:30 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 Scott Prager=20
> > =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:=20
> >> I think this is equivalent:=20
> >>=20
> >> http://en.cppreference.com/w/cpp/algorithm/partition_copy=20
> >>=20
> [..]=20
> >=20
> > Thanks. I did not even know that such algorithm already exists in the=
=20
> > standard library. :)  It seems that it was included only in C++ 11.=20
>=20
> Yes, that is correct, it was added by acceptance of:=20
>=20
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2666.pdf=20
>=20
> - Daniel=20
> =20
> =20
> Well, there is no problem.   In this case the thread can be renamed as
> =20
> "New algorithm partition_copy".:)
> =20
> Let consider a simple task: split a sequence of integers into two sequenc=
es.The first one shall contain only positive numbers and the second one sha=
ll contain only negative numbers. This simple task can not be done by means=
 of the current algorithm std::partition_copy because it is unknown how to =
exclude elements of the original sequence that are equal to zero. So the po=
ssibilities of the current algorithm std::partition_copy is very restrictiv=
e.
> =20
> I am suggesting to append this algorithm with a new modification which is=
 more flexible and will allow to do more complex task.  Here is its definit=
ion
> =20
> template <class InputIterator,=20
>           class OutputIterator1,=20
>           class OutputIterator2,
>           class UnaryPredicate1,
>           class UnaryPredicate2>
> std::pair<OutputIterator1, OutputIterator2>=20
> partition_copy( InputIterator first, InputIterator last,
>                 OutputIterator1 out1, OutputIterator2 out2,
>                 UnaryPredicate1 unary_predicate1,
>                 UnaryPredicate2 unary_predicate2 )
> {
>  for ( ; first !=3D last; ++first )
>  {
>   if ( unary_predicate1( *first ) ) *out1++ =3D *first;
>   if ( unary_predicate2( *first ) ) *out2++ =3D *first;
>  }
>  return ( std::make_pair( out1, out2 ) );
> }
> Take into account that instead of statement
>=20
>   else if ( unary_predicate2( *first ) ) *out2++ =3D *first;
>=20
> there is
>=20
>   if ( unary_predicate2( *first ) ) *out2++ =3D *first;
>=20
> This will allow to place an element of the original sequence in two resul=
t sequences simultaneously.
>=20
> In fact this algorithm includes two algorithms std::copy_if that deal wit=
h the same original sequence. But it is more effective than to apply std::c=
opy_if two times sequentially.
>=20

This feels wrong to me.   [ How's that for a deep technical argument?  ;-) =
]

Two predicates, two outputs? And the ones that aren't matched aren't copied=
 at all?
 Those seem like arbitrary decisions.

If I were proposing something like this, I might suggest a collection of pr=
edicates and a (identically sized) collection of output iterators.
[ Warning - uncompiled code ]

 template <typename InputIterator, typename Predicates, typename Outputs>
 Outputs partition_copy ( InputIterator first, InputIterator last, Predicat=
es p, Outputs o )
 {
  for ( ; first !=3D last; ++first ) {
   auto pi =3D p.begin ();
   auto oi =3D o.begin ();
                 for ( ; pi !=3D p.end (); ++pi, ++oi )
    if ((*pi) (*first)) {
     **oi =3D *first;
     *oi++;
     break;
     }
  return o;
 }

If you want to copy the elements that don't match somewhere, put a predicat=
e that always returns true at the end of the list.

There's a similar algorithm that copies the values to _each_ output sequenc=
e where the predicates match (just remove the "break" from the code)

-- Marshall

Marshall Clow     Idio Software   <mailto:mclow.lists@gmail.com>

A.D. 1517: Martin Luther nails his 95 Theses to the church door and is prom=
ptly moderated down to (-1, Flamebait).
        -- Yu Suzuki

--=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/?hl=3Den.



--Apple-Mail=_4D60ED7E-182A-4EE6-AF68-BBD7998B1BCE
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; "><div><div>On Feb 19, 2013, a=
t 2:59 AM, Vlad from Moscow &lt;<a href=3D"mailto:vlad.moscow@mail.ru">vlad=
..moscow@mail.ru</a>&gt; wrote:</div><blockquote type=3D"cite">On Friday, Ja=
nuary 11, 2013 8:43:12 PM UTC+4, Daniel Kr=C3=BCgler wrote:<blockquote styl=
e=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(2=
04, 204, 204); border-left-width: 1px; border-left-style: solid;" class=3D"=
gmail_quote">2013/1/11 Vlad from Moscow &lt;<a href=3D"javascript:" target=
=3D"_blank" gdf-obfuscated-mailto=3D"OkSpVUdUtosJ">vlad....@mail.ru</a>&gt;=
:
<br>&gt;
<br>&gt; =D0=BF=D1=8F=D1=82=D0=BD=D0=B8=D1=86=D0=B0, 11 =D1=8F=D0=BD=D0=B2=
=D0=B0=D1=80=D1=8F 2013 =D0=B3., 20:24:30 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 Scott Prager
<br>&gt; =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:
<br>&gt;&gt; I think this is equivalent:
<br>&gt;&gt;
<br>&gt;&gt; <a href=3D"http://en.cppreference.com/w/cpp/algorithm/partitio=
n_copy" target=3D"_blank">http://en.cppreference.com/w/<wbr>cpp/algorithm/p=
artition_copy</a>
<br>&gt;&gt;
<br>[..]
<br>&gt;
<br>&gt; Thanks. I did not even know that such algorithm already exists in =
the
<br>&gt; standard library. :) &nbsp;It seems that it was included only in C=
++ 11.
<br>
<br>Yes, that is correct, it was added by acceptance of:
<br>
<br><a href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n266=
6.pdf" target=3D"_blank">http://www.open-std.org/jtc1/<wbr>sc22/wg21/docs/p=
apers/2008/<wbr>n2666.pdf</a>
<br>
<br>- Daniel
<br></blockquote><div>&nbsp;</div><div>&nbsp;</div><div>Well, there is no p=
roblem. &nbsp; In this case the thread can be renamed as </div><div>&nbsp;<=
/div><div>"New algorithm partition_copy".:)</div><div>&nbsp;</div><div>Let =
consider a simple task: split a sequence of integers into two sequences.The=
 first one shall contain only positive numbers and the second one shall con=
tain only negative numbers. This simple task can not be done by means of th=
e current algorithm std::partition_copy because it is unknown how to exclud=
e elements of the original sequence that are equal to zero. So the possibil=
ities of the current algorithm std::partition_copy is very restrictive.</di=
v><div>&nbsp;</div><div>I&nbsp;am suggesting to append this algorithm with&=
nbsp;a new modification which&nbsp;is more flexible and&nbsp;will allow to =
do more complex task.&nbsp; Here is its definition</div><div><font size=3D"=
2" face=3D"Consolas"><font size=3D"2" face=3D"Consolas"></font></font>&nbsp=
;</div><div><font size=3D"2" face=3D"Consolas">template &lt;class InputIter=
ator, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; class Outp=
utIterator1, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cla=
ss OutputIterator2,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; class UnaryPredicate1,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp; class UnaryPredicate2&gt;<br>std::pair&lt;OutputIterator1, OutputI=
terator2&gt; <br>partition_copy( InputIterator first, InputIterator last,<b=
r>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp; OutputIterator1 out1, OutputIterator2 out2,<br>&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp; UnaryPredicate1 unary_predicate1,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UnaryPredic=
ate2 unary_predicate2 )<br>{<br>&nbsp;for ( ; first !=3D last; ++first )<br=
>&nbsp;{<br>&nbsp;&nbsp;if ( unary_predicate1( *first ) ) *out1++ =3D *firs=
t;<br>&nbsp;&nbsp;if ( unary_predicate2( *first ) ) *out2++ =3D *first;<br>=
&nbsp;}</font></div><div><font size=3D"2" face=3D"Consolas">&nbsp;return ( =
std::make_pair( out1, out2 ) );<br>}<br></font></div><font size=3D"2" face=
=3D"Consolas"><p>Take into account that instead of&nbsp;statement</p><p>&nb=
sp;&nbsp;else if ( unary_predicate2( *first ) ) *out2++ =3D *first;<br></p>=
<p>there is </p><p><font size=3D"2">&nbsp; if ( unary_predicate2( *first ) =
) *out2++ =3D *first;</font><br></p><p>This will allow to place an element =
of the original sequence in two result sequences simultaneously.</p><p>In f=
act this algorithm includes two algorithms std::copy_if&nbsp;that deal with=
 the same original sequence. But it is more effective than to apply std::co=
py_if two times sequentially.</p></font></blockquote><div><br></div>This fe=
els wrong to me. &nbsp; [ How's that for a deep technical argument?&nbsp;&n=
bsp;;-)&nbsp;]</div><div><br></div><div>Two predicates, two outputs? And th=
e ones that aren't matched aren't copied at all?</div><div><span class=3D"A=
pple-tab-span" style=3D"white-space:pre"> </span>Those seem like arbitrary =
decisions.</div><div><br></div><div>If I were proposing something like this=
, I might suggest a collection of predicates and a (identically sized) coll=
ection of output iterators.</div><div>[ Warning - uncompiled code ]</div><d=
iv><br></div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre">=
 </span>template &lt;typename InputIterator, typename Predicates, typename =
Outputs&gt;</div><div><span class=3D"Apple-tab-span" style=3D"white-space:p=
re"> </span>Outputs partition_copy (&nbsp;InputIterator first, InputIterato=
r last, Predicates p, Outputs o )</div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre"> </span>{</div><span class=3D"Apple-tab-span" sty=
le=3D"white-space:pre">  </span>for ( ; first !=3D last; ++first )&nbsp;{<b=
r><span class=3D"Apple-tab-span" style=3D"white-space:pre">   </span>auto p=
i =3D p.begin ();<div><span class=3D"Apple-tab-span" style=3D"white-space:p=
re">   </span>auto oi =3D o.begin ();</div><div>&nbsp; &nbsp; &nbsp; &nbsp;=
 <span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>&nbsp; &n=
bsp; &nbsp; &nbsp; for ( ; pi !=3D p.end (); ++pi, ++oi )</div><div><span c=
lass=3D"Apple-tab-span" style=3D"white-space:pre">    </span>if ((*pi) (*fi=
rst)) {</div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre">=
     </span>**oi =3D *first;</div><div><span class=3D"Apple-tab-span" style=
=3D"white-space:pre">     </span>*oi++;</div><div><span class=3D"Apple-tab-=
span" style=3D"white-space:pre">     </span>break;</div><div><span class=3D=
"Apple-tab-span" style=3D"white-space:pre">     </span>}</div><div><span cl=
ass=3D"Apple-tab-span" style=3D"white-space:pre">  </span>return o;</div><d=
iv><span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>}<br><d=
iv><br></div><div>If you want to copy the elements that don't match somewhe=
re, put a predicate that always returns true at the end of the list.</div><=
div><br></div><div>There's a similar algorithm that copies the values to _e=
ach_ output sequence where the predicates match (just remove the "break" fr=
om the code)</div><div><br></div><div apple-content-edited=3D"true">
<span class=3D"Apple-style-span" style=3D"border-collapse: separate; border=
-spacing: 0px; ">-- Marshall<br><br>Marshall Clow &nbsp; &nbsp; Idio Softwa=
re &nbsp; &lt;<a href=3D"mailto:mclow.lists@gmail.com">mailto:mclow.lists@g=
mail.com</a>&gt;<br><br>A.D. 1517: Martin Luther nails his 95 Theses to the=
 church door and is promptly moderated down to (-1, Flamebait).<br>&nbsp;&n=
bsp; &nbsp; &nbsp; &nbsp;-- Yu Suzuki</span>

</div>
<br></div></body></html>

<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/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
&nbsp;<br />
&nbsp;<br />

--Apple-Mail=_4D60ED7E-182A-4EE6-AF68-BBD7998B1BCE--

.


Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Tue, 19 Feb 2013 10:48:52 -0800 (PST)
Raw View
------=_Part_847_24471221.1361299732664
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable


On Tuesday, February 19, 2013 9:08:23 PM UTC+4, Marshall wrote:
>
> On Feb 19, 2013, at 2:59 AM, Vlad from Moscow <vlad....@mail.ru<javascrip=
t:>>=20
> wrote:
>
> On Friday, January 11, 2013 8:43:12 PM UTC+4, Daniel Kr=C3=BCgler wrote:
>>
>> 2013/1/11 Vlad from Moscow <vlad....@mail.ru>:=20
>> >=20
>> > =D0=BF=D1=8F=D1=82=D0=BD=D0=B8=D1=86=D0=B0, 11 =D1=8F=D0=BD=D0=B2=D0=
=B0=D1=80=D1=8F 2013 =D0=B3., 20:24:30 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 Scott Prager=20
>> > =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:=20
>> >> I think this is equivalent:=20
>> >>=20
>> >> http://en.cppreference.com/w/cpp/algorithm/partition_copy=20
>> >>=20
>> [..]=20
>> >=20
>> > Thanks. I did not even know that such algorithm already exists in the=
=20
>> > standard library. :)  It seems that it was included only in C++ 11.=20
>>
>> Yes, that is correct, it was added by acceptance of:=20
>>
>> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2666.pdf=20
>>
>> - Daniel=20
>>
> =20
> =20
> Well, there is no problem.   In this case the thread can be renamed as=20
> =20
> "New algorithm partition_copy".:)
> =20
> Let consider a simple task: split a sequence of integers into two=20
> sequences.The first one shall contain only positive numbers and the secon=
d=20
> one shall contain only negative numbers. This simple task can not be done=
=20
> by means of the current algorithm std::partition_copy because it is unkno=
wn=20
> how to exclude elements of the original sequence that are equal to zero. =
So=20
> the possibilities of the current algorithm std::partition_copy is very=20
> restrictive.
> =20
> I am suggesting to append this algorithm with a new modification which is=
=20
> more flexible and will allow to do more complex task.  Here is its=20
> definition
> =20
> template <class InputIterator,=20
>           class OutputIterator1,=20
>           class OutputIterator2,
>           class UnaryPredicate1,
>           class UnaryPredicate2>
> std::pair<OutputIterator1, OutputIterator2>=20
> partition_copy( InputIterator first, InputIterator last,
>                 OutputIterator1 out1, OutputIterator2 out2,
>                 UnaryPredicate1 unary_predicate1,
>                 UnaryPredicate2 unary_predicate2 )
> {
>  for ( ; first !=3D last; ++first )
>  {
>   if ( unary_predicate1( *first ) ) *out1++ =3D *first;
>   if ( unary_predicate2( *first ) ) *out2++ =3D *first;
>  }
>  return ( std::make_pair( out1, out2 ) );
> }
>
> Take into account that instead of statement
>
>   else if ( unary_predicate2( *first ) ) *out2++ =3D *first;
>
> there is=20
>
>   if ( unary_predicate2( *first ) ) *out2++ =3D *first;
>
> This will allow to place an element of the original sequence in two resul=
t=20
> sequences simultaneously.
>
> In fact this algorithm includes two algorithms std::copy_if that deal wit=
h=20
> the same original sequence. But it is more effective than to apply=20
> std::copy_if two times sequentially.
>
>
> This feels wrong to me.   [ How's that for a deep technical=20
> argument?  ;-) ]
>
> Two predicates, two outputs? And the ones that aren't matched aren't=20
> copied at all?
> Those seem like arbitrary decisions.
>
> If I were proposing something like this, I might suggest a collection of=
=20
> predicates and a (identically sized) collection of output iterators.
> [ Warning - uncompiled code ]
>
> template <typename InputIterator, typename Predicates, typename Outputs>
> Outputs partition_copy ( InputIterator first, InputIterator last,=20
> Predicates p, Outputs o )
> {
> for ( ; first !=3D last; ++first ) {
> auto pi =3D p.begin ();
> auto oi =3D o.begin ();
>                 for ( ; pi !=3D p.end (); ++pi, ++oi )
> if ((*pi) (*first)) {
> **oi =3D *first;
> *oi++;
> break;
> }
> return o;
> }
>
> If you want to copy the elements that don't match somewhere, put a=20
> predicate that always returns true at the end of the list.
>
> There's a similar algorithm that copies the values to _each_ output=20
> sequence where the predicates match (just remove the "break" from the cod=
e)
>
> -- Marshall
>
> Marshall Clow     Idio Software   <mailto:mc...@gmail.com <javascript:>>
>
> A.D. 1517: Martin Luther nails his 95 Theses to the church door and is=20
> promptly moderated down to (-1, Flamebait).
>         -- Yu Suzuki=20
>
> =20
=20
Yes, two outputs and two predicates.  And the ones that aren't matched=20
aren't copied at all. It is the semantic of this new algorithm that=20
corresponds to the symantic of std::copy_if. If you want to copy all=20
ekements of the original sequence either in the first sequence or in the=20
second sequence you can use the current algorithm std::partition_copy,
In fact these two algorithm, existent one and the new< correspond to two=20
algorithms std::copy and std:copy_if, The current algorithm corresponds to=
=20
std::copt (all elements are copied) and the new one corresponds to=20
std::copy_if (only selected elements are copied).

--=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/?hl=3Den.



------=_Part_847_24471221.1361299732664
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<br>On Tuesday, February 19, 2013 9:08:23 PM UTC+4, Marshall wrote:<blockqu=
ote style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-colo=
r: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;" c=
lass=3D"gmail_quote"><div style=3D"word-wrap: break-word;"><div><div>On Feb=
 19, 2013, at 2:59 AM, Vlad from Moscow &lt;<a href=3D"javascript:" target=
=3D"_blank" gdf-obfuscated-mailto=3D"9FoKb8k6-fYJ">vlad....@mail.ru</a>&gt;=
 wrote:</div><blockquote type=3D"cite">On Friday, January 11, 2013 8:43:12 =
PM UTC+4, Daniel Kr=C3=BCgler wrote:<blockquote style=3D"margin: 0px 0px 0p=
x 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-l=
eft-width: 1px; border-left-style: solid;" class=3D"gmail_quote">2013/1/11 =
Vlad from Moscow &lt;<a>vlad....@mail.ru</a>&gt;:
<br>&gt;
<br>&gt; =D0=BF=D1=8F=D1=82=D0=BD=D0=B8=D1=86=D0=B0, 11 =D1=8F=D0=BD=D0=B2=
=D0=B0=D1=80=D1=8F 2013 =D0=B3., 20:24:30 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 Scott Prager
<br>&gt; =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:
<br>&gt;&gt; I think this is equivalent:
<br>&gt;&gt;
<br>&gt;&gt; <a href=3D"http://en.cppreference.com/w/cpp/algorithm/partitio=
n_copy" target=3D"_blank">http://en.cppreference.com/w/<wbr>cpp/algorithm/p=
artition_copy</a>
<br>&gt;&gt;
<br>[..]
<br>&gt;
<br>&gt; Thanks. I did not even know that such algorithm already exists in =
the
<br>&gt; standard library. :) &nbsp;It seems that it was included only in C=
++ 11.
<br>
<br>Yes, that is correct, it was added by acceptance of:
<br>
<br><a href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n266=
6.pdf" target=3D"_blank">http://www.open-std.org/jtc1/<wbr>sc22/wg21/docs/p=
apers/2008/<wbr>n2666.pdf</a>
<br>
<br>- Daniel
<br></blockquote><div>&nbsp;</div><div>&nbsp;</div><div>Well, there is no p=
roblem. &nbsp; In this case the thread can be renamed as </div><div>&nbsp;<=
/div><div>"New algorithm partition_copy".:)</div><div>&nbsp;</div><div>Let =
consider a simple task: split a sequence of integers into two sequences.The=
 first one shall contain only positive numbers and the second one shall con=
tain only negative numbers. This simple task can not be done by means of th=
e current algorithm std::partition_copy because it is unknown how to exclud=
e elements of the original sequence that are equal to zero. So the possibil=
ities of the current algorithm std::partition_copy is very restrictive.</di=
v><div>&nbsp;</div><div>I&nbsp;am suggesting to append this algorithm with&=
nbsp;a new modification which&nbsp;is more flexible and&nbsp;will allow to =
do more complex task.&nbsp; Here is its definition</div><div><font size=3D"=
2" face=3D"Consolas"><font size=3D"2" face=3D"Consolas"></font></font>&nbsp=
;</div><div><font size=3D"2" face=3D"Consolas">template &lt;class InputIter=
ator, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; class Outp=
utIterator1, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cla=
ss OutputIterator2,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; class UnaryPredicate1,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp; class UnaryPredicate2&gt;<br>std::pair&lt;OutputIterator1, OutputI=
terator2&gt; <br>partition_copy( InputIterator first, InputIterator last,<b=
r>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp; OutputIterator1 out1, OutputIterator2 out2,<br>&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp; UnaryPredicate1 unary_predicate1,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<wbr>UnaryP=
redicate2 unary_predicate2 )<br>{<br>&nbsp;for ( ; first !=3D last; ++first=
 )<br>&nbsp;{<br>&nbsp;&nbsp;if ( unary_predicate1( *first ) ) *out1++ =3D =
*first;<br>&nbsp;&nbsp;if ( unary_predicate2( *first ) ) *out2++ =3D *first=
;<br>&nbsp;}</font></div><div><font size=3D"2" face=3D"Consolas">&nbsp;retu=
rn ( std::make_pair( out1, out2 ) );<br>}<br></font></div><font size=3D"2" =
face=3D"Consolas"><p>Take into account that instead of&nbsp;statement</p><p=
>&nbsp;&nbsp;else if ( unary_predicate2( *first ) ) *out2++ =3D *first;<br>=
</p><p>there is </p><p><font size=3D"2">&nbsp; if ( unary_predicate2( *firs=
t ) ) *out2++ =3D *first;</font><br></p><p>This will allow to place an elem=
ent of the original sequence in two result sequences simultaneously.</p><p>=
In fact this algorithm includes two algorithms std::copy_if&nbsp;that deal =
with the same original sequence. But it is more effective than to apply std=
::copy_if two times sequentially.</p></font></blockquote><div><br></div>Thi=
s feels wrong to me. &nbsp; [ How's that for a deep technical argument?&nbs=
p;&nbsp;;-)&nbsp;]</div><div><br></div><div>Two predicates, two outputs? An=
d the ones that aren't matched aren't copied at all?</div><div><span style=
=3D"white-space: pre;"> </span>Those seem like arbitrary decisions.</div><d=
iv><br></div><div>If I were proposing something like this, I might suggest =
a collection of predicates and a (identically sized) collection of output i=
terators.</div><div>[ Warning - uncompiled code ]</div><div><br></div><div>=
<span style=3D"white-space: pre;"> </span>template &lt;typename InputIterat=
or, typename Predicates, typename Outputs&gt;</div><div><span style=3D"whit=
e-space: pre;"> </span>Outputs partition_copy (&nbsp;InputIterator first, I=
nputIterator last, Predicates p, Outputs o )</div><div><span style=3D"white=
-space: pre;"> </span>{</div><span style=3D"white-space: pre;">  </span>for=
 ( ; first !=3D last; ++first )&nbsp;{<br><span style=3D"white-space: pre;"=
>   </span>auto pi =3D p.begin ();<div><span style=3D"white-space: pre;">  =
 </span>auto oi =3D o.begin ();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; <span=
 style=3D"white-space: pre;"> </span>&nbsp; &nbsp; &nbsp; &nbsp; for ( ; pi=
 !=3D p.end (); ++pi, ++oi )</div><div><span style=3D"white-space: pre;">  =
  </span>if ((*pi) (*first)) {</div><div><span style=3D"white-space: pre;">=
     </span>**oi =3D *first;</div><div><span style=3D"white-space: pre;">  =
   </span>*oi++;</div><div><span style=3D"white-space: pre;">     </span>br=
eak;</div><div><span style=3D"white-space: pre;">     </span>}</div><div><s=
pan style=3D"white-space: pre;">  </span>return o;</div><div><span style=3D=
"white-space: pre;"> </span>}<br><div><br></div><div>If you want to copy th=
e elements that don't match somewhere, put a predicate that always returns =
true at the end of the list.</div><div><br></div><div>There's a similar alg=
orithm that copies the values to _each_ output sequence where the predicate=
s match (just remove the "break" from the code)</div><div><br></div><div>
<span style=3D"border-collapse: separate; border-spacing: 0px;">-- Marshall=
<br><br>Marshall Clow &nbsp; &nbsp; Idio Software &nbsp; &lt;<a href=3D"jav=
ascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"9FoKb8k6-fYJ">mailto:m=
c...@gmail.com</a>&gt;<br><br>A.D. 1517: Martin Luther nails his 95 Theses =
to the church door and is promptly moderated down to (-1, Flamebait).<br>&n=
bsp;&nbsp; &nbsp; &nbsp; &nbsp;-- Yu Suzuki</span>

</div>
<br></div></div></blockquote><div>&nbsp;</div><div>&nbsp;</div><div>Yes, tw=
o outputs and two predicates.&nbsp;&nbsp;And the ones that aren't matched a=
ren't copied at all. It is the semantic of this new algorithm that correspo=
nds to the symantic of std::copy_if. If you want to copy all ekements of th=
e original sequence either in the first sequence or in the second sequence =
you can use the current algorithm std::partition_copy,</div><div>In fact th=
ese two algorithm, existent one and the new&lt; correspond to two algorithm=
s std::copy and std:copy_if, The current algorithm corresponds to std::copt=
 (all elements are copied) and the new one corresponds to std::copy_if (onl=
y selected elements are copied).</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/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_847_24471221.1361299732664--

.


Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Tue, 19 Feb 2013 11:03:59 -0800 (PST)
Raw View
------=_Part_58_26740941.1361300639202
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable


On Tuesday, February 19, 2013 10:48:52 PM UTC+4, Vlad from Moscow wrote:
>
>
> On Tuesday, February 19, 2013 9:08:23 PM UTC+4, Marshall wrote:
>>
>> On Feb 19, 2013, at 2:59 AM, Vlad from Moscow <vlad....@mail.ru> wrote:
>>
>> On Friday, January 11, 2013 8:43:12 PM UTC+4, Daniel Kr=C3=BCgler wrote:
>>>
>>> 2013/1/11 Vlad from Moscow <vlad....@mail.ru>:=20
>>> >=20
>>> > =D0=BF=D1=8F=D1=82=D0=BD=D0=B8=D1=86=D0=B0, 11 =D1=8F=D0=BD=D0=B2=D0=
=B0=D1=80=D1=8F 2013 =D0=B3., 20:24:30 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 Scott Prager=20
>>> > =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:=20
>>> >> I think this is equivalent:=20
>>> >>=20
>>> >> http://en.cppreference.com/w/cpp/algorithm/partition_copy=20
>>> >>=20
>>> [..]=20
>>> >=20
>>> > Thanks. I did not even know that such algorithm already exists in the=
=20
>>> > standard library. :)  It seems that it was included only in C++ 11.=
=20
>>>
>>> Yes, that is correct, it was added by acceptance of:=20
>>>
>>> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2666.pdf=20
>>>
>>> - Daniel=20
>>>
>> =20
>> =20
>> Well, there is no problem.   In this case the thread can be renamed as=
=20
>> =20
>> "New algorithm partition_copy".:)
>> =20
>> Let consider a simple task: split a sequence of integers into two=20
>> sequences.The first one shall contain only positive numbers and the seco=
nd=20
>> one shall contain only negative numbers. This simple task can not be don=
e=20
>> by means of the current algorithm std::partition_copy because it is unkn=
own=20
>> how to exclude elements of the original sequence that are equal to zero.=
 So=20
>> the possibilities of the current algorithm std::partition_copy is very=
=20
>> restrictive.
>> =20
>> I am suggesting to append this algorithm with a new modification which i=
s=20
>> more flexible and will allow to do more complex task.  Here is its=20
>> definition
>> =20
>> template <class InputIterator,=20
>>           class OutputIterator1,=20
>>           class OutputIterator2,
>>           class UnaryPredicate1,
>>           class UnaryPredicate2>
>> std::pair<OutputIterator1, OutputIterator2>=20
>> partition_copy( InputIterator first, InputIterator last,
>>                 OutputIterator1 out1, OutputIterator2 out2,
>>                 UnaryPredicate1 unary_predicate1,
>>                 UnaryPredicate2 unary_predicate2 )
>> {
>>  for ( ; first !=3D last; ++first )
>>  {
>>   if ( unary_predicate1( *first ) ) *out1++ =3D *first;
>>   if ( unary_predicate2( *first ) ) *out2++ =3D *first;
>>  }
>>  return ( std::make_pair( out1, out2 ) );
>> }
>>
>> Take into account that instead of statement
>>
>>   else if ( unary_predicate2( *first ) ) *out2++ =3D *first;
>>
>> there is=20
>>
>>   if ( unary_predicate2( *first ) ) *out2++ =3D *first;
>>
>> This will allow to place an element of the original sequence in two=20
>> result sequences simultaneously.
>>
>> In fact this algorithm includes two algorithms std::copy_if that deal=20
>> with the same original sequence. But it is more effective than to apply=
=20
>> std::copy_if two times sequentially.
>>
>>
>> This feels wrong to me.   [ How's that for a deep technical=20
>> argument?  ;-) ]
>>
>> Two predicates, two outputs? And the ones that aren't matched aren't=20
>> copied at all?
>> Those seem like arbitrary decisions.
>>
>> If I were proposing something like this, I might suggest a collection of=
=20
>> predicates and a (identically sized) collection of output iterators.
>> [ Warning - uncompiled code ]
>>
>> template <typename InputIterator, typename Predicates, typename Outputs>
>> Outputs partition_copy ( InputIterator first, InputIterator last,=20
>> Predicates p, Outputs o )
>> {
>> for ( ; first !=3D last; ++first ) {
>> auto pi =3D p.begin ();
>> auto oi =3D o.begin ();
>>                 for ( ; pi !=3D p.end (); ++pi, ++oi )
>> if ((*pi) (*first)) {
>> **oi =3D *first;
>> *oi++;
>> break;
>> }
>> return o;
>> }
>>
>> If you want to copy the elements that don't match somewhere, put a=20
>> predicate that always returns true at the end of the list.
>>
>> There's a similar algorithm that copies the values to _each_ output=20
>> sequence where the predicates match (just remove the "break" from the co=
de)
>>
>> -- Marshall
>>
>> Marshall Clow     Idio Software   <mailto:mc...@gmail.com>
>>
>> A.D. 1517: Martin Luther nails his 95 Theses to the church door and is=
=20
>> promptly moderated down to (-1, Flamebait).
>>         -- Yu Suzuki=20
>>
>> =20
> =20
> Yes, two outputs and two predicates.  And the ones that aren't matched=20
> aren't copied at all. It is the semantic of this new algorithm that=20
> corresponds to the symantic of std::copy_if. If you want to copy all=20
> ekements of the original sequence either in the first sequence or in the=
=20
> second sequence you can use the current algorithm std::partition_copy,
> In fact these two algorithm, existent one and the new< correspond to two=
=20
> algorithms std::copy and std:copy_if, The current algorithm corresponds t=
o=20
> std::copt (all elements are copied) and the new one corresponds to=20
> std::copy_if (only selected elements are copied).
> =20
>
=20
=20
By the way your idea to use a set of output iterators and a set of=20
predicates can be realozed with std::tuple. So this algorithm can be the=20
first that will use std::tuple. Why not?=20

--=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/?hl=3Den.



------=_Part_58_26740941.1361300639202
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<br>On Tuesday, February 19, 2013 10:48:52 PM UTC+4, Vlad from Moscow wrote=
:<blockquote style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-=
left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: =
solid;" class=3D"gmail_quote"><br>On Tuesday, February 19, 2013 9:08:23 PM =
UTC+4, Marshall wrote:<blockquote style=3D"margin: 0px 0px 0px 0.8ex; paddi=
ng-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px=
; border-left-style: solid;" class=3D"gmail_quote"><div style=3D"word-wrap:=
 break-word;"><div><div>On Feb 19, 2013, at 2:59 AM, Vlad from Moscow &lt;<=
a>vlad....@mail.ru</a>&gt; wrote:</div><blockquote type=3D"cite">On Friday,=
 January 11, 2013 8:43:12 PM UTC+4, Daniel Kr=C3=BCgler wrote:<blockquote s=
tyle=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rg=
b(204, 204, 204); border-left-width: 1px; border-left-style: solid;" class=
=3D"gmail_quote">2013/1/11 Vlad from Moscow &lt;<a>vlad....@mail.ru</a>&gt;=
:
<br>&gt;
<br>&gt; =D0=BF=D1=8F=D1=82=D0=BD=D0=B8=D1=86=D0=B0, 11 =D1=8F=D0=BD=D0=B2=
=D0=B0=D1=80=D1=8F 2013 =D0=B3., 20:24:30 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 Scott Prager
<br>&gt; =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:
<br>&gt;&gt; I think this is equivalent:
<br>&gt;&gt;
<br>&gt;&gt; <a href=3D"http://en.cppreference.com/w/cpp/algorithm/partitio=
n_copy" target=3D"_blank">http://en.cppreference.com/w/<wbr>cpp/algorithm/p=
artition_copy</a>
<br>&gt;&gt;
<br>[..]
<br>&gt;
<br>&gt; Thanks. I did not even know that such algorithm already exists in =
the
<br>&gt; standard library. :) &nbsp;It seems that it was included only in C=
++ 11.
<br>
<br>Yes, that is correct, it was added by acceptance of:
<br>
<br><a href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n266=
6.pdf" target=3D"_blank">http://www.open-std.org/jtc1/<wbr>sc22/wg21/docs/p=
apers/2008/<wbr>n2666.pdf</a>
<br>
<br>- Daniel
<br></blockquote><div>&nbsp;</div><div>&nbsp;</div><div>Well, there is no p=
roblem. &nbsp; In this case the thread can be renamed as </div><div>&nbsp;<=
/div><div>"New algorithm partition_copy".:)</div><div>&nbsp;</div><div>Let =
consider a simple task: split a sequence of integers into two sequences.The=
 first one shall contain only positive numbers and the second one shall con=
tain only negative numbers. This simple task can not be done by means of th=
e current algorithm std::partition_copy because it is unknown how to exclud=
e elements of the original sequence that are equal to zero. So the possibil=
ities of the current algorithm std::partition_copy is very restrictive.</di=
v><div>&nbsp;</div><div>I&nbsp;am suggesting to append this algorithm with&=
nbsp;a new modification which&nbsp;is more flexible and&nbsp;will allow to =
do more complex task.&nbsp; Here is its definition</div><div><font size=3D"=
2" face=3D"Consolas"><font size=3D"2" face=3D"Consolas"></font></font>&nbsp=
;</div><div><font size=3D"2" face=3D"Consolas">template &lt;class InputIter=
ator, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; class Outp=
utIterator1, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cla=
ss OutputIterator2,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; class UnaryPredicate1,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp; class UnaryPredicate2&gt;<br>std::pair&lt;OutputIterator1, OutputI=
terator2&gt; <br>partition_copy( InputIterator first, InputIterator last,<b=
r>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp; OutputIterator1 out1, OutputIterator2 out2,<br>&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp; UnaryPredicate1 unary_predicate1,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<wbr>UnaryP=
redicate2 unary_predicate2 )<br>{<br>&nbsp;for ( ; first !=3D last; ++first=
 )<br>&nbsp;{<br>&nbsp;&nbsp;if ( unary_predicate1( *first ) ) *out1++ =3D =
*first;<br>&nbsp;&nbsp;if ( unary_predicate2( *first ) ) *out2++ =3D *first=
;<br>&nbsp;}</font></div><div><font size=3D"2" face=3D"Consolas">&nbsp;retu=
rn ( std::make_pair( out1, out2 ) );<br>}<br></font></div><font size=3D"2" =
face=3D"Consolas"><p>Take into account that instead of&nbsp;statement</p><p=
>&nbsp;&nbsp;else if ( unary_predicate2( *first ) ) *out2++ =3D *first;<br>=
</p><p>there is </p><p><font size=3D"2">&nbsp; if ( unary_predicate2( *firs=
t ) ) *out2++ =3D *first;</font><br></p><p>This will allow to place an elem=
ent of the original sequence in two result sequences simultaneously.</p><p>=
In fact this algorithm includes two algorithms std::copy_if&nbsp;that deal =
with the same original sequence. But it is more effective than to apply std=
::copy_if two times sequentially.</p></font></blockquote><div><br></div>Thi=
s feels wrong to me. &nbsp; [ How's that for a deep technical argument?&nbs=
p;&nbsp;;-)&nbsp;]</div><div><br></div><div>Two predicates, two outputs? An=
d the ones that aren't matched aren't copied at all?</div><div><span style=
=3D"white-space: pre;"> </span>Those seem like arbitrary decisions.</div><d=
iv><br></div><div>If I were proposing something like this, I might suggest =
a collection of predicates and a (identically sized) collection of output i=
terators.</div><div>[ Warning - uncompiled code ]</div><div><br></div><div>=
<span style=3D"white-space: pre;"> </span>template &lt;typename InputIterat=
or, typename Predicates, typename Outputs&gt;</div><div><span style=3D"whit=
e-space: pre;"> </span>Outputs partition_copy (&nbsp;InputIterator first, I=
nputIterator last, Predicates p, Outputs o )</div><div><span style=3D"white=
-space: pre;"> </span>{</div><span style=3D"white-space: pre;">  </span>for=
 ( ; first !=3D last; ++first )&nbsp;{<br><span style=3D"white-space: pre;"=
>   </span>auto pi =3D p.begin ();<div><span style=3D"white-space: pre;">  =
 </span>auto oi =3D o.begin ();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; <span=
 style=3D"white-space: pre;"> </span>&nbsp; &nbsp; &nbsp; &nbsp; for ( ; pi=
 !=3D p.end (); ++pi, ++oi )</div><div><span style=3D"white-space: pre;">  =
  </span>if ((*pi) (*first)) {</div><div><span style=3D"white-space: pre;">=
     </span>**oi =3D *first;</div><div><span style=3D"white-space: pre;">  =
   </span>*oi++;</div><div><span style=3D"white-space: pre;">     </span>br=
eak;</div><div><span style=3D"white-space: pre;">     </span>}</div><div><s=
pan style=3D"white-space: pre;">  </span>return o;</div><div><span style=3D=
"white-space: pre;"> </span>}<br><div><br></div><div>If you want to copy th=
e elements that don't match somewhere, put a predicate that always returns =
true at the end of the list.</div><div><br></div><div>There's a similar alg=
orithm that copies the values to _each_ output sequence where the predicate=
s match (just remove the "break" from the code)</div><div><br></div><div>
<span style=3D"border-collapse: separate; border-spacing: 0px;">-- Marshall=
<br><br>Marshall Clow &nbsp; &nbsp; Idio Software &nbsp; &lt;<a>mailto:mc..=
..@gmail.com</a>&gt;<br><br>A.D. 1517: Martin Luther nails his 95 Theses to =
the church door and is promptly moderated down to (-1, Flamebait).<br>&nbsp=
;&nbsp; &nbsp; &nbsp; &nbsp;-- Yu Suzuki</span>

</div>
<br></div></div></blockquote><div>&nbsp;</div><div>&nbsp;</div><div>Yes, tw=
o outputs and two predicates.&nbsp;&nbsp;And the ones that aren't matched a=
ren't copied at all. It is the semantic of this new algorithm that correspo=
nds to the symantic of std::copy_if. If you want to copy all ekements of th=
e original sequence either in the first sequence or in the second sequence =
you can use the current algorithm std::partition_copy,</div><div>In fact th=
ese two algorithm, existent one and the new&lt; correspond to two algorithm=
s std::copy and std:copy_if, The current algorithm corresponds to std::copt=
 (all elements are copied) and the new one corresponds to std::copy_if (onl=
y selected elements are copied).</div><div>&nbsp;</div></blockquote><div>&n=
bsp;</div><div>&nbsp;</div><div>By the way your idea to use a set of output=
 iterators and a set of predicates can be realozed with std::tuple. So this=
 algorithm can be&nbsp;the first that will use std::tuple. Why not?&nbsp;</=
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/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_58_26740941.1361300639202--

.


Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Wed, 20 Feb 2013 05:49:42 -0800 (PST)
Raw View
------=_Part_1001_13251.1361368182086
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



=D0=B2=D1=82=D0=BE=D1=80=D0=BD=D0=B8=D0=BA, 19 =D1=84=D0=B5=D0=B2=D1=80=D0=
=B0=D0=BB=D1=8F 2013 =D0=B3., 22:03:59 UTC+3 =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:
>
>
> On Tuesday, February 19, 2013 10:48:52 PM UTC+4, Vlad from Moscow wrote:
>>
>>
>> On Tuesday, February 19, 2013 9:08:23 PM UTC+4, Marshall wrote:
>>>
>>> On Feb 19, 2013, at 2:59 AM, Vlad from Moscow <vlad....@mail.ru> wrote:
>>>
>>> On Friday, January 11, 2013 8:43:12 PM UTC+4, Daniel Kr=C3=BCgler wrote=
:
>>>>
>>>> 2013/1/11 Vlad from Moscow <vlad....@mail.ru>:=20
>>>> >=20
>>>> > =D0=BF=D1=8F=D1=82=D0=BD=D0=B8=D1=86=D0=B0, 11 =D1=8F=D0=BD=D0=B2=D0=
=B0=D1=80=D1=8F 2013 =D0=B3., 20:24:30 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 Scott Prager=20
>>>> > =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:=20
>>>> >> I think this is equivalent:=20
>>>> >>=20
>>>> >> http://en.cppreference.com/w/cpp/algorithm/partition_copy=20
>>>> >>=20
>>>> [..]=20
>>>> >=20
>>>> > Thanks. I did not even know that such algorithm already exists in th=
e=20
>>>> > standard library. :)  It seems that it was included only in C++ 11.=
=20
>>>>
>>>> Yes, that is correct, it was added by acceptance of:=20
>>>>
>>>> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2666.pdf=20
>>>>
>>>> - Daniel=20
>>>>
>>> =20
>>> =20
>>> Well, there is no problem.   In this case the thread can be renamed as=
=20
>>> =20
>>> "New algorithm partition_copy".:)
>>> =20
>>> Let consider a simple task: split a sequence of integers into two=20
>>> sequences.The first one shall contain only positive numbers and the sec=
ond=20
>>> one shall contain only negative numbers. This simple task can not be do=
ne=20
>>> by means of the current algorithm std::partition_copy because it is unk=
nown=20
>>> how to exclude elements of the original sequence that are equal to zero=
.. So=20
>>> the possibilities of the current algorithm std::partition_copy is very=
=20
>>> restrictive.
>>> =20
>>> I am suggesting to append this algorithm with a new modification=20
>>> which is more flexible and will allow to do more complex task.  Here is=
 its=20
>>> definition
>>> =20
>>> template <class InputIterator,=20
>>>           class OutputIterator1,=20
>>>           class OutputIterator2,
>>>           class UnaryPredicate1,
>>>           class UnaryPredicate2>
>>> std::pair<OutputIterator1, OutputIterator2>=20
>>> partition_copy( InputIterator first, InputIterator last,
>>>                 OutputIterator1 out1, OutputIterator2 out2,
>>>                 UnaryPredicate1 unary_predicate1,
>>>                 UnaryPredicate2 unary_predicate2 )
>>> {
>>>  for ( ; first !=3D last; ++first )
>>>  {
>>>   if ( unary_predicate1( *first ) ) *out1++ =3D *first;
>>>   if ( unary_predicate2( *first ) ) *out2++ =3D *first;
>>>  }
>>>  return ( std::make_pair( out1, out2 ) );
>>> }
>>>
>>> Take into account that instead of statement
>>>
>>>   else if ( unary_predicate2( *first ) ) *out2++ =3D *first;
>>>
>>> there is=20
>>>
>>>   if ( unary_predicate2( *first ) ) *out2++ =3D *first;
>>>
>>> This will allow to place an element of the original sequence in two=20
>>> result sequences simultaneously.
>>>
>>> In fact this algorithm includes two algorithms std::copy_if that deal=
=20
>>> with the same original sequence. But it is more effective than to apply=
=20
>>> std::copy_if two times sequentially.
>>>
>>>
>>> This feels wrong to me.   [ How's that for a deep technical=20
>>> argument?  ;-) ]
>>>
>>> Two predicates, two outputs? And the ones that aren't matched aren't=20
>>> copied at all?
>>> Those seem like arbitrary decisions.
>>>
>>> If I were proposing something like this, I might suggest a collection o=
f=20
>>> predicates and a (identically sized) collection of output iterators.
>>> [ Warning - uncompiled code ]
>>>
>>> template <typename InputIterator, typename Predicates, typename Outputs=
>
>>> Outputs partition_copy ( InputIterator first, InputIterator last,=20
>>> Predicates p, Outputs o )
>>> {
>>> for ( ; first !=3D last; ++first ) {
>>> auto pi =3D p.begin ();
>>> auto oi =3D o.begin ();
>>>                 for ( ; pi !=3D p.end (); ++pi, ++oi )
>>> if ((*pi) (*first)) {
>>> **oi =3D *first;
>>> *oi++;
>>> break;
>>> }
>>> return o;
>>> }
>>>
>>> If you want to copy the elements that don't match somewhere, put a=20
>>> predicate that always returns true at the end of the list.
>>>
>>> There's a similar algorithm that copies the values to _each_ output=20
>>> sequence where the predicates match (just remove the "break" from the c=
ode)
>>>
>>> -- Marshall
>>>
>>> Marshall Clow     Idio Software   <mailto:mc...@gmail.com>
>>>
>>> A.D. 1517: Martin Luther nails his 95 Theses to the church door and is=
=20
>>> promptly moderated down to (-1, Flamebait).
>>>         -- Yu Suzuki=20
>>>
>>> =20
>> =20
>> Yes, two outputs and two predicates.  And the ones that aren't matched=
=20
>> aren't copied at all. It is the semantic of this new algorithm that=20
>> corresponds to the symantic of std::copy_if. If you want to copy all=20
>> ekements of the original sequence either in the first sequence or in the=
=20
>> second sequence you can use the current algorithm std::partition_copy,
>> In fact these two algorithm, existent one and the new< correspond to two=
=20
>> algorithms std::copy and std:copy_if, The current algorithm corresponds =
to=20
>> std::copt (all elements are copied) and the new one corresponds to=20
>> std::copy_if (only selected elements are copied).
>> =20
>>
> =20
> =20
> By the way your idea to use a set of output iterators and a set of=20
> predicates can be realozed with std::tuple. So this algorithm can be the=
=20
> first that will use std::tuple. Why not?=20
>

Something as

template <class InputIterator, class ... OutputIterators, class ... Predica=
tes>std::tuple<OutputIterators...> partition_copy( InputIterator first, Inp=
utIterator last,=20
                                               std::tuple<OutputIterators..=
..> outs,
                                               std::tuple<Predicates...> pr=
edicates );

--=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/?hl=3Den.



------=_Part_1001_13251.1361368182086
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<br><br>=D0=B2=D1=82=D0=BE=D1=80=D0=BD=D0=B8=D0=BA, 19 =D1=84=D0=B5=D0=B2=
=D1=80=D0=B0=D0=BB=D1=8F 2013&nbsp;=D0=B3., 22:03:59 UTC+3 =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:<blockquote class=3D"gmail_quote=
" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding=
-left: 1ex;"><br>On Tuesday, February 19, 2013 10:48:52 PM UTC+4, Vlad from=
 Moscow wrote:<blockquote style=3D"margin:0px 0px 0px 0.8ex;padding-left:1e=
x;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-styl=
e:solid" class=3D"gmail_quote"><br>On Tuesday, February 19, 2013 9:08:23 PM=
 UTC+4, Marshall wrote:<blockquote 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" class=3D"gmail_quote"><div style=3D"word-wrap:break-word"=
><div><div>On Feb 19, 2013, at 2:59 AM, Vlad from Moscow &lt;<a>vlad....@ma=
il.ru</a>&gt; wrote:</div><blockquote type=3D"cite">On Friday, January 11, =
2013 8:43:12 PM UTC+4, Daniel Kr=C3=BCgler wrote:<blockquote style=3D"margi=
n:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);bor=
der-left-width:1px;border-left-style:solid" class=3D"gmail_quote">2013/1/11=
 Vlad from Moscow &lt;<a>vlad....@mail.ru</a>&gt;:
<br>&gt;
<br>&gt; =D0=BF=D1=8F=D1=82=D0=BD=D0=B8=D1=86=D0=B0, 11 =D1=8F=D0=BD=D0=B2=
=D0=B0=D1=80=D1=8F 2013 =D0=B3., 20:24:30 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 Scott Prager
<br>&gt; =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:
<br>&gt;&gt; I think this is equivalent:
<br>&gt;&gt;
<br>&gt;&gt; <a href=3D"http://en.cppreference.com/w/cpp/algorithm/partitio=
n_copy" target=3D"_blank">http://en.cppreference.com/w/<wbr>cpp/algorithm/p=
artition_copy</a>
<br>&gt;&gt;
<br>[..]
<br>&gt;
<br>&gt; Thanks. I did not even know that such algorithm already exists in =
the
<br>&gt; standard library. :) &nbsp;It seems that it was included only in C=
++ 11.
<br>
<br>Yes, that is correct, it was added by acceptance of:
<br>
<br><a href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n266=
6.pdf" target=3D"_blank">http://www.open-std.org/jtc1/<wbr>sc22/wg21/docs/p=
apers/2008/<wbr>n2666.pdf</a>
<br>
<br>- Daniel
<br></blockquote><div>&nbsp;</div><div>&nbsp;</div><div>Well, there is no p=
roblem. &nbsp; In this case the thread can be renamed as </div><div>&nbsp;<=
/div><div>"New algorithm partition_copy".:)</div><div>&nbsp;</div><div>Let =
consider a simple task: split a sequence of integers into two sequences.The=
 first one shall contain only positive numbers and the second one shall con=
tain only negative numbers. This simple task can not be done by means of th=
e current algorithm std::partition_copy because it is unknown how to exclud=
e elements of the original sequence that are equal to zero. So the possibil=
ities of the current algorithm std::partition_copy is very restrictive.</di=
v><div>&nbsp;</div><div>I&nbsp;am suggesting to append this algorithm with&=
nbsp;a new modification which&nbsp;is more flexible and&nbsp;will allow to =
do more complex task.&nbsp; Here is its definition</div><div><font size=3D"=
2" face=3D"Consolas"><font size=3D"2" face=3D"Consolas"></font></font>&nbsp=
;</div><div><font size=3D"2" face=3D"Consolas">template &lt;class InputIter=
ator, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; class Outp=
utIterator1, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cla=
ss OutputIterator2,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; class UnaryPredicate1,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp; class UnaryPredicate2&gt;<br>std::pair&lt;OutputIterator1, OutputI=
terator2&gt; <br>partition_copy( InputIterator first, InputIterator last,<b=
r>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp; OutputIterator1 out1, OutputIterator2 out2,<br>&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp; UnaryPredicate1 unary_predicate1,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<wbr>UnaryP=
redicate2 unary_predicate2 )<br>{<br>&nbsp;for ( ; first !=3D last; ++first=
 )<br>&nbsp;{<br>&nbsp;&nbsp;if ( unary_predicate1( *first ) ) *out1++ =3D =
*first;<br>&nbsp;&nbsp;if ( unary_predicate2( *first ) ) *out2++ =3D *first=
;<br>&nbsp;}</font></div><div><font size=3D"2" face=3D"Consolas">&nbsp;retu=
rn ( std::make_pair( out1, out2 ) );<br>}<br></font></div><font size=3D"2" =
face=3D"Consolas"><p>Take into account that instead of&nbsp;statement</p><p=
>&nbsp;&nbsp;else if ( unary_predicate2( *first ) ) *out2++ =3D *first;<br>=
</p><p>there is </p><p><font size=3D"2">&nbsp; if ( unary_predicate2( *firs=
t ) ) *out2++ =3D *first;</font><br></p><p>This will allow to place an elem=
ent of the original sequence in two result sequences simultaneously.</p><p>=
In fact this algorithm includes two algorithms std::copy_if&nbsp;that deal =
with the same original sequence. But it is more effective than to apply std=
::copy_if two times sequentially.</p></font></blockquote><div><br></div>Thi=
s feels wrong to me. &nbsp; [ How's that for a deep technical argument?&nbs=
p;&nbsp;;-)&nbsp;]</div><div><br></div><div>Two predicates, two outputs? An=
d the ones that aren't matched aren't copied at all?</div><div><span style=
=3D"white-space:pre"> </span>Those seem like arbitrary decisions.</div><div=
><br></div><div>If I were proposing something like this, I might suggest a =
collection of predicates and a (identically sized) collection of output ite=
rators.</div><div>[ Warning - uncompiled code ]</div><div><br></div><div><s=
pan style=3D"white-space:pre"> </span>template &lt;typename InputIterator, =
typename Predicates, typename Outputs&gt;</div><div><span style=3D"white-sp=
ace:pre"> </span>Outputs partition_copy (&nbsp;InputIterator first, InputIt=
erator last, Predicates p, Outputs o )</div><div><span style=3D"white-space=
:pre"> </span>{</div><span style=3D"white-space:pre">  </span>for ( ; first=
 !=3D last; ++first )&nbsp;{<br><span style=3D"white-space:pre">   </span>a=
uto pi =3D p.begin ();<div><span style=3D"white-space:pre">   </span>auto o=
i =3D o.begin ();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; <span style=3D"whit=
e-space:pre"> </span>&nbsp; &nbsp; &nbsp; &nbsp; for ( ; pi !=3D p.end (); =
++pi, ++oi )</div><div><span style=3D"white-space:pre">    </span>if ((*pi)=
 (*first)) {</div><div><span style=3D"white-space:pre">     </span>**oi =3D=
 *first;</div><div><span style=3D"white-space:pre">     </span>*oi++;</div>=
<div><span style=3D"white-space:pre">     </span>break;</div><div><span sty=
le=3D"white-space:pre">     </span>}</div><div><span style=3D"white-space:p=
re">  </span>return o;</div><div><span style=3D"white-space:pre"> </span>}<=
br><div><br></div><div>If you want to copy the elements that don't match so=
mewhere, put a predicate that always returns true at the end of the list.</=
div><div><br></div><div>There's a similar algorithm that copies the values =
to _each_ output sequence where the predicates match (just remove the "brea=
k" from the code)</div><div><br></div><div>
<span style=3D"border-collapse:separate;border-spacing:0px">-- Marshall<br>=
<br>Marshall Clow &nbsp; &nbsp; Idio Software &nbsp; &lt;<a>mailto:mc...@gm=
ail.com</a>&gt;<br><br>A.D. 1517: Martin Luther nails his 95 Theses to the =
church door and is promptly moderated down to (-1, Flamebait).<br>&nbsp;&nb=
sp; &nbsp; &nbsp; &nbsp;-- Yu Suzuki</span>

</div>
<br></div></div></blockquote><div>&nbsp;</div><div>&nbsp;</div><div>Yes, tw=
o outputs and two predicates.&nbsp;&nbsp;And the ones that aren't matched a=
ren't copied at all. It is the semantic of this new algorithm that correspo=
nds to the symantic of std::copy_if. If you want to copy all ekements of th=
e original sequence either in the first sequence or in the second sequence =
you can use the current algorithm std::partition_copy,</div><div>In fact th=
ese two algorithm, existent one and the new&lt; correspond to two algorithm=
s std::copy and std:copy_if, The current algorithm corresponds to std::copt=
 (all elements are copied) and the new one corresponds to std::copy_if (onl=
y selected elements are copied).</div><div>&nbsp;</div></blockquote><div>&n=
bsp;</div><div>&nbsp;</div><div>By the way your idea to use a set of output=
 iterators and a set of predicates can be realozed with std::tuple. So this=
 algorithm can be&nbsp;the first that will use std::tuple. Why not?&nbsp;</=
div></blockquote><div><br></div><div>Something as</div><div><br></div><pre =
class=3D"de1" style=3D"padding-bottom: 5px; padding-top: 3px; padding-left:=
 10px; background-color: rgb(250, 250, 250);"><span class=3D"kw2" style=3D"=
color: rgb(0, 0, 255); line-height: 13px !important;">template</span><font =
color=3D"#000066"> </font><span class=3D"sy1" style=3D"color: rgb(0, 0, 128=
); line-height: 13px !important;">&lt;</span><span class=3D"kw2" style=3D"c=
olor: rgb(0, 0, 255); line-height: 13px !important;">class</span><font colo=
r=3D"#000066"> InputIterator, </font><span class=3D"kw2" style=3D"color: rg=
b(0, 0, 255); line-height: 13px !important;">class</span><font color=3D"#00=
0066"> ... </font><span class=3D"me1" style=3D"color: rgb(0, 119, 136); lin=
e-height: 13px !important;">OutputIterators</span><font color=3D"#000066">,=
 </font><span class=3D"kw2" style=3D"color: rgb(0, 0, 255); line-height: 13=
px !important;">class</span><font color=3D"#000066"> ... </font><span class=
=3D"me1" style=3D"color: rgb(0, 119, 136); line-height: 13px !important;">P=
redicates</span><span class=3D"sy1" style=3D"color: rgb(0, 0, 128); line-he=
ight: 13px !important;">&gt;</span><font color=3D"#000066">
</font><font color=3D"#0000ff"><span style=3D"line-height: 13px;">std::tupl=
e&lt;OutputIterators...&gt;</span></font><span style=3D"color: rgb(0, 0, 10=
2);"> partition_copy<span class=3D"br0" style=3D"line-height: 13px !importa=
nt; color: rgb(0, 128, 0);">(</span> InputIterator first, InputIterator las=
t,=20
&nbsp; &nbsp; &nbsp; &nbsp;                                        std<span=
 class=3D"sy4" style=3D"line-height: 13px !important; color: rgb(0, 128, 12=
8);">::</span><span class=3D"me2" style=3D"line-height: 13px !important; co=
lor: rgb(0, 119, 136);">tuple</span><span class=3D"sy1" style=3D"line-heigh=
t: 13px !important; color: rgb(0, 0, 128);">&lt;</span>OutputIterators...<s=
pan class=3D"sy1" style=3D"line-height: 13px !important; color: rgb(0, 0, 1=
28);">&gt;</span> outs,
&nbsp; &nbsp; &nbsp; &nbsp;                                        std<span=
 class=3D"sy4" style=3D"line-height: 13px !important; color: rgb(0, 128, 12=
8);">::</span><span class=3D"me2" style=3D"line-height: 13px !important; co=
lor: rgb(0, 119, 136);">tuple</span><span class=3D"sy1" style=3D"line-heigh=
t: 13px !important; color: rgb(0, 0, 128);">&lt;</span>Predicates...<span c=
lass=3D"sy1" style=3D"line-height: 13px !important; color: rgb(0, 0, 128);"=
>&gt;</span> predicates <span class=3D"br0" style=3D"line-height: 13px !imp=
ortant; color: rgb(0, 128, 0);">);</span>
<br></span></pre>

<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/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_1001_13251.1361368182086--

.


Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Wed, 20 Feb 2013 05:54:28 -0800 (PST)
Raw View
------=_Part_295_29238143.1361368468844
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



=D1=81=D1=80=D0=B5=D0=B4=D0=B0, 20 =D1=84=D0=B5=D0=B2=D1=80=D0=B0=D0=BB=D1=
=8F 2013 =D0=B3., 16:49:42 UTC+3 =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:
>
>
>
> =D0=B2=D1=82=D0=BE=D1=80=D0=BD=D0=B8=D0=BA, 19 =D1=84=D0=B5=D0=B2=D1=80=
=D0=B0=D0=BB=D1=8F 2013 =D0=B3., 22:03:59 UTC+3 =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:
>>
>>
>> On Tuesday, February 19, 2013 10:48:52 PM UTC+4, Vlad from Moscow wrote:
>>>
>>>
>>> On Tuesday, February 19, 2013 9:08:23 PM UTC+4, Marshall wrote:
>>>>
>>>> On Feb 19, 2013, at 2:59 AM, Vlad from Moscow <vlad....@mail.ru> wrote=
:
>>>>
>>>> On Friday, January 11, 2013 8:43:12 PM UTC+4, Daniel Kr=C3=BCgler wrot=
e:
>>>>>
>>>>> 2013/1/11 Vlad from Moscow <vlad....@mail.ru>:=20
>>>>> >=20
>>>>> > =D0=BF=D1=8F=D1=82=D0=BD=D0=B8=D1=86=D0=B0, 11 =D1=8F=D0=BD=D0=B2=
=D0=B0=D1=80=D1=8F 2013 =D0=B3., 20:24:30 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 Scott Prager=20
>>>>> > =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:=20
>>>>> >> I think this is equivalent:=20
>>>>> >>=20
>>>>> >> http://en.cppreference.com/w/cpp/algorithm/partition_copy=20
>>>>> >>=20
>>>>> [..]=20
>>>>> >=20
>>>>> > Thanks. I did not even know that such algorithm already exists in=
=20
>>>>> the=20
>>>>> > standard library. :)  It seems that it was included only in C++ 11.=
=20
>>>>>
>>>>> Yes, that is correct, it was added by acceptance of:=20
>>>>>
>>>>> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2666.pdf=20
>>>>>
>>>>> - Daniel=20
>>>>>
>>>> =20
>>>> =20
>>>> Well, there is no problem.   In this case the thread can be renamed as=
=20
>>>> =20
>>>> "New algorithm partition_copy".:)
>>>> =20
>>>> Let consider a simple task: split a sequence of integers into two=20
>>>> sequences.The first one shall contain only positive numbers and the se=
cond=20
>>>> one shall contain only negative numbers. This simple task can not be d=
one=20
>>>> by means of the current algorithm std::partition_copy because it is un=
known=20
>>>> how to exclude elements of the original sequence that are equal to zer=
o. So=20
>>>> the possibilities of the current algorithm std::partition_copy is very=
=20
>>>> restrictive.
>>>> =20
>>>> I am suggesting to append this algorithm with a new modification=20
>>>> which is more flexible and will allow to do more complex task.  Here i=
s its=20
>>>> definition
>>>> =20
>>>> template <class InputIterator,=20
>>>>           class OutputIterator1,=20
>>>>           class OutputIterator2,
>>>>           class UnaryPredicate1,
>>>>           class UnaryPredicate2>
>>>> std::pair<OutputIterator1, OutputIterator2>=20
>>>> partition_copy( InputIterator first, InputIterator last,
>>>>                 OutputIterator1 out1, OutputIterator2 out2,
>>>>                 UnaryPredicate1 unary_predicate1,
>>>>                 UnaryPredicate2 unary_predicate2 )
>>>> {
>>>>  for ( ; first !=3D last; ++first )
>>>>  {
>>>>   if ( unary_predicate1( *first ) ) *out1++ =3D *first;
>>>>   if ( unary_predicate2( *first ) ) *out2++ =3D *first;
>>>>  }
>>>>  return ( std::make_pair( out1, out2 ) );
>>>> }
>>>>
>>>> Take into account that instead of statement
>>>>
>>>>   else if ( unary_predicate2( *first ) ) *out2++ =3D *first;
>>>>
>>>> there is=20
>>>>
>>>>   if ( unary_predicate2( *first ) ) *out2++ =3D *first;
>>>>
>>>> This will allow to place an element of the original sequence in two=20
>>>> result sequences simultaneously.
>>>>
>>>> In fact this algorithm includes two algorithms std::copy_if that deal=
=20
>>>> with the same original sequence. But it is more effective than to appl=
y=20
>>>> std::copy_if two times sequentially.
>>>>
>>>>
>>>> This feels wrong to me.   [ How's that for a deep technical=20
>>>> argument?  ;-) ]
>>>>
>>>> Two predicates, two outputs? And the ones that aren't matched aren't=
=20
>>>> copied at all?
>>>> Those seem like arbitrary decisions.
>>>>
>>>> If I were proposing something like this, I might suggest a collection=
=20
>>>> of predicates and a (identically sized) collection of output iterators=
..
>>>> [ Warning - uncompiled code ]
>>>>
>>>> template <typename InputIterator, typename Predicates, typename Output=
s>
>>>> Outputs partition_copy ( InputIterator first, InputIterator last,=20
>>>> Predicates p, Outputs o )
>>>> {
>>>> for ( ; first !=3D last; ++first ) {
>>>> auto pi =3D p.begin ();
>>>> auto oi =3D o.begin ();
>>>>                 for ( ; pi !=3D p.end (); ++pi, ++oi )
>>>> if ((*pi) (*first)) {
>>>> **oi =3D *first;
>>>> *oi++;
>>>> break;
>>>> }
>>>> return o;
>>>> }
>>>>
>>>> If you want to copy the elements that don't match somewhere, put a=20
>>>> predicate that always returns true at the end of the list.
>>>>
>>>> There's a similar algorithm that copies the values to _each_ output=20
>>>> sequence where the predicates match (just remove the "break" from the =
code)
>>>>
>>>> -- Marshall
>>>>
>>>> Marshall Clow     Idio Software   <mailto:mc...@gmail.com>
>>>>
>>>> A.D. 1517: Martin Luther nails his 95 Theses to the church door and is=
=20
>>>> promptly moderated down to (-1, Flamebait).
>>>>         -- Yu Suzuki=20
>>>>
>>>> =20
>>> =20
>>> Yes, two outputs and two predicates.  And the ones that aren't matched=
=20
>>> aren't copied at all. It is the semantic of this new algorithm that=20
>>> corresponds to the symantic of std::copy_if. If you want to copy all=20
>>> ekements of the original sequence either in the first sequence or in th=
e=20
>>> second sequence you can use the current algorithm std::partition_copy,
>>> In fact these two algorithm, existent one and the new< correspond to tw=
o=20
>>> algorithms std::copy and std:copy_if, The current algorithm corresponds=
 to=20
>>> std::copt (all elements are copied) and the new one corresponds to=20
>>> std::copy_if (only selected elements are copied).
>>> =20
>>>
>> =20
>> =20
>> By the way your idea to use a set of output iterators and a set of=20
>> predicates can be realozed with std::tuple. So this algorithm can be the=
=20
>> first that will use std::tuple. Why not?=20
>>
>
> Something as
>
> template <class InputIterator, class ... OutputIterators, class ... Predi=
cates>std::tuple<OutputIterators...> partition_copy( InputIterator first, I=
nputIterator last,=20
>                                                std::tuple<OutputIterators=
....> outs,
>                                                std::tuple<Predicates...> =
predicates );
>
>

But in any case in my opinion there should be the algorithm partition_copy=
=20
for two output iterators with two predicates in the C++ standard, because=
=20
it will be more effective and simple compared to the algorithm with using=
=20
for example std::tuple.

--=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/?hl=3Den.



------=_Part_295_29238143.1361368468844
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<br><br>=D1=81=D1=80=D0=B5=D0=B4=D0=B0, 20 =D1=84=D0=B5=D0=B2=D1=80=D0=B0=
=D0=BB=D1=8F 2013&nbsp;=D0=B3., 16:49:42 UTC+3 =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:<blockquote class=3D"gmail_quote" style=3D"m=
argin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"=
><br><br>=D0=B2=D1=82=D0=BE=D1=80=D0=BD=D0=B8=D0=BA, 19 =D1=84=D0=B5=D0=B2=
=D1=80=D0=B0=D0=BB=D1=8F 2013&nbsp;=D0=B3., 22:03:59 UTC+3 =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:<blockquote class=3D"gmail_quote=
" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-le=
ft:1ex"><br>On Tuesday, February 19, 2013 10:48:52 PM UTC+4, Vlad from Mosc=
ow wrote:<blockquote style=3D"margin:0px 0px 0px 0.8ex;padding-left:1ex;bor=
der-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:sol=
id" class=3D"gmail_quote"><br>On Tuesday, February 19, 2013 9:08:23 PM UTC+=
4, Marshall wrote:<blockquote style=3D"margin:0px 0px 0px 0.8ex;padding-lef=
t:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-=
style:solid" class=3D"gmail_quote"><div style=3D"word-wrap:break-word"><div=
><div>On Feb 19, 2013, at 2:59 AM, Vlad from Moscow &lt;<a>vlad....@mail.ru=
</a>&gt; wrote:</div><blockquote type=3D"cite">On Friday, January 11, 2013 =
8:43:12 PM UTC+4, Daniel Kr=C3=BCgler wrote:<blockquote style=3D"margin:0px=
 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-l=
eft-width:1px;border-left-style:solid" class=3D"gmail_quote">2013/1/11 Vlad=
 from Moscow &lt;<a>vlad....@mail.ru</a>&gt;:
<br>&gt;
<br>&gt; =D0=BF=D1=8F=D1=82=D0=BD=D0=B8=D1=86=D0=B0, 11 =D1=8F=D0=BD=D0=B2=
=D0=B0=D1=80=D1=8F 2013 =D0=B3., 20:24:30 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 Scott Prager
<br>&gt; =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:
<br>&gt;&gt; I think this is equivalent:
<br>&gt;&gt;
<br>&gt;&gt; <a href=3D"http://en.cppreference.com/w/cpp/algorithm/partitio=
n_copy" target=3D"_blank">http://en.cppreference.com/w/<wbr>cpp/algorithm/p=
artition_copy</a>
<br>&gt;&gt;
<br>[..]
<br>&gt;
<br>&gt; Thanks. I did not even know that such algorithm already exists in =
the
<br>&gt; standard library. :) &nbsp;It seems that it was included only in C=
++ 11.
<br>
<br>Yes, that is correct, it was added by acceptance of:
<br>
<br><a href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n266=
6.pdf" target=3D"_blank">http://www.open-std.org/jtc1/<wbr>sc22/wg21/docs/p=
apers/2008/<wbr>n2666.pdf</a>
<br>
<br>- Daniel
<br></blockquote><div>&nbsp;</div><div>&nbsp;</div><div>Well, there is no p=
roblem. &nbsp; In this case the thread can be renamed as </div><div>&nbsp;<=
/div><div>"New algorithm partition_copy".:)</div><div>&nbsp;</div><div>Let =
consider a simple task: split a sequence of integers into two sequences.The=
 first one shall contain only positive numbers and the second one shall con=
tain only negative numbers. This simple task can not be done by means of th=
e current algorithm std::partition_copy because it is unknown how to exclud=
e elements of the original sequence that are equal to zero. So the possibil=
ities of the current algorithm std::partition_copy is very restrictive.</di=
v><div>&nbsp;</div><div>I&nbsp;am suggesting to append this algorithm with&=
nbsp;a new modification which&nbsp;is more flexible and&nbsp;will allow to =
do more complex task.&nbsp; Here is its definition</div><div><font size=3D"=
2" face=3D"Consolas"><font size=3D"2" face=3D"Consolas"></font></font>&nbsp=
;</div><div><font size=3D"2" face=3D"Consolas">template &lt;class InputIter=
ator, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; class Outp=
utIterator1, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cla=
ss OutputIterator2,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; class UnaryPredicate1,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp; class UnaryPredicate2&gt;<br>std::pair&lt;OutputIterator1, OutputI=
terator2&gt; <br>partition_copy( InputIterator first, InputIterator last,<b=
r>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp; OutputIterator1 out1, OutputIterator2 out2,<br>&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp; UnaryPredicate1 unary_predicate1,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<wbr>UnaryP=
redicate2 unary_predicate2 )<br>{<br>&nbsp;for ( ; first !=3D last; ++first=
 )<br>&nbsp;{<br>&nbsp;&nbsp;if ( unary_predicate1( *first ) ) *out1++ =3D =
*first;<br>&nbsp;&nbsp;if ( unary_predicate2( *first ) ) *out2++ =3D *first=
;<br>&nbsp;}</font></div><div><font size=3D"2" face=3D"Consolas">&nbsp;retu=
rn ( std::make_pair( out1, out2 ) );<br>}<br></font></div><font size=3D"2" =
face=3D"Consolas"><p>Take into account that instead of&nbsp;statement</p><p=
>&nbsp;&nbsp;else if ( unary_predicate2( *first ) ) *out2++ =3D *first;<br>=
</p><p>there is </p><p><font size=3D"2">&nbsp; if ( unary_predicate2( *firs=
t ) ) *out2++ =3D *first;</font><br></p><p>This will allow to place an elem=
ent of the original sequence in two result sequences simultaneously.</p><p>=
In fact this algorithm includes two algorithms std::copy_if&nbsp;that deal =
with the same original sequence. But it is more effective than to apply std=
::copy_if two times sequentially.</p></font></blockquote><div><br></div>Thi=
s feels wrong to me. &nbsp; [ How's that for a deep technical argument?&nbs=
p;&nbsp;;-)&nbsp;]</div><div><br></div><div>Two predicates, two outputs? An=
d the ones that aren't matched aren't copied at all?</div><div><span style=
=3D"white-space:pre"> </span>Those seem like arbitrary decisions.</div><div=
><br></div><div>If I were proposing something like this, I might suggest a =
collection of predicates and a (identically sized) collection of output ite=
rators.</div><div>[ Warning - uncompiled code ]</div><div><br></div><div><s=
pan style=3D"white-space:pre"> </span>template &lt;typename InputIterator, =
typename Predicates, typename Outputs&gt;</div><div><span style=3D"white-sp=
ace:pre"> </span>Outputs partition_copy (&nbsp;InputIterator first, InputIt=
erator last, Predicates p, Outputs o )</div><div><span style=3D"white-space=
:pre"> </span>{</div><span style=3D"white-space:pre">  </span>for ( ; first=
 !=3D last; ++first )&nbsp;{<br><span style=3D"white-space:pre">   </span>a=
uto pi =3D p.begin ();<div><span style=3D"white-space:pre">   </span>auto o=
i =3D o.begin ();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; <span style=3D"whit=
e-space:pre"> </span>&nbsp; &nbsp; &nbsp; &nbsp; for ( ; pi !=3D p.end (); =
++pi, ++oi )</div><div><span style=3D"white-space:pre">    </span>if ((*pi)=
 (*first)) {</div><div><span style=3D"white-space:pre">     </span>**oi =3D=
 *first;</div><div><span style=3D"white-space:pre">     </span>*oi++;</div>=
<div><span style=3D"white-space:pre">     </span>break;</div><div><span sty=
le=3D"white-space:pre">     </span>}</div><div><span style=3D"white-space:p=
re">  </span>return o;</div><div><span style=3D"white-space:pre"> </span>}<=
br><div><br></div><div>If you want to copy the elements that don't match so=
mewhere, put a predicate that always returns true at the end of the list.</=
div><div><br></div><div>There's a similar algorithm that copies the values =
to _each_ output sequence where the predicates match (just remove the "brea=
k" from the code)</div><div><br></div><div>
<span style=3D"border-collapse:separate;border-spacing:0px">-- Marshall<br>=
<br>Marshall Clow &nbsp; &nbsp; Idio Software &nbsp; &lt;<a>mailto:mc...@gm=
ail.com</a>&gt;<br><br>A.D. 1517: Martin Luther nails his 95 Theses to the =
church door and is promptly moderated down to (-1, Flamebait).<br>&nbsp;&nb=
sp; &nbsp; &nbsp; &nbsp;-- Yu Suzuki</span>

</div>
<br></div></div></blockquote><div>&nbsp;</div><div>&nbsp;</div><div>Yes, tw=
o outputs and two predicates.&nbsp;&nbsp;And the ones that aren't matched a=
ren't copied at all. It is the semantic of this new algorithm that correspo=
nds to the symantic of std::copy_if. If you want to copy all ekements of th=
e original sequence either in the first sequence or in the second sequence =
you can use the current algorithm std::partition_copy,</div><div>In fact th=
ese two algorithm, existent one and the new&lt; correspond to two algorithm=
s std::copy and std:copy_if, The current algorithm corresponds to std::copt=
 (all elements are copied) and the new one corresponds to std::copy_if (onl=
y selected elements are copied).</div><div>&nbsp;</div></blockquote><div>&n=
bsp;</div><div>&nbsp;</div><div>By the way your idea to use a set of output=
 iterators and a set of predicates can be realozed with std::tuple. So this=
 algorithm can be&nbsp;the first that will use std::tuple. Why not?&nbsp;</=
div></blockquote><div><br></div><div>Something as</div><div><br></div><pre =
style=3D"padding-bottom:5px;padding-top:3px;padding-left:10px;background-co=
lor:rgb(250,250,250)"><span style=3D"color:rgb(0,0,255);line-height:13px!im=
portant">template</span><font color=3D"#000066"> </font><span style=3D"colo=
r:rgb(0,0,128);line-height:13px!important">&lt;</span><span style=3D"color:=
rgb(0,0,255);line-height:13px!important">class</span><font color=3D"#000066=
"> InputIterator, </font><span style=3D"color:rgb(0,0,255);line-height:13px=
!important">class</span><font color=3D"#000066"> ... </font><span style=3D"=
color:rgb(0,119,136);line-height:13px!important">OutputIterators</span><fon=
t color=3D"#000066">, </font><span style=3D"color:rgb(0,0,255);line-height:=
13px!important">class</span><font color=3D"#000066"> ... </font><span style=
=3D"color:rgb(0,119,136);line-height:13px!important">Predicates</span><span=
 style=3D"color:rgb(0,0,128);line-height:13px!important">&gt;</span><font c=
olor=3D"#000066">
</font><font color=3D"#0000ff"><span style=3D"line-height:13px">std::tuple&=
lt;OutputIterators...&gt;</span></font><span style=3D"color:rgb(0,0,102)"> =
partition_copy<span style=3D"line-height:13px!important;color:rgb(0,128,0)"=
>(</span> InputIterator first, InputIterator last,=20
&nbsp; &nbsp; &nbsp; &nbsp;                                        std<span=
 style=3D"line-height:13px!important;color:rgb(0,128,128)">::</span><span s=
tyle=3D"line-height:13px!important;color:rgb(0,119,136)">tuple</span><span =
style=3D"line-height:13px!important;color:rgb(0,0,128)">&lt;</span>OutputIt=
erators...<span style=3D"line-height:13px!important;color:rgb(0,0,128)">&gt=
;</span> outs,
&nbsp; &nbsp; &nbsp; &nbsp;                                        std<span=
 style=3D"line-height:13px!important;color:rgb(0,128,128)">::</span><span s=
tyle=3D"line-height:13px!important;color:rgb(0,119,136)">tuple</span><span =
style=3D"line-height:13px!important;color:rgb(0,0,128)">&lt;</span>Predicat=
es...<span style=3D"line-height:13px!important;color:rgb(0,0,128)">&gt;</sp=
an> predicates <span style=3D"line-height:13px!important;color:rgb(0,128,0)=
">);</span>
<br></span></pre></blockquote><div><br></div><div><br></div><div>But in any=
 case in my opinion there should be the algorithm partition_copy for two ou=
tput iterators with two predicates in the C++ standard, because it will be =
more effective and simple compared to the algorithm with using for example =
std::tuple.</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/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_295_29238143.1361368468844--

.


Author: Marshall Clow <mclow.lists@gmail.com>
Date: Wed, 20 Feb 2013 13:23:50 -0800
Raw View
--Apple-Mail=_94338D9B-C659-4FDF-9F18-A5736E7AAE11
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1

On Feb 19, 2013, at 11:03 AM, Vlad from Moscow <vlad.moscow@mail.ru> wrote:
> On Tuesday, February 19, 2013 10:48:52 PM UTC+4, Vlad from Moscow wrote:
>=20
> On Tuesday, February 19, 2013 9:08:23 PM UTC+4, Marshall wrote:
> Two predicates, two outputs? And the ones that aren't matched aren't copi=
ed at all?
>  Those seem like arbitrary decisions.

> Yes, two outputs and two predicates.  And the ones that aren't matched ar=
en't copied at all. It is the semantic of this new algorithm that correspon=
ds to the symantic of std::copy_if. If you want to copy all ekements of the=
 original sequence either in the first sequence or in the second sequence y=
ou can use the current algorithm std::partition_copy,
> In fact these two algorithm, existent one and the new< correspond to two =
algorithms std::copy and std:copy_if, The current algorithm corresponds to =
std::copt (all elements are copied) and the new one corresponds to std::cop=
y_if (only selected elements are copied)

My point was why two? Why not have versions for three, four as well?

I believe with a collection of predicates and iterators you can do N-way pa=
rtitioning,
and provide both the "things that match aren't copied", and "copy all the t=
hings that nothing matched <here>" functionality.


>=20
> If I were proposing something like this, I might suggest a collection of =
predicates and a (identically sized) collection of output iterators.
> [ Warning - uncompiled code ]
>=20
>  template <typename InputIterator, typename Predicates, typename Outputs>
>  Outputs partition_copy ( InputIterator first, InputIterator last, Predic=
ates p, Outputs o )
>  {
>   for ( ; first !=3D last; ++first ) {
>    auto pi =3D p.begin ();
>    auto oi =3D o.begin ();
>                  for ( ; pi !=3D p.end (); ++pi, ++oi )
>     if ((*pi) (*first)) {
>      **oi =3D *first;
>      *oi++;
>      break;
>      }
>   return o;
>  }
>=20
> If you want to copy the elements that don't match somewhere, put a predic=
ate that always returns true at the end of the list.
>=20
> There's a similar algorithm that copies the values to _each_ output seque=
nce where the predicates match (just remove the "break" from the code)
> =20
> By the way your idea to use a set of output iterators and a set of predic=
ates can be realozed with std::tuple. So this algorithm can be the first th=
at will use std::tuple. Why not?=20

I don't think std::tuple is the right data structure here, because it is (c=
an be) heterogeneous.
We want a collection of predicates (and iterators) that we can treat identi=
cally.

-- Marshall

Marshall Clow     Idio Software   <mailto:mclow.lists@gmail.com>

A.D. 1517: Martin Luther nails his 95 Theses to the church door and is prom=
ptly moderated down to (-1, Flamebait).
        -- Yu Suzuki

--=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/?hl=3Den.



--Apple-Mail=_94338D9B-C659-4FDF-9F18-A5736E7AAE11
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dus-ascii"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode=
: space; -webkit-line-break: after-white-space; "><div><div>On Feb 19, 2013=
, at 11:03 AM, Vlad from Moscow &lt;<a href=3D"mailto:vlad.moscow@mail.ru">=
vlad.moscow@mail.ru</a>&gt; wrote:</div><blockquote type=3D"cite">On Tuesda=
y, February 19, 2013 10:48:52 PM UTC+4, Vlad from Moscow wrote:<blockquote =
style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: r=
gb(204, 204, 204); border-left-width: 1px; border-left-style: solid; positi=
on: static; z-index: auto; " class=3D"gmail_quote"><br>On Tuesday, February=
 19, 2013 9:08:23 PM UTC+4, Marshall wrote:<blockquote style=3D"margin: 0px=
 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); b=
order-left-width: 1px; border-left-style: solid; position: static; z-index:=
 auto; " class=3D"gmail_quote"><div style=3D"word-wrap: break-word;"><div><=
div>Two predicates, two outputs? And the ones that aren't matched aren't co=
pied at all?</div></div><div><span style=3D"white-space: pre;"> </span>Thos=
e seem like arbitrary decisions.</div></div></blockquote></blockquote></blo=
ckquote><div><br></div><blockquote type=3D"cite"><blockquote class=3D"gmail=
_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-=
color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid=
; position: static; z-index: auto; "><div>Yes, two outputs and two predicat=
es.&nbsp;&nbsp;And the ones that aren't matched aren't copied at all. It is=
 the semantic of this new algorithm that corresponds to the symantic of std=
::copy_if. If you want to copy all ekements of the original sequence either=
 in the first sequence or in the second sequence you can use the current al=
gorithm std::partition_copy,</div><div>In fact these two algorithm, existen=
t one and the new&lt; correspond to two algorithms std::copy and std:copy_i=
f, The current algorithm corresponds to std::copt (all elements are copied)=
 and the new one corresponds to std::copy_if (only selected elements are co=
pied)</div></blockquote></blockquote><div><br></div><div>My point was why t=
wo? Why not have versions for three, four as well?</div><div><br></div><div=
>I believe with a collection of predicates and iterators you can do N-way p=
artitioning,</div><div>and provide both the "things that match aren't copie=
d", and "copy all the things that nothing matched &lt;here&gt;" functionali=
ty.</div><div><br></div><div><br></div><blockquote type=3D"cite"><blockquot=
e style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color:=
 rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid; posi=
tion: static; z-index: auto; " class=3D"gmail_quote"><blockquote 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; position: static=
; z-index: auto; " class=3D"gmail_quote"><div style=3D"word-wrap: break-wor=
d;"><div><br></div><div>If I were proposing something like this, I might su=
ggest a collection of predicates and a (identically sized) collection of ou=
tput iterators.</div><div>[ Warning - uncompiled code ]</div><div><br></div=
><div><span style=3D"white-space: pre;"> </span>template &lt;typename Input=
Iterator, typename Predicates, typename Outputs&gt;</div><div><span style=
=3D"white-space: pre;"> </span>Outputs partition_copy (&nbsp;InputIterator =
first, InputIterator last, Predicates p, Outputs o )</div><div><span style=
=3D"white-space: pre;"> </span>{</div><span style=3D"white-space: pre;">  <=
/span>for ( ; first !=3D last; ++first )&nbsp;{<br><span style=3D"white-spa=
ce: pre;">   </span>auto pi =3D p.begin ();<div><span style=3D"white-space:=
 pre;">   </span>auto oi =3D o.begin ();</div><div>&nbsp; &nbsp; &nbsp; &nb=
sp; <span style=3D"white-space: pre;"> </span>&nbsp; &nbsp; &nbsp; &nbsp; f=
or ( ; pi !=3D p.end (); ++pi, ++oi )</div><div><span style=3D"white-space:=
 pre;">    </span>if ((*pi) (*first)) {</div><div><span style=3D"white-spac=
e: pre;">     </span>**oi =3D *first;</div><div><span style=3D"white-space:=
 pre;">     </span>*oi++;</div><div><span style=3D"white-space: pre;">     =
</span>break;</div><div><span style=3D"white-space: pre;">     </span>}</di=
v><div><span style=3D"white-space: pre;">  </span>return o;</div><div><span=
 style=3D"white-space: pre;"> </span>}<br><div><br></div><div>If you want t=
o copy the elements that don't match somewhere, put a predicate that always=
 returns true at the end of the list.</div><div><br></div><div>There's a si=
milar algorithm that copies the values to _each_ output sequence where the =
predicates match (just remove the "break" from the code)</div></div></div><=
/blockquote><div>&nbsp;</div></blockquote><div>By the way your idea to use =
a set of output iterators and a set of predicates can be realozed with std:=
:tuple. So this algorithm can be&nbsp;the first that will use std::tuple. W=
hy not?&nbsp;</div></blockquote><div><br></div>I don't think std::tuple is =
the right data structure here, because it is (can be) heterogeneous.</div><=
div>We want a collection of predicates (and iterators) that we can treat id=
entically.</div><div><br></div><div apple-content-edited=3D"true">
<span class=3D"Apple-style-span" style=3D"border-collapse: separate; border=
-spacing: 0px; ">-- Marshall<br><br>Marshall Clow &nbsp; &nbsp; Idio Softwa=
re &nbsp; &lt;<a href=3D"mailto:mclow.lists@gmail.com">mailto:mclow.lists@g=
mail.com</a>&gt;<br><br>A.D. 1517: Martin Luther nails his 95 Theses to the=
 church door and is promptly moderated down to (-1, Flamebait).<br>&nbsp;&n=
bsp; &nbsp; &nbsp; &nbsp;-- Yu Suzuki</span>

</div>
<br></body></html>

<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/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
&nbsp;<br />
&nbsp;<br />

--Apple-Mail=_94338D9B-C659-4FDF-9F18-A5736E7AAE11--

.


Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Thu, 21 Feb 2013 04:15:04 -0800 (PST)
Raw View
------=_Part_1569_4759699.1361448904705
Content-Type: text/plain; charset=KOI8-R
Content-Transfer-Encoding: quoted-printable



=DE=C5=D4=D7=C5=D2=C7, 21 =C6=C5=D7=D2=C1=CC=D1 2013 =C7., 0:23:50 UTC+3 =
=D0=CF=CC=D8=DA=CF=D7=C1=D4=C5=CC=D8 Marshall =CE=C1=D0=C9=D3=C1=CC:
>
> On Feb 19, 2013, at 11:03 AM, Vlad from Moscow <vlad....@mail.ru<javascri=
pt:>>=20
> wrote:
>
> On Tuesday, February 19, 2013 10:48:52 PM UTC+4, Vlad from Moscow wrote:
>>
>>
>> On Tuesday, February 19, 2013 9:08:23 PM UTC+4, Marshall wrote:
>>>
>>> Two predicates, two outputs? And the ones that aren't matched aren't=20
>>> copied at all?
>>> Those seem like arbitrary decisions.
>>>
>>
> Yes, two outputs and two predicates.  And the ones that aren't matched=20
>> aren't copied at all. It is the semantic of this new algorithm that=20
>> corresponds to the symantic of std::copy_if. If you want to copy all=20
>> ekements of the original sequence either in the first sequence or in the=
=20
>> second sequence you can use the current algorithm std::partition_copy,
>> In fact these two algorithm, existent one and the new< correspond to two=
=20
>> algorithms std::copy and std:copy_if, The current algorithm corresponds =
to=20
>> std::copt (all elements are copied) and the new one corresponds to=20
>> std::copy_if (only selected elements are copied)
>>
>
> My point was why two? Why not have versions for three, four as well?
>
> I believe with a collection of predicates and iterators you can do N-way=
=20
> partitioning,
> and provide both the "things that match aren't copied", and "copy all the=
=20
> things that nothing matched <here>" functionality.
>
>
>
>>> If I were proposing something like this, I might suggest a collection o=
f=20
>>> predicates and a (identically sized) collection of output iterators.
>>> [ Warning - uncompiled code ]
>>>
>>> template <typename InputIterator, typename Predicates, typename Outputs=
>
>>> Outputs partition_copy ( InputIterator first, InputIterator last,=20
>>> Predicates p, Outputs o )
>>> {
>>> for ( ; first !=3D last; ++first ) {
>>> auto pi =3D p.begin ();
>>> auto oi =3D o.begin ();
>>>                 for ( ; pi !=3D p.end (); ++pi, ++oi )
>>> if ((*pi) (*first)) {
>>> **oi =3D *first;
>>> *oi++;
>>> break;
>>> }
>>> return o;
>>> }
>>>
>>> If you want to copy the elements that don't match somewhere, put a=20
>>> predicate that always returns true at the end of the list.
>>>
>>> There's a similar algorithm that copies the values to _each_ output=20
>>> sequence where the predicates match (just remove the "break" from the c=
ode)
>>>
>> =20
>>
> By the way your idea to use a set of output iterators and a set of=20
> predicates can be realozed with std::tuple. So this algorithm can be the=
=20
> first that will use std::tuple. Why not?=20
>
>
> I don't think std::tuple is the right data structure here, because it is=
=20
> (can be) heterogeneous.
> We want a collection of predicates (and iterators) that we can treat=20
> identically.
>
> -- Marshall
>
> Marshall Clow     Idio Software   <mailto:mc...@gmail.com <javascript:>>
>
> A.D. 1517: Martin Luther nails his 95 Theses to the church door and is=20
> promptly moderated down to (-1, Flamebait).
>         -- Yu Suzuki=20
>
>

The current algorithm std::partition_copy has restrictive possibilities and=
=20
even does not allow to resolve the simple problem I described early. In=20
fact it is supllement to algorithm std::copy that copies all elements of a=
=20
sequence except that std::partition_copy copies all elements of a sequence=
=20
into two sequences.
However algorithm std::copy_if that selectively copies elements of a=20
sequence has no  similar algorithm with name partition_copy. Without the=20
new modification the family of algorithms copy and partition_copy is=20
incomplete. I do not see any satisfactory realization of partition_copy for=
=20
the number of output iterators greater than two. Even such a modification=
=20
will be suggested I think everybody will prefer to use the algorithm I=20
suggested when the number of output iterators will be equal to two because=
=20
this algorithm modification wil be more effective and visually clear for=20
readers of code then the modifications for several output iterators..

--=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/?hl=3Den.



------=_Part_1569_4759699.1361448904705
Content-Type: text/html; charset=KOI8-R
Content-Transfer-Encoding: quoted-printable

<br><br>=DE=C5=D4=D7=C5=D2=C7, 21 =C6=C5=D7=D2=C1=CC=D1 2013&nbsp;=C7., 0:2=
3:50 UTC+3 =D0=CF=CC=D8=DA=CF=D7=C1=D4=C5=CC=D8 Marshall =CE=C1=D0=C9=D3=C1=
=CC:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex=
;border-left: 1px #ccc solid;padding-left: 1ex;"><div style=3D"word-wrap:br=
eak-word"><div><div>On Feb 19, 2013, at 11:03 AM, Vlad from Moscow &lt;<a h=
ref=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"Wb7CwhwfpC4J=
">vlad....@mail.ru</a>&gt; wrote:</div><blockquote type=3D"cite">On Tuesday=
, February 19, 2013 10:48:52 PM UTC+4, Vlad from Moscow wrote:<blockquote s=
tyle=3D"margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204=
,204,204);border-left-width:1px;border-left-style:solid" class=3D"gmail_quo=
te"><br>On Tuesday, February 19, 2013 9:08:23 PM UTC+4, Marshall wrote:<blo=
ckquote style=3D"margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-colo=
r:rgb(204,204,204);border-left-width:1px;border-left-style:solid" class=3D"=
gmail_quote"><div style=3D"word-wrap:break-word"><div><div>Two predicates, =
two outputs? And the ones that aren't matched aren't copied at all?</div></=
div><div><span style=3D"white-space:pre"> </span>Those seem like arbitrary =
decisions.</div></div></blockquote></blockquote></blockquote><div><br></div=
><blockquote type=3D"cite"><blockquote class=3D"gmail_quote" style=3D"margi=
n:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);bor=
der-left-width:1px;border-left-style:solid"><div>Yes, two outputs and two p=
redicates.&nbsp;&nbsp;And the ones that aren't matched aren't copied at all=
.. It is the semantic of this new algorithm that corresponds to the symantic=
 of std::copy_if. If you want to copy all ekements of the original sequence=
 either in the first sequence or in the second sequence you can use the cur=
rent algorithm std::partition_copy,</div><div>In fact these two algorithm, =
existent one and the new&lt; correspond to two algorithms std::copy and std=
:copy_if, The current algorithm corresponds to std::copt (all elements are =
copied) and the new one corresponds to std::copy_if (only selected elements=
 are copied)</div></blockquote></blockquote><div><br></div><div>My point wa=
s why two? Why not have versions for three, four as well?</div><div><br></d=
iv><div>I believe with a collection of predicates and iterators you can do =
N-way partitioning,</div><div>and provide both the "things that match aren'=
t copied", and "copy all the things that nothing matched &lt;here&gt;" func=
tionality.</div><div><br></div><div><br></div><blockquote type=3D"cite"><bl=
ockquote style=3D"margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-col=
or:rgb(204,204,204);border-left-width:1px;border-left-style:solid" class=3D=
"gmail_quote"><blockquote style=3D"margin:0px 0px 0px 0.8ex;padding-left:1e=
x;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-styl=
e:solid" class=3D"gmail_quote"><div style=3D"word-wrap:break-word"><div><br=
></div><div>If I were proposing something like this, I might suggest a coll=
ection of predicates and a (identically sized) collection of output iterato=
rs.</div><div>[ Warning - uncompiled code ]</div><div><br></div><div><span =
style=3D"white-space:pre"> </span>template &lt;typename InputIterator, type=
name Predicates, typename Outputs&gt;</div><div><span style=3D"white-space:=
pre"> </span>Outputs partition_copy (&nbsp;InputIterator first, InputIterat=
or last, Predicates p, Outputs o )</div><div><span style=3D"white-space:pre=
"> </span>{</div><span style=3D"white-space:pre">  </span>for ( ; first !=
=3D last; ++first )&nbsp;{<br><span style=3D"white-space:pre">   </span>aut=
o pi =3D p.begin ();<div><span style=3D"white-space:pre">   </span>auto oi =
=3D o.begin ();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; <span style=3D"white-=
space:pre"> </span>&nbsp; &nbsp; &nbsp; &nbsp; for ( ; pi !=3D p.end (); ++=
pi, ++oi )</div><div><span style=3D"white-space:pre">    </span>if ((*pi) (=
*first)) {</div><div><span style=3D"white-space:pre">     </span>**oi =3D *=
first;</div><div><span style=3D"white-space:pre">     </span>*oi++;</div><d=
iv><span style=3D"white-space:pre">     </span>break;</div><div><span style=
=3D"white-space:pre">     </span>}</div><div><span style=3D"white-space:pre=
">  </span>return o;</div><div><span style=3D"white-space:pre"> </span>}<br=
><div><br></div><div>If you want to copy the elements that don't match some=
where, put a predicate that always returns true at the end of the list.</di=
v><div><br></div><div>There's a similar algorithm that copies the values to=
 _each_ output sequence where the predicates match (just remove the "break"=
 from the code)</div></div></div></blockquote><div>&nbsp;</div></blockquote=
><div>By the way your idea to use a set of output iterators and a set of pr=
edicates can be realozed with std::tuple. So this algorithm can be&nbsp;the=
 first that will use std::tuple. Why not?&nbsp;</div></blockquote><div><br>=
</div>I don't think std::tuple is the right data structure here, because it=
 is (can be) heterogeneous.</div><div>We want a collection of predicates (a=
nd iterators) that we can treat identically.</div><div><br></div><div>
<span style=3D"border-collapse:separate;border-spacing:0px">-- Marshall<br>=
<br>Marshall Clow &nbsp; &nbsp; Idio Software &nbsp; &lt;<a href=3D"javascr=
ipt:" target=3D"_blank" gdf-obfuscated-mailto=3D"Wb7CwhwfpC4J">mailto:mc...=
@gmail.com</a>&gt;<br><br>A.D. 1517: Martin Luther nails his 95 Theses to t=
he church door and is promptly moderated down to (-1, Flamebait).<br>&nbsp;=
&nbsp; &nbsp; &nbsp; &nbsp;-- Yu Suzuki</span>

</div>
<br></div></blockquote><div><br></div><div><br></div><div>The current algor=
ithm std::partition_copy has restrictive possibilities and even does not al=
low to resolve the simple problem I described early. In fact it is suplleme=
nt to algorithm std::copy that copies all elements of a sequence except tha=
t std::partition_copy copies all elements of a sequence into two sequences.=
</div><div>However algorithm std::copy_if that selectively copies elements =
of a sequence has no &nbsp;similar algorithm with name partition_copy. With=
out the new modification the family of algorithms copy and partition_copy i=
s incomplete. I do not see any satisfactory realization of partition_copy f=
or the number of output iterators greater than two. Even such a modificatio=
n will be suggested I think everybody will prefer to use the algorithm I su=
ggested when the number of output iterators will be equal to two because th=
is algorithm modification wil be more effective and visually clear for read=
ers of code then the modifications for several output iterators..</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/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_1569_4759699.1361448904705--

.