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> </div><div>So maybe it would be useful to consid=
er something as</div><div> </div><div>template <class InputIterator=
, <br> class OutputIterator1, <br> clas=
s OutputIterator2,<br>  =
; class UnaryPredicate><br>std::pair<OutputIterator1, OutputIterator2=
> split( InputIterator first, InputIterator last,<br> &=
nbsp; &nbs=
p; OutputIterator1 out1, OutputIterator2 out2,<br>&=
nbsp; UnaryPredicate unary_predicate )<br>{<br>&nbs=
p;for ( ; first !=3D last; ++first )<br> {<br> if ( unary_p=
redicate( *first ) ) *out1++ =3D *first;<br> else *out2++ =3D *f=
irst;<br> }</div><div> return ( std::make_pair( out1, out2 ) );<b=
r>}<br></div>
<p></p>
-- <br />
<br />
<br />
<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> </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> </div><div>So maybe it would be useful to consider=
something as</div><div> </div><div>template <class InputIterator, =
<br> class OutputIterator1, <br> class =
OutputIterator2,<br> =
class UnaryPredicate><br>std::pair<OutputIterator1, OutputIterator2&g=
t; split( InputIterator first, InputIterator last,<br> &nb=
sp; =
OutputIterator1 out1, OutputIterator2 out2,<br>&nb=
sp; UnaryPredicate unary_predicate )<br>{<br> =
for ( ; first !=3D last; ++first )<br> {<br> if ( unary_pre=
dicate( *first ) ) *out1++ =3D *first;<br> else *out2++ =3D *fir=
st;<br> }</div><div> return ( std::make_pair( out1, out2 ) );<br>=
}<br></div></blockquote>
<p></p>
-- <br />
<br />
<br />
<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 =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> </div><div>So maybe it woul=
d be useful to consider something as</div><div> </div><div>template &l=
t;class InputIterator, <br> class OutputIterator1, <br>&n=
bsp; class OutputIterator2,<br> &n=
bsp; class UnaryPredicate><br>std::pair<OutputItera=
tor1, OutputIterator2> split( InputIterator first, InputIterator last,<b=
r> &=
nbsp; OutputIterator1 out1, Outpu=
tIterator2 out2,<br> UnaryPredicate unary_pre=
dicate )<br>{<br> for ( ; first !=3D last; ++first )<br> {<br>&nb=
sp; if ( unary_predicate( *first ) ) *out1++ =3D *first;<br> &nbs=
p;else *out2++ =3D *first;<br> }</div><div> return ( std::make_pa=
ir( out1, out2 ) );<br>}<br></div></blockquote></blockquote><div> </di=
v><div> </div><div>Thanks. I did not even know that such algorithm alr=
eady exists in the standard library. :) It seems that it was included=
only in C++ 11. </div>
<p></p>
-- <br />
<br />
<br />
<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 <<a href=3D"jav=
ascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"OkSpVUdUtosJ">vlad....=
@mail.ru</a>>:
<br>>
<br>> =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>> =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:
<br>>> I think this is equivalent:
<br>>>
<br>>> <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>>>
<br>[..]
<br>>
<br>> Thanks. I did not even know that such algorithm already exists in =
the
<br>> standard library. :) 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> </div><div> </div><div>Well, there is no p=
roblem. In this case the thread can be renamed as </div><div> <=
/div><div>"New algorithm partition_copy".:)</div><div> </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> </div><div>I am suggesting to append this algorithm with&=
nbsp;a new modification which is more flexible and will allow to =
do more complex task. Here is its definition</div><div><font size=3D"=
2" face=3D"Consolas"><font size=3D"2" face=3D"Consolas"></font></font> =
;</div><div><font size=3D"2" face=3D"Consolas"><font size=3D"2" face=3D"Con=
solas">template <class InputIterator, <br> =
class OutputIterator1, <br>  =
; class OutputIterator2,<br>  =
; class UnaryPredicate1,<br>  =
; class UnaryPredicate2><br>st=
d::pair<OutputIterator1, OutputIterator2> <br>partition_copy( InputIt=
erator first, InputIterator last,<br> &n=
bsp; OutputIterator1 out1, =
OutputIterator2 out2,<br> &n=
bsp; UnaryPredicate1 unary_predicate1,<=
br> =
UnaryPredicate2 unary_predicate2 )<br>{<br> fo=
r ( ; first !=3D last; ++first )<br> {<br> if ( unary_predi=
cate1( *first ) ) *out1++ =3D *first;<br> if ( unary_predicate2(=
*first ) ) *out2++ =3D *first;<br> }</font></font></div><div><font si=
ze=3D"2" face=3D"Consolas"><font size=3D"2" face=3D"Consolas"> 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 statement</p><p> else if ( unary_predica=
te2( *first ) ) *out2++ =3D *first;<br></p><p>there is </p><p><font size=3D=
"2"> 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 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 />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
<br />
<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 <<a href=3D"mailto:vlad.moscow@mail.ru">vlad=
..moscow@mail.ru</a>> 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 <<a href=3D"javascript:" target=
=3D"_blank" gdf-obfuscated-mailto=3D"OkSpVUdUtosJ">vlad....@mail.ru</a>>=
:
<br>>
<br>> =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>> =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:
<br>>> I think this is equivalent:
<br>>>
<br>>> <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>>>
<br>[..]
<br>>
<br>> Thanks. I did not even know that such algorithm already exists in =
the
<br>> standard library. :) 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> </div><div> </div><div>Well, there is no p=
roblem. In this case the thread can be renamed as </div><div> <=
/div><div>"New algorithm partition_copy".:)</div><div> </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> </div><div>I am suggesting to append this algorithm with&=
nbsp;a new modification which is more flexible and will allow to =
do more complex task. Here is its definition</div><div><font size=3D"=
2" face=3D"Consolas"><font size=3D"2" face=3D"Consolas"></font></font> =
;</div><div><font size=3D"2" face=3D"Consolas">template <class InputIter=
ator, <br> class Outp=
utIterator1, <br> cla=
ss OutputIterator2,<br> &nbs=
p; class UnaryPredicate1,<br> &nbs=
p; class UnaryPredicate2><br>std::pair<OutputIterator1, OutputI=
terator2> <br>partition_copy( InputIterator first, InputIterator last,<b=
r> &=
nbsp; OutputIterator1 out1, OutputIterator2 out2,<br> &nbs=
p; &=
nbsp; UnaryPredicate1 unary_predicate1,<br> &n=
bsp; UnaryPredic=
ate2 unary_predicate2 )<br>{<br> for ( ; first !=3D last; ++first )<br=
> {<br> if ( unary_predicate1( *first ) ) *out1++ =3D *firs=
t;<br> if ( unary_predicate2( *first ) ) *out2++ =3D *first;<br>=
}</font></div><div><font size=3D"2" face=3D"Consolas"> return ( =
std::make_pair( out1, out2 ) );<br>}<br></font></div><font size=3D"2" face=
=3D"Consolas"><p>Take into account that instead of statement</p><p>&nb=
sp; else if ( unary_predicate2( *first ) ) *out2++ =3D *first;<br></p>=
<p>there is </p><p><font size=3D"2"> 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 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. [ How's that for a deep technical argument? &n=
bsp;;-) ]</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 <typename InputIterator, typename Predicates, typename =
Outputs></div><div><span class=3D"Apple-tab-span" style=3D"white-space:p=
re"> </span>Outputs partition_copy ( 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 ) {<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> =
<span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span> &n=
bsp; 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 Idio Softwa=
re <<a href=3D"mailto:mclow.lists@gmail.com">mailto:mclow.lists@g=
mail.com</a>><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; -- Yu Suzuki</span>
</div>
<br></div></body></html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
<br />
<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 <<a href=3D"javascript:" target=
=3D"_blank" gdf-obfuscated-mailto=3D"9FoKb8k6-fYJ">vlad....@mail.ru</a>>=
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 <<a>vlad....@mail.ru</a>>:
<br>>
<br>> =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>> =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:
<br>>> I think this is equivalent:
<br>>>
<br>>> <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>>>
<br>[..]
<br>>
<br>> Thanks. I did not even know that such algorithm already exists in =
the
<br>> standard library. :) 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> </div><div> </div><div>Well, there is no p=
roblem. In this case the thread can be renamed as </div><div> <=
/div><div>"New algorithm partition_copy".:)</div><div> </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> </div><div>I am suggesting to append this algorithm with&=
nbsp;a new modification which is more flexible and will allow to =
do more complex task. Here is its definition</div><div><font size=3D"=
2" face=3D"Consolas"><font size=3D"2" face=3D"Consolas"></font></font> =
;</div><div><font size=3D"2" face=3D"Consolas">template <class InputIter=
ator, <br> class Outp=
utIterator1, <br> cla=
ss OutputIterator2,<br> &nbs=
p; class UnaryPredicate1,<br> &nbs=
p; class UnaryPredicate2><br>std::pair<OutputIterator1, OutputI=
terator2> <br>partition_copy( InputIterator first, InputIterator last,<b=
r> &=
nbsp; OutputIterator1 out1, OutputIterator2 out2,<br> &nbs=
p; &=
nbsp; UnaryPredicate1 unary_predicate1,<br> &n=
bsp; <wbr>UnaryP=
redicate2 unary_predicate2 )<br>{<br> for ( ; first !=3D last; ++first=
)<br> {<br> if ( unary_predicate1( *first ) ) *out1++ =3D =
*first;<br> if ( unary_predicate2( *first ) ) *out2++ =3D *first=
;<br> }</font></div><div><font size=3D"2" face=3D"Consolas"> 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 statement</p><p=
> else if ( unary_predicate2( *first ) ) *out2++ =3D *first;<br>=
</p><p>there is </p><p><font size=3D"2"> 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 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. [ How's that for a deep technical argument?&nbs=
p; ;-) ]</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 <typename InputIterat=
or, typename Predicates, typename Outputs></div><div><span style=3D"whit=
e-space: pre;"> </span>Outputs partition_copy ( 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 ) {<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> <span=
style=3D"white-space: pre;"> </span> 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 Idio Software <<a href=3D"jav=
ascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"9FoKb8k6-fYJ">mailto:m=
c...@gmail.com</a>><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; -- Yu Suzuki</span>
</div>
<br></div></div></blockquote><div> </div><div> </div><div>Yes, tw=
o outputs and two predicates. 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< 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 />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
<br />
<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 <<=
a>vlad....@mail.ru</a>> 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 <<a>vlad....@mail.ru</a>>=
:
<br>>
<br>> =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>> =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:
<br>>> I think this is equivalent:
<br>>>
<br>>> <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>>>
<br>[..]
<br>>
<br>> Thanks. I did not even know that such algorithm already exists in =
the
<br>> standard library. :) 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> </div><div> </div><div>Well, there is no p=
roblem. In this case the thread can be renamed as </div><div> <=
/div><div>"New algorithm partition_copy".:)</div><div> </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> </div><div>I am suggesting to append this algorithm with&=
nbsp;a new modification which is more flexible and will allow to =
do more complex task. Here is its definition</div><div><font size=3D"=
2" face=3D"Consolas"><font size=3D"2" face=3D"Consolas"></font></font> =
;</div><div><font size=3D"2" face=3D"Consolas">template <class InputIter=
ator, <br> class Outp=
utIterator1, <br> cla=
ss OutputIterator2,<br> &nbs=
p; class UnaryPredicate1,<br> &nbs=
p; class UnaryPredicate2><br>std::pair<OutputIterator1, OutputI=
terator2> <br>partition_copy( InputIterator first, InputIterator last,<b=
r> &=
nbsp; OutputIterator1 out1, OutputIterator2 out2,<br> &nbs=
p; &=
nbsp; UnaryPredicate1 unary_predicate1,<br> &n=
bsp; <wbr>UnaryP=
redicate2 unary_predicate2 )<br>{<br> for ( ; first !=3D last; ++first=
)<br> {<br> if ( unary_predicate1( *first ) ) *out1++ =3D =
*first;<br> if ( unary_predicate2( *first ) ) *out2++ =3D *first=
;<br> }</font></div><div><font size=3D"2" face=3D"Consolas"> 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 statement</p><p=
> else if ( unary_predicate2( *first ) ) *out2++ =3D *first;<br>=
</p><p>there is </p><p><font size=3D"2"> 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 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. [ How's that for a deep technical argument?&nbs=
p; ;-) ]</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 <typename InputIterat=
or, typename Predicates, typename Outputs></div><div><span style=3D"whit=
e-space: pre;"> </span>Outputs partition_copy ( 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 ) {<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> <span=
style=3D"white-space: pre;"> </span> 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 Idio Software <<a>mailto:mc..=
..@gmail.com</a>><br><br>A.D. 1517: Martin Luther nails his 95 Theses to =
the church door and is promptly moderated down to (-1, Flamebait).<br> =
; -- Yu Suzuki</span>
</div>
<br></div></div></blockquote><div> </div><div> </div><div>Yes, tw=
o outputs and two predicates. 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< 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> </div></blockquote><div>&n=
bsp;</div><div> </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 the first that will use std::tuple. Why not? </=
div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
<br />
<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 =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 <<a>vlad....@ma=
il.ru</a>> 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 <<a>vlad....@mail.ru</a>>:
<br>>
<br>> =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>> =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:
<br>>> I think this is equivalent:
<br>>>
<br>>> <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>>>
<br>[..]
<br>>
<br>> Thanks. I did not even know that such algorithm already exists in =
the
<br>> standard library. :) 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> </div><div> </div><div>Well, there is no p=
roblem. In this case the thread can be renamed as </div><div> <=
/div><div>"New algorithm partition_copy".:)</div><div> </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> </div><div>I am suggesting to append this algorithm with&=
nbsp;a new modification which is more flexible and will allow to =
do more complex task. Here is its definition</div><div><font size=3D"=
2" face=3D"Consolas"><font size=3D"2" face=3D"Consolas"></font></font> =
;</div><div><font size=3D"2" face=3D"Consolas">template <class InputIter=
ator, <br> class Outp=
utIterator1, <br> cla=
ss OutputIterator2,<br> &nbs=
p; class UnaryPredicate1,<br> &nbs=
p; class UnaryPredicate2><br>std::pair<OutputIterator1, OutputI=
terator2> <br>partition_copy( InputIterator first, InputIterator last,<b=
r> &=
nbsp; OutputIterator1 out1, OutputIterator2 out2,<br> &nbs=
p; &=
nbsp; UnaryPredicate1 unary_predicate1,<br> &n=
bsp; <wbr>UnaryP=
redicate2 unary_predicate2 )<br>{<br> for ( ; first !=3D last; ++first=
)<br> {<br> if ( unary_predicate1( *first ) ) *out1++ =3D =
*first;<br> if ( unary_predicate2( *first ) ) *out2++ =3D *first=
;<br> }</font></div><div><font size=3D"2" face=3D"Consolas"> 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 statement</p><p=
> else if ( unary_predicate2( *first ) ) *out2++ =3D *first;<br>=
</p><p>there is </p><p><font size=3D"2"> 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 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. [ How's that for a deep technical argument?&nbs=
p; ;-) ]</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 <typename InputIterator, =
typename Predicates, typename Outputs></div><div><span style=3D"white-sp=
ace:pre"> </span>Outputs partition_copy ( 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 ) {<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> <span style=3D"whit=
e-space:pre"> </span> 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 Idio Software <<a>mailto:mc...@gm=
ail.com</a>><br><br>A.D. 1517: Martin Luther nails his 95 Theses to the =
church door and is promptly moderated down to (-1, Flamebait).<br> &nb=
sp; -- Yu Suzuki</span>
</div>
<br></div></div></blockquote><div> </div><div> </div><div>Yes, tw=
o outputs and two predicates. 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< 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> </div></blockquote><div>&n=
bsp;</div><div> </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 the first that will use std::tuple. Why not? </=
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;"><</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;">></span><font color=3D"#000066">
</font><font color=3D"#0000ff"><span style=3D"line-height: 13px;">std::tupl=
e<OutputIterators...></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
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);"><</span>OutputIterators...<s=
pan class=3D"sy1" style=3D"line-height: 13px !important; color: rgb(0, 0, 1=
28);">></span> outs,
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);"><</span>Predicates...<span c=
lass=3D"sy1" style=3D"line-height: 13px !important; color: rgb(0, 0, 128);"=
>></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 />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
<br />
<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 =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 =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 <<a>vlad....@mail.ru=
</a>> 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 <<a>vlad....@mail.ru</a>>:
<br>>
<br>> =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>> =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:
<br>>> I think this is equivalent:
<br>>>
<br>>> <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>>>
<br>[..]
<br>>
<br>> Thanks. I did not even know that such algorithm already exists in =
the
<br>> standard library. :) 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> </div><div> </div><div>Well, there is no p=
roblem. In this case the thread can be renamed as </div><div> <=
/div><div>"New algorithm partition_copy".:)</div><div> </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> </div><div>I am suggesting to append this algorithm with&=
nbsp;a new modification which is more flexible and will allow to =
do more complex task. Here is its definition</div><div><font size=3D"=
2" face=3D"Consolas"><font size=3D"2" face=3D"Consolas"></font></font> =
;</div><div><font size=3D"2" face=3D"Consolas">template <class InputIter=
ator, <br> class Outp=
utIterator1, <br> cla=
ss OutputIterator2,<br> &nbs=
p; class UnaryPredicate1,<br> &nbs=
p; class UnaryPredicate2><br>std::pair<OutputIterator1, OutputI=
terator2> <br>partition_copy( InputIterator first, InputIterator last,<b=
r> &=
nbsp; OutputIterator1 out1, OutputIterator2 out2,<br> &nbs=
p; &=
nbsp; UnaryPredicate1 unary_predicate1,<br> &n=
bsp; <wbr>UnaryP=
redicate2 unary_predicate2 )<br>{<br> for ( ; first !=3D last; ++first=
)<br> {<br> if ( unary_predicate1( *first ) ) *out1++ =3D =
*first;<br> if ( unary_predicate2( *first ) ) *out2++ =3D *first=
;<br> }</font></div><div><font size=3D"2" face=3D"Consolas"> 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 statement</p><p=
> else if ( unary_predicate2( *first ) ) *out2++ =3D *first;<br>=
</p><p>there is </p><p><font size=3D"2"> 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 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. [ How's that for a deep technical argument?&nbs=
p; ;-) ]</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 <typename InputIterator, =
typename Predicates, typename Outputs></div><div><span style=3D"white-sp=
ace:pre"> </span>Outputs partition_copy ( 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 ) {<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> <span style=3D"whit=
e-space:pre"> </span> 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 Idio Software <<a>mailto:mc...@gm=
ail.com</a>><br><br>A.D. 1517: Martin Luther nails his 95 Theses to the =
church door and is promptly moderated down to (-1, Flamebait).<br> &nb=
sp; -- Yu Suzuki</span>
</div>
<br></div></div></blockquote><div> </div><div> </div><div>Yes, tw=
o outputs and two predicates. 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< 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> </div></blockquote><div>&n=
bsp;</div><div> </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 the first that will use std::tuple. Why not? </=
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"><</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">></span><font c=
olor=3D"#000066">
</font><font color=3D"#0000ff"><span style=3D"line-height:13px">std::tuple&=
lt;OutputIterators...></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
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)"><</span>OutputIt=
erators...<span style=3D"line-height:13px!important;color:rgb(0,0,128)">>=
;</span> outs,
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)"><</span>Predicat=
es...<span style=3D"line-height:13px!important;color:rgb(0,0,128)">></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 />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
<br />
<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 <<a href=3D"mailto:vlad.moscow@mail.ru">=
vlad.moscow@mail.ru</a>> 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. 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< 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 <here>" 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 <typename Input=
Iterator, typename Predicates, typename Outputs></div><div><span style=
=3D"white-space: pre;"> </span>Outputs partition_copy ( 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 ) {<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> &nb=
sp; <span style=3D"white-space: pre;"> </span> 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> </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 the first that will use std::tuple. W=
hy not? </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 Idio Softwa=
re <<a href=3D"mailto:mclow.lists@gmail.com">mailto:mclow.lists@g=
mail.com</a>><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; -- Yu Suzuki</span>
</div>
<br></body></html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
<br />
<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 =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 <<a h=
ref=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"Wb7CwhwfpC4J=
">vlad....@mail.ru</a>> 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. 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< 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 <here>" 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 <typename InputIterator, type=
name Predicates, typename Outputs></div><div><span style=3D"white-space:=
pre"> </span>Outputs partition_copy ( 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 ) {<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> <span style=3D"white-=
space:pre"> </span> 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> </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 the=
first that will use std::tuple. Why not? </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 Idio Software <<a href=3D"javascr=
ipt:" target=3D"_blank" gdf-obfuscated-mailto=3D"Wb7CwhwfpC4J">mailto:mc...=
@gmail.com</a>><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> =
-- 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 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 />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
<br />
<br />
------=_Part_1569_4759699.1361448904705--
.