Topic: Fixing oversights in algorithm header


Author: =?UTF-8?Q?Martin_Ho=C5=99e=C5=88ovsk=C3=BD?= <martin.horenovsky@gmail.com>
Date: Fri, 20 Feb 2015 11:31:22 -0800 (PST)
Raw View
------=_Part_1174_400758201.1424460682595
Content-Type: multipart/alternative;
 boundary="----=_Part_1175_1034367215.1424460682595"

------=_Part_1175_1034367215.1424460682595
Content-Type: text/plain; charset=UTF-8

I would like to make couple of changes to algorithm header, mostly
additions for symmetry and convenience.

*MOVE_N*
move_n in the following form to the algorithm header, for symmetry with
copy_n.

template< class InputIt, class Size, class OutputIt >
std::pair<InputIt, OutputIt> move_n( InputIt first, Size count, OutputIt
result );

The return type is different from copy_n, because copy_n's return type is
wrong, and I also want to suggest fixing it to

template< class InputIt, class Size, class OutputIt >
std::pair<InputIt, OutputIt> copy_n( InputIt first, Size count, OutputIt
result );

but I am afraid the ship has sailed on that one. (But please remember that
it was added only in C++11 and there won't be that much code depending on
it yet. The longer we wait, the farther the proverbial ship gets.)

The position of returned iterators should be equivalent to position of
first and result iterators after calling std::advance(first, count) and
std::advance(result, count) respectively.

The reason to return InputIt as well is that otherwise we have to iterate
over the elements twice (IE when using std::list<>) and it prevents
composition, ie I have to write this:
std::list<int> data;
std::vector<int> start, rest;
/* fill in data */

std::copy_n(begin(data), 5, std::back_inserter(start)); //Iterating over
list for the first time
auto foo = begin(data);
std::advance(foo, 5); //Iterating over list again
std::copy(foo, end(data), std::back_inserter(rest));


instead of this
std::list<int> data;
std::vector<int> start, rest;
/* fill in data */

std::copy(std::copy_n(begin(data), 5, std::back_inserter(start)).first,
        end(data),
        std::back_inserter(rest));



*MOVE_IF*
There also seems to be missing move_if, but I am not sure if it should be
added. On one hand, I can easily see where it can be useful, on the other,
it seems that it would be too easy to use it wrong and try to work with
moved-from objects.
Pros

   - There are cases where it could be useful.
   - Convenience over for loops and move_iterators
   - Symmetry

Cons

   - Possibly easy to misuse.
   - Is only convenience over for loops and using move_iterators


*REVERSE_MOVE, UNIQUE_MOVE, ROTATE_MOVE*
There are also missing convenience functions reverse_move, unique_move,
rotate_move (to complement reverse_copy, unique_copy and rotate_copy). I
suggest putting these in as well, but I think they have the least priority.
Pros

   - There are cases where they could be useful
   - Convenience over using move_iterators
   - Symmetry

Cons

   - Possibly easy to misuse.
   - Probably will be used only rarely


*PARTITION_MOVE*
Complement to partition_copy. I really don't have anything new to say about
it.





I might have forgotten some algorithms and inconsistencies, if so please
tell me.

Also I am horribly sorry if some of the formatting is broken.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

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

<div dir=3D"ltr">I would like to make couple of changes to algorithm header=
, mostly additions for symmetry and convenience.<div><br><div><b>MOVE_N</b>=
</div><div>move_n in the following form to the algorithm header, for symmet=
ry with copy_n.<div><br></div><div><div class=3D"prettyprint" style=3D"bord=
er: 1px solid rgb(187, 187, 187); word-wrap: break-word; background-color: =
rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"subprettypri=
nt"><table class=3D"t-dcl-begin" style=3D"font-size: 12.8000001907349px; di=
splay: block; padding-top: 0.5em; padding-bottom: 0.5em; color: rgb(0, 0, 0=
); font-family: DejaVuSans, 'DejaVu Sans', arial, sans-serif; line-height: =
15.3600006103516px; background-color: rgb(255, 255, 255);"><tbody><tr class=
=3D"t-dcl t-since-cxx11"><td style=3D"border-top-width: 1px; border-top-sty=
le: solid; border-top-color: rgb(204, 204, 204); padding: 0.3em 2em 0.2em 1=
em; font-size: 1em;"><span class=3D"mw-geshi cpp source-cpp" style=3D"font-=
family: monospace; line-height: 1.1em; white-space: nowrap;"><span class=3D=
"kw1" style=3D"line-height: 1.1em; color: rgb(0, 0, 221);"><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">template</span></span><span class=
=3D"sy1" style=3D"line-height: 1.1em; color: rgb(0, 0, 128);"><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span></span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span class=3D"kw1"=
 style=3D"line-height: 1.1em; color: rgb(0, 0, 221);"><span style=3D"color:=
 #008;" class=3D"styled-by-prettify">class</span></span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;"=
 class=3D"styled-by-prettify">InputIt</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span class=3D"kw1" style=3D"line-height: 1.1em; =
color: rgb(0, 0, 221);"><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">class</span></span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">=
Size</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span c=
lass=3D"kw1" style=3D"line-height: 1.1em; color: rgb(0, 0, 221);"><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">class</span></span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #606;" class=3D"styled-by-prettify">OutputIt</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span class=3D"sy1" style=
=3D"line-height: 1.1em; color: rgb(0, 0, 128);"><span style=3D"color: #660;=
" class=3D"styled-by-prettify">&gt;</span></span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br>std</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">pair</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&lt;</span><span style=3D"color: #606;" class=3D"styled-by-p=
rettify">InputIt</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #606;" class=3D"styled-by-prettify">OutputIt</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> move_n</span><span =
class=3D"br0" style=3D"line-height: 1.1em; color: rgb(0, 128, 0);"><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">(</span></span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #606;" class=3D"styled-by-prettify">InputIt</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> first</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">Size</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> count</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #606;" class=3D"styled-by-prettify">OutputIt</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> result </span>=
<span class=3D"br0" style=3D"line-height: 1.1em; color: rgb(0, 128, 0);"><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">)</span></span><spa=
n class=3D"sy4" style=3D"line-height: 1.1em; color: rgb(0, 128, 128);"><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">;</span></span></span=
></td><td class=3D"t-dcl-nopad" style=3D"padding-right: 1.5em; border-top-w=
idth: 1px; border-top-style: solid; border-top-color: rgb(204, 204, 204); f=
ont-size: 0.8em;"></td></tr></tbody></table></div></code></div><div><br></d=
iv><div>The return type is different from copy_n, because copy_n's return t=
ype is wrong, and I also want to suggest fixing it to</div><div><br></div><=
div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187=
); word-wrap: break-word; background-color: rgb(250, 250, 250);"><code clas=
s=3D"prettyprint"><div class=3D"subprettyprint"><table class=3D"t-dcl-begin=
" style=3D"font-size: 12.8000001907349px; display: block; padding-top: 0.5e=
m; padding-bottom: 0.5em; color: rgb(0, 0, 0); font-family: DejaVuSans, 'De=
jaVu Sans', arial, sans-serif; line-height: 15.3600006103516px; background-=
color: rgb(255, 255, 255);"><tbody><tr class=3D"t-dcl t-since-cxx11"><td st=
yle=3D"border-top-width: 1px; border-top-style: solid; border-top-color: rg=
b(204, 204, 204); padding: 0.3em 2em 0.2em 1em; font-size: 1em;"><span clas=
s=3D"mw-geshi cpp source-cpp" style=3D"font-family: monospace; line-height:=
 1.1em; white-space: nowrap;"><span class=3D"kw1" style=3D"line-height: 1.1=
em; color: rgb(0, 0, 221);"><span style=3D"color: #008;" class=3D"styled-by=
-prettify">template</span></span><span class=3D"sy1" style=3D"line-height: =
1.1em; color: rgb(0, 0, 128);"><span style=3D"color: #660;" class=3D"styled=
-by-prettify">&lt;</span></span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span class=3D"kw1" style=3D"line-height: 1.1em; col=
or: rgb(0, 0, 221);"><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">class</span></span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Inp=
utIt</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span c=
lass=3D"kw1" style=3D"line-height: 1.1em; color: rgb(0, 0, 221);"><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">class</span></span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #606;" class=3D"styled-by-prettify">Size</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span class=3D"kw1" style=3D"line-height=
: 1.1em; color: rgb(0, 0, 221);"><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">class</span></span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-p=
rettify">OutputIt</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span class=3D"sy1" style=3D"line-height: 1.1em; color: rgb(=
0, 0, 128);"><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;=
</span></span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">pair</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span sty=
le=3D"color: #606;" class=3D"styled-by-prettify">InputIt</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" =
class=3D"styled-by-prettify">OutputIt</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> copy_n</span><span class=3D"br0" style=3D"line-height=
: 1.1em; color: rgb(0, 128, 0);"><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">(</span></span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prett=
ify">InputIt</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> first</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #606;" class=3D"styled-by-prettify">Size</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> count</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" =
class=3D"styled-by-prettify">OutputIt</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> result </span><span class=3D"br0" style=3D"line=
-height: 1.1em; color: rgb(0, 128, 0);"><span style=3D"color: #660;" class=
=3D"styled-by-prettify">)</span></span><span class=3D"sy4" style=3D"line-he=
ight: 1.1em; color: rgb(0, 128, 128);"><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span></span></span></td><td class=3D"t-dcl-nopad=
" style=3D"padding-right: 1.5em; border-top-width: 1px; border-top-style: s=
olid; border-top-color: rgb(204, 204, 204); font-size: 0.8em;"></td></tr></=
tbody></table></div></code></div><br>but I am afraid the ship has sailed on=
 that one. (But please remember that it was added only in C++11 and there w=
on't be that much code depending on it yet. The longer we wait, the farther=
 the proverbial ship gets.)</div><div><br></div><div>The position of return=
ed iterators should be equivalent to position of first and result iterators=
 after calling std::advance(first, count) and std::advance(result, count) r=
espectively.</div><div><br></div><div>The reason to return InputIt as well =
is that otherwise we have to iterate over the elements twice (IE when using=
 std::list&lt;&gt;) and it prevents composition, ie I have to write this:</=
div><div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187=
, 187); word-wrap: break-word; background-color: rgb(250, 250, 250);"><code=
 class=3D"prettyprint"><div class=3D"subprettyprint"><span class=3D"styled-=
by-prettify"><div class=3D"subprettyprint"><div class=3D"subprettyprint">st=
d::list&lt;int&gt; data;</div><div class=3D"subprettyprint">std::vector&lt;=
int&gt; start, rest;</div><div class=3D"subprettyprint">/* fill in data */<=
/div><div class=3D"subprettyprint"><span class=3D"Apple-tab-span" style=3D"=
white-space:pre"><br>s</span>td::copy_n(begin(data), 5, std::back_inserter(=
start)); //Iterating over list for the first time<br>auto foo =3D begin(dat=
a);<br>std::advance(foo, 5); //Iterating over list again<br></div><div clas=
s=3D"subprettyprint">std::copy(foo,&nbsp;<span style=3D"font-family: Arial,=
 Helvetica, sans-serif;">end(data),&nbsp;</span><span style=3D"font-family:=
 Arial, Helvetica, sans-serif;">std::back_inserter(rest));</span></div><div=
><br></div></div></span></div></code></div><br></div><div>instead of this</=
div><div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187=
, 187); word-wrap: break-word; background-color: rgb(250, 250, 250);"><code=
 class=3D"prettyprint"><div class=3D"subprettyprint"><div class=3D"subprett=
yprint"><div class=3D"subprettyprint">std::list&lt;int&gt; data;</div><div =
class=3D"subprettyprint">std::vector&lt;int&gt; start, rest;</div><div clas=
s=3D"subprettyprint">/* fill in data */</div><div class=3D"subprettyprint">=
<span style=3D"font-family: Arial, Helvetica, sans-serif;"><br>std::copy(st=
d::copy_n(begin(data), 5, std::back_inserter(start)).first,</span><br></div=
><div class=3D"subprettyprint">&nbsp; &nbsp; &nbsp; &nbsp; end(data),</div>=
<div class=3D"subprettyprint">&nbsp; &nbsp; &nbsp; &nbsp; std::back_inserte=
r(rest));<br><br></div></div></div></code></div></div></div><div><br></div>=
<div><br></div><div><b>MOVE_IF</b></div><div>There also seems to be missing=
 move_if, but I am not sure if it should be added. On one hand, I can easil=
y see where it can be useful, on the other, it seems that it would be too e=
asy to use it wrong and try to work with moved-from objects.</div><div>Pros=
&nbsp;</div><div><ul><li><span style=3D"line-height: normal;">There are cas=
es where it could be useful.</span></li><li><span style=3D"line-height: nor=
mal;">Convenience over for loops and move_iterators</span></li><li><span st=
yle=3D"line-height: normal;">Symmetry</span></li></ul></div><div>Cons</div>=
<div><ul><li><span style=3D"line-height: normal;">Possibly easy to misuse.<=
/span></li><li><span style=3D"line-height: normal;">Is only convenience ove=
r for loops and using move_iterators</span></li></ul></div><div><br></div><=
div><b>REVERSE_MOVE, UNIQUE_MOVE, ROTATE_MOVE</b></div><div>There are also =
missing convenience functions reverse_move, unique_move, rotate_move (to co=
mplement reverse_copy, unique_copy and rotate_copy). I suggest putting thes=
e in as well, but I think they have the least priority.</div><div>Pros</div=
><div><ul><li><span style=3D"line-height: normal;">There are cases where th=
ey could be useful</span></li><li><span style=3D"line-height: normal;">Conv=
enience over using move_iterators</span></li><li><span style=3D"line-height=
: normal;">Symmetry</span></li></ul><div>Cons</div></div><div><ul><li><span=
 style=3D"line-height: normal;">Possibly easy to misuse.</span></li><li><sp=
an style=3D"line-height: normal;">Probably will be used only rarely</span><=
/li></ul><div><b><br></b></div><div><b>PARTITION_MOVE</b></div></div><div>C=
omplement to partition_copy. I really don't have anything new to say about =
it.</div><div><br></div><div><br></div><div><br></div><div><br></div><div><=
br></div><div>I might have forgotten some algorithms and inconsistencies, i=
f so please tell me.</div><div><br></div><div>Also I am horribly sorry if s=
ome of the formatting is broken.</div></div></div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_1175_1034367215.1424460682595--
------=_Part_1174_400758201.1424460682595--

.


Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Fri, 20 Feb 2015 11:51:11 -0800 (PST)
Raw View
------=_Part_1060_1189626209.1424461871581
Content-Type: multipart/alternative;
 boundary="----=_Part_1061_974941093.1424461871582"

------=_Part_1061_974941093.1424461871582
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

I would not change the return type of the algorithms. Instead of this I=20
suggest to allow to use iterators for some algorithms by reference.

See this thread with the corresponding discussion.

https://groups.google.com/a/isocpp.org/forum/#!topic/std-discussion/lCuvU-2=
MPes

On Friday, February 20, 2015 at 10:31:22 PM UTC+3, Martin Ho=C5=99e=C5=88ov=
sk=C3=BD wrote:

> I would like to make couple of changes to algorithm header, mostly=20
> additions for symmetry and convenience.
>
> *MOVE_N*
> move_n in the following form to the algorithm header, for symmetry with=
=20
> copy_n.
>
> template< class InputIt, class Size, class OutputIt >
> std::pair<InputIt, OutputIt> move_n( InputIt first, Size count, OutputIt=
=20
> result );
>
> The return type is different from copy_n, because copy_n's return type is=
=20
> wrong, and I also want to suggest fixing it to
>
> template< class InputIt, class Size, class OutputIt >
> std::pair<InputIt, OutputIt> copy_n( InputIt first, Size count, OutputIt=
=20
> result );
>
> but I am afraid the ship has sailed on that one. (But please remember tha=
t=20
> it was added only in C++11 and there won't be that much code depending on=
=20
> it yet. The longer we wait, the farther the proverbial ship gets.)
>
> The position of returned iterators should be equivalent to position of=20
> first and result iterators after calling std::advance(first, count) and=
=20
> std::advance(result, count) respectively.
>
> The reason to return InputIt as well is that otherwise we have to iterate=
=20
> over the elements twice (IE when using std::list<>) and it prevents=20
> composition, ie I have to write this:
> std::list<int> data;
> std::vector<int> start, rest;
> /* fill in data */
>
> std::copy_n(begin(data), 5, std::back_inserter(start)); //Iterating over=
=20
> list for the first time
> auto foo =3D begin(data);
> std::advance(foo, 5); //Iterating over list again
> std::copy(foo, end(data), std::back_inserter(rest));
>
>
> instead of this
> std::list<int> data;
> std::vector<int> start, rest;
> /* fill in data */
>
> std::copy(std::copy_n(begin(data), 5, std::back_inserter(start)).first,
>         end(data),
>         std::back_inserter(rest));
>
>
>
> *MOVE_IF*
> There also seems to be missing move_if, but I am not sure if it should be=
=20
> added. On one hand, I can easily see where it can be useful, on the other=
,=20
> it seems that it would be too easy to use it wrong and try to work with=
=20
> moved-from objects.
> Pros=20
>
>    - There are cases where it could be useful.
>    - Convenience over for loops and move_iterators
>    - Symmetry
>
> Cons
>
>    - Possibly easy to misuse.
>    - Is only convenience over for loops and using move_iterators
>
>
> *REVERSE_MOVE, UNIQUE_MOVE, ROTATE_MOVE*
> There are also missing convenience functions reverse_move, unique_move,=
=20
> rotate_move (to complement reverse_copy, unique_copy and rotate_copy). I=
=20
> suggest putting these in as well, but I think they have the least priorit=
y.
> Pros
>
>    - There are cases where they could be useful
>    - Convenience over using move_iterators
>    - Symmetry
>
> Cons
>
>    - Possibly easy to misuse.
>    - Probably will be used only rarely
>
>
> *PARTITION_MOVE*
> Complement to partition_copy. I really don't have anything new to say=20
> about it.
>
>
>
>
>
> I might have forgotten some algorithms and inconsistencies, if so please=
=20
> tell me.
>
> Also I am horribly sorry if some of the formatting is broken.
>

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

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

<div dir=3D"ltr"><div>I would not change the return type of the algorithms.=
 Instead of this I suggest to allow to use iterators for some algorithms by=
 reference.</div><div><br></div><div>See this thread with the corresponding=
 discussion.</div><div><br></div><div><a href=3D"https://groups.google.com/=
a/isocpp.org/forum/#!topic/std-discussion/lCuvU-2MPes">https://groups.googl=
e.com/a/isocpp.org/forum/#!topic/std-discussion/lCuvU-2MPes</a><br><br>On F=
riday, February 20, 2015 at 10:31:22 PM UTC+3, Martin Ho=C5=99e=C5=88ovsk=
=C3=BD wrote:</div><blockquote class=3D"gmail_quote" style=3D"margin: 0px 0=
px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); bor=
der-left-width: 1px; border-left-style: solid;"><div dir=3D"ltr">I would li=
ke to make couple of changes to algorithm header, mostly additions for symm=
etry and convenience.<div><br><div><b>MOVE_N</b></div><div>move_n in the fo=
llowing form to the algorithm header, for symmetry with copy_n.<div><br></d=
iv><div><div style=3D"border: 1px solid rgb(187, 187, 187); border-image: n=
one; -ms-word-wrap: break-word; background-color: rgb(250, 250, 250);"><cod=
e><div><table style=3D'color: rgb(0, 0, 0); line-height: 15.36px; padding-t=
op: 0.5em; padding-bottom: 0.5em; font-family: DejaVuSans,"DejaVu Sans",ari=
al,sans-serif; font-size: 12.8px; display: block; background-color: rgb(255=
, 255, 255);'><tbody><tr><td style=3D"padding: 0.3em 2em 0.2em 1em; font-si=
ze: 1em; border-top-color: rgb(204, 204, 204); border-top-width: 1px; borde=
r-top-style: solid;"><span style=3D"line-height: 1.1em; font-family: monosp=
ace; white-space: nowrap;"><span style=3D"color: rgb(0, 0, 221); line-heigh=
t: 1.1em;"><span style=3D"color: rgb(0, 0, 136);">template</span></span><sp=
an style=3D"color: rgb(0, 0, 128); line-height: 1.1em;"><span style=3D"colo=
r: rgb(102, 102, 0);">&lt;</span></span><span style=3D"color: rgb(0, 0, 0);=
"> </span><span style=3D"color: rgb(0, 0, 221); line-height: 1.1em;"><span =
style=3D"color: rgb(0, 0, 136);">class</span></span><span style=3D"color: r=
gb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 0, 102);">InputIt</spa=
n><span style=3D"color: rgb(102, 102, 0);">,</span><span style=3D"color: rg=
b(0, 0, 0);"> </span><span style=3D"color: rgb(0, 0, 221); line-height: 1.1=
em;"><span style=3D"color: rgb(0, 0, 136);">class</span></span><span style=
=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 0, 102);">=
Size</span><span style=3D"color: rgb(102, 102, 0);">,</span><span style=3D"=
color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(0, 0, 221); line-he=
ight: 1.1em;"><span style=3D"color: rgb(0, 0, 136);">class</span></span><sp=
an style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 0,=
 102);">OutputIt</span><span style=3D"color: rgb(0, 0, 0);"> </span><span s=
tyle=3D"color: rgb(0, 0, 128); line-height: 1.1em;"><span style=3D"color: r=
gb(102, 102, 0);">&gt;</span></span><span style=3D"color: rgb(0, 0, 0);"><b=
r>std</span><span style=3D"color: rgb(102, 102, 0);">::</span><span style=
=3D"color: rgb(0, 0, 0);">pair</span><span style=3D"color: rgb(102, 102, 0)=
;">&lt;</span><span style=3D"color: rgb(102, 0, 102);">InputIt</span><span =
style=3D"color: rgb(102, 102, 0);">,</span><span style=3D"color: rgb(0, 0, =
0);"> </span><span style=3D"color: rgb(102, 0, 102);">OutputIt</span><span =
style=3D"color: rgb(102, 102, 0);">&gt;</span><span style=3D"color: rgb(0, =
0, 0);"> move_n</span><span style=3D"color: rgb(0, 128, 0); line-height: 1.=
1em;"><span style=3D"color: rgb(102, 102, 0);">(</span></span><span style=
=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 0, 102);">=
InputIt</span><span style=3D"color: rgb(0, 0, 0);"> first</span><span style=
=3D"color: rgb(102, 102, 0);">,</span><span style=3D"color: rgb(0, 0, 0);">=
 </span><span style=3D"color: rgb(102, 0, 102);">Size</span><span style=3D"=
color: rgb(0, 0, 0);"> count</span><span style=3D"color: rgb(102, 102, 0);"=
>,</span><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color:=
 rgb(102, 0, 102);">OutputIt</span><span style=3D"color: rgb(0, 0, 0);"> re=
sult </span><span style=3D"color: rgb(0, 128, 0); line-height: 1.1em;"><spa=
n style=3D"color: rgb(102, 102, 0);">)</span></span><span style=3D"color: r=
gb(0, 128, 128); line-height: 1.1em;"><span style=3D"color: rgb(102, 102, 0=
);">;</span></span></span></td><td style=3D"padding-right: 1.5em; font-size=
: 0.8em; border-top-color: rgb(204, 204, 204); border-top-width: 1px; borde=
r-top-style: solid;"></td></tr></tbody></table></div></code></div><div><br>=
</div><div>The return type is different from copy_n, because copy_n's retur=
n type is wrong, and I also want to suggest fixing it to</div><div><br></di=
v><div><div style=3D"border: 1px solid rgb(187, 187, 187); border-image: no=
ne; -ms-word-wrap: break-word; background-color: rgb(250, 250, 250);"><code=
><div><table style=3D'color: rgb(0, 0, 0); line-height: 15.36px; padding-to=
p: 0.5em; padding-bottom: 0.5em; font-family: DejaVuSans,"DejaVu Sans",aria=
l,sans-serif; font-size: 12.8px; display: block; background-color: rgb(255,=
 255, 255);'><tbody><tr><td style=3D"padding: 0.3em 2em 0.2em 1em; font-siz=
e: 1em; border-top-color: rgb(204, 204, 204); border-top-width: 1px; border=
-top-style: solid;"><span style=3D"line-height: 1.1em; font-family: monospa=
ce; white-space: nowrap;"><span style=3D"color: rgb(0, 0, 221); line-height=
: 1.1em;"><span style=3D"color: rgb(0, 0, 136);">template</span></span><spa=
n style=3D"color: rgb(0, 0, 128); line-height: 1.1em;"><span style=3D"color=
: rgb(102, 102, 0);">&lt;</span></span><span style=3D"color: rgb(0, 0, 0);"=
> </span><span style=3D"color: rgb(0, 0, 221); line-height: 1.1em;"><span s=
tyle=3D"color: rgb(0, 0, 136);">class</span></span><span style=3D"color: rg=
b(0, 0, 0);"> </span><span style=3D"color: rgb(102, 0, 102);">InputIt</span=
><span style=3D"color: rgb(102, 102, 0);">,</span><span style=3D"color: rgb=
(0, 0, 0);"> </span><span style=3D"color: rgb(0, 0, 221); line-height: 1.1e=
m;"><span style=3D"color: rgb(0, 0, 136);">class</span></span><span style=
=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 0, 102);">=
Size</span><span style=3D"color: rgb(102, 102, 0);">,</span><span style=3D"=
color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(0, 0, 221); line-he=
ight: 1.1em;"><span style=3D"color: rgb(0, 0, 136);">class</span></span><sp=
an style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 0,=
 102);">OutputIt</span><span style=3D"color: rgb(0, 0, 0);"> </span><span s=
tyle=3D"color: rgb(0, 0, 128); line-height: 1.1em;"><span style=3D"color: r=
gb(102, 102, 0);">&gt;</span></span><span style=3D"color: rgb(0, 0, 0);"><b=
r>std</span><span style=3D"color: rgb(102, 102, 0);">::</span><span style=
=3D"color: rgb(0, 0, 0);">pair</span><span style=3D"color: rgb(102, 102, 0)=
;">&lt;</span><span style=3D"color: rgb(102, 0, 102);">InputIt</span><span =
style=3D"color: rgb(102, 102, 0);">,</span><span style=3D"color: rgb(0, 0, =
0);"> </span><span style=3D"color: rgb(102, 0, 102);">OutputIt</span><span =
style=3D"color: rgb(102, 102, 0);">&gt;</span><span style=3D"color: rgb(0, =
0, 0);"> copy_n</span><span style=3D"color: rgb(0, 128, 0); line-height: 1.=
1em;"><span style=3D"color: rgb(102, 102, 0);">(</span></span><span style=
=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 0, 102);">=
InputIt</span><span style=3D"color: rgb(0, 0, 0);"> first</span><span style=
=3D"color: rgb(102, 102, 0);">,</span><span style=3D"color: rgb(0, 0, 0);">=
 </span><span style=3D"color: rgb(102, 0, 102);">Size</span><span style=3D"=
color: rgb(0, 0, 0);"> count</span><span style=3D"color: rgb(102, 102, 0);"=
>,</span><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color:=
 rgb(102, 0, 102);">OutputIt</span><span style=3D"color: rgb(0, 0, 0);"> re=
sult </span><span style=3D"color: rgb(0, 128, 0); line-height: 1.1em;"><spa=
n style=3D"color: rgb(102, 102, 0);">)</span></span><span style=3D"color: r=
gb(0, 128, 128); line-height: 1.1em;"><span style=3D"color: rgb(102, 102, 0=
);">;</span></span></span></td><td style=3D"padding-right: 1.5em; font-size=
: 0.8em; border-top-color: rgb(204, 204, 204); border-top-width: 1px; borde=
r-top-style: solid;"></td></tr></tbody></table></div></code></div><br>but I=
 am afraid the ship has sailed on that one. (But please remember that it wa=
s added only in C++11 and there won't be that much code depending on it yet=
.. The longer we wait, the farther the proverbial ship gets.)</div><div><br>=
</div><div>The position of returned iterators should be equivalent to posit=
ion of first and result iterators after calling std::advance(first, count) =
and std::advance(result, count) respectively.</div><div><br></div><div>The =
reason to return InputIt as well is that otherwise we have to iterate over =
the elements twice (IE when using std::list&lt;&gt;) and it prevents compos=
ition, ie I have to write this:</div><div><div style=3D"border: 1px solid r=
gb(187, 187, 187); border-image: none; -ms-word-wrap: break-word; backgroun=
d-color: rgb(250, 250, 250);"><code><div><span><div><div>std::list&lt;int&g=
t; data;</div><div>std::vector&lt;int&gt; start, rest;</div><div>/* fill in=
 data */</div><div><span style=3D"white-space: pre;"><br>s</span>td::copy_n=
(begin(data), 5, std::back_inserter(start)); //Iterating over list for the =
first time<br>auto foo =3D begin(data);<br>std::advance(foo, 5); //Iteratin=
g over list again<br></div><div>std::copy(foo,&nbsp;<span style=3D"font-fam=
ily: Arial,Helvetica,sans-serif;">end(data),&nbsp;</span><span style=3D"fon=
t-family: Arial,Helvetica,sans-serif;">std:<wbr>:back_inserter(rest));</spa=
n></div><div><br></div></div></span></div></code></div><br></div><div>inste=
ad of this</div><div><div style=3D"border: 1px solid rgb(187, 187, 187); bo=
rder-image: none; -ms-word-wrap: break-word; background-color: rgb(250, 250=
, 250);"><code><div><div><div>std::list&lt;int&gt; data;</div><div>std::vec=
tor&lt;int&gt; start, rest;</div><div>/* fill in data */</div><div><span st=
yle=3D"font-family: Arial,Helvetica,sans-serif;"><br>std::copy(std::copy_n(=
begin(<wbr>data), 5, std::back_inserter(start)).<wbr>first,</span><br></div=
><div>&nbsp; &nbsp; &nbsp; &nbsp; end(data),</div><div>&nbsp; &nbsp; &nbsp;=
 &nbsp; std::back_inserter(rest));<br><br></div></div></div></code></div></=
div></div><div><br></div><div><br></div><div><b>MOVE_IF</b></div><div>There=
 also seems to be missing move_if, but I am not sure if it should be added.=
 On one hand, I can easily see where it can be useful, on the other, it see=
ms that it would be too easy to use it wrong and try to work with moved-fro=
m objects.</div><div>Pros&nbsp;</div><div><ul><li><span style=3D"line-heigh=
t: normal;">There are cases where it could be useful.</span></li><li><span =
style=3D"line-height: normal;">Convenience over for loops and move_iterator=
s</span></li><li><span style=3D"line-height: normal;">Symmetry</span></li><=
/ul></div><div>Cons</div><div><ul><li><span style=3D"line-height: normal;">=
Possibly easy to misuse.</span></li><li><span style=3D"line-height: normal;=
">Is only convenience over for loops and using move_iterators</span></li></=
ul></div><div><br></div><div><b>REVERSE_MOVE, UNIQUE_MOVE, ROTATE_MOVE</b><=
/div><div>There are also missing convenience functions reverse_move, unique=
_move, rotate_move (to complement reverse_copy, unique_copy and rotate_copy=
). I suggest putting these in as well, but I think they have the least prio=
rity.</div><div>Pros</div><div><ul><li><span style=3D"line-height: normal;"=
>There are cases where they could be useful</span></li><li><span style=3D"l=
ine-height: normal;">Convenience over using move_iterators</span></li><li><=
span style=3D"line-height: normal;">Symmetry</span></li></ul><div>Cons</div=
></div><div><ul><li><span style=3D"line-height: normal;">Possibly easy to m=
isuse.</span></li><li><span style=3D"line-height: normal;">Probably will be=
 used only rarely</span></li></ul><div><b><br></b></div><div><b>PARTITION_M=
OVE</b></div></div><div>Complement to partition_copy. I really don't have a=
nything new to say about it.</div><div><br></div><div><br></div><div><br></=
div><div><br></div><div><br></div><div>I might have forgotten some algorith=
ms and inconsistencies, if so please tell me.</div><div><br></div><div>Also=
 I am horribly sorry if some of the formatting is broken.</div></div></div>=
</div></blockquote></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_1061_974941093.1424461871582--
------=_Part_1060_1189626209.1424461871581--

.


Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Sat, 21 Feb 2015 03:05:43 -0800 (PST)
Raw View
------=_Part_180_2122844049.1424516743411
Content-Type: multipart/alternative;
 boundary="----=_Part_181_346620285.1424516743411"

------=_Part_181_346620285.1424516743411
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Here is a demonstrative example of the approach

#include <iostream>
#include <iterator>
#include <algorithm>
#include <list>
template <class InputIterator, class OutputIterator>
OutputIterator copy( InputIterator first,
                     InputIterator last,
                     OutputIterator result )
{
 for ( ; first !=3D last; ++first, ++result ) *result =3D *first;
=20
 return result;
}
template<class InputIterator, class Size, class OutputIterator>
OutputIterator copy_n( InputIterator first,=20
                       Size n,
                       OutputIterator result )
{
 for ( Size i =3D Size(); i !=3D n; ++i, ++first, ++result ) *result =3D *f=
irst;
=20
 return result;
}                      =20
int main()=20
{
 {
  std::list<int> l =3D { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  auto it =3D l.begin();
  ::copy_n<decltype( it ) &>( it, l.size() / 2,=20
                         std::ostream_iterator<int>( std::cout, " " ) );
  std::cout << std::endl;
 =20
  l.insert( it, 0 );
 =20
  for ( int x : l ) std::cout << x << ' ';
  std::cout << std::endl;
 }
 {
  const size_t N =3D 3;
  int a[N][N] =3D
  {
   { 1, 2, 3 },
   { 4, 5, 6 },
   { 7, 8, 9 }
  };
 =20
  int b[2 * N + 1];
 =20
  int *last =3D b;
  size_t i =3D 0;
 =20
  while ( i < N &&
          ::copy<int *, int * &>( std::begin( a[i] ),=20
                                 std::end( a[i] ),=20
                                 last ) <=3D std::prev( std::end( b ), N ) =
)=20
++i;
  for ( auto it =3D b; it !=3D last; ++it ) std::cout << *it << ' ';
  std::cout << std::endl;
 }
}=20

The program output is

0 1 2 3 4=20
0 1 2 3 4 0 5 6 7 8 9=20
1 2 3 4 5 6=20

Thus simply for some algorithms there should be written moreclearly in the=
=20
C++ Standard what is the value of the iterator passed by reference after=20
exiting the algorithm


On Friday, February 20, 2015 at 10:51:11 PM UTC+3, Vlad from Moscow wrote:

> I would not change the return type of the algorithms. Instead of this I=
=20
> suggest to allow to use iterators for some algorithms by reference.
>
> See this thread with the corresponding discussion.
>
>
> https://groups.google.com/a/isocpp.org/forum/#!topic/std-discussion/lCuvU=
-2MPes
>
> On Friday, February 20, 2015 at 10:31:22 PM UTC+3, Martin Ho=C5=99e=C5=88=
ovsk=C3=BD wrote:
>
>> I would like to make couple of changes to algorithm header, mostly=20
>> additions for symmetry and convenience.
>>
>> *MOVE_N*
>> move_n in the following form to the algorithm header, for symmetry with=
=20
>> copy_n.
>>
>> template< class InputIt, class Size, class OutputIt >
>> std::pair<InputIt, OutputIt> move_n( InputIt first, Size count, OutputIt=
=20
>> result );
>>
>> The return type is different from copy_n, because copy_n's return type i=
s=20
>> wrong, and I also want to suggest fixing it to
>>
>> template< class InputIt, class Size, class OutputIt >
>> std::pair<InputIt, OutputIt> copy_n( InputIt first, Size count, OutputIt=
=20
>> result );
>>
>> but I am afraid the ship has sailed on that one. (But please remember=20
>> that it was added only in C++11 and there won't be that much code depend=
ing=20
>> on it yet. The longer we wait, the farther the proverbial ship gets.)
>>
>> The position of returned iterators should be equivalent to position of=
=20
>> first and result iterators after calling std::advance(first, count) and=
=20
>> std::advance(result, count) respectively.
>>
>> The reason to return InputIt as well is that otherwise we have to iterat=
e=20
>> over the elements twice (IE when using std::list<>) and it prevents=20
>> composition, ie I have to write this:
>> std::list<int> data;
>> std::vector<int> start, rest;
>> /* fill in data */
>>
>> std::copy_n(begin(data), 5, std::back_inserter(start)); //Iterating over=
=20
>> list for the first time
>> auto foo =3D begin(data);
>> std::advance(foo, 5); //Iterating over list again
>> std::copy(foo, end(data), std::back_inserter(rest));
>>
>>
>> instead of this
>> std::list<int> data;
>> std::vector<int> start, rest;
>> /* fill in data */
>>
>> std::copy(std::copy_n(begin(data), 5, std::back_inserter(start)).first,
>>         end(data),
>>         std::back_inserter(rest));
>>
>>
>>
>> *MOVE_IF*
>> There also seems to be missing move_if, but I am not sure if it should b=
e=20
>> added. On one hand, I can easily see where it can be useful, on the othe=
r,=20
>> it seems that it would be too easy to use it wrong and try to work with=
=20
>> moved-from objects.
>> Pros=20
>>
>>    - There are cases where it could be useful.
>>    - Convenience over for loops and move_iterators
>>    - Symmetry
>>
>> Cons
>>
>>    - Possibly easy to misuse.
>>    - Is only convenience over for loops and using move_iterators
>>
>>
>> *REVERSE_MOVE, UNIQUE_MOVE, ROTATE_MOVE*
>> There are also missing convenience functions reverse_move, unique_move,=
=20
>> rotate_move (to complement reverse_copy, unique_copy and rotate_copy). I=
=20
>> suggest putting these in as well, but I think they have the least priori=
ty.
>> Pros
>>
>>    - There are cases where they could be useful
>>    - Convenience over using move_iterators
>>    - Symmetry
>>
>> Cons
>>
>>    - Possibly easy to misuse.
>>    - Probably will be used only rarely
>>
>>
>> *PARTITION_MOVE*
>> Complement to partition_copy. I really don't have anything new to say=20
>> about it.
>>
>>
>>
>>
>>
>> I might have forgotten some algorithms and inconsistencies, if so please=
=20
>> tell me.
>>
>> Also I am horribly sorry if some of the formatting is broken.
>>
>

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

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

<div dir=3D"ltr"><div>Here is a demonstrative example of the approach</div>=
<div><br></div><div>#include &lt;iostream&gt;<br>#include &lt;iterator&gt;<=
br>#include &lt;algorithm&gt;<br>#include &lt;list&gt;</div><div>template &=
lt;class InputIterator, class OutputIterator&gt;<br>OutputIterator copy( In=
putIterator first,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InputIt=
erator last,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OutputIterato=
r result )<br>{<br>&nbsp;for ( ; first !=3D last; ++first, ++result ) *resu=
lt =3D *first;<br>&nbsp;<br>&nbsp;return result;<br>}</div><div>template&lt=
;class InputIterator, class Size, class OutputIterator&gt;</div><div>Output=
Iterator copy_n( InputIterator first, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp; Size n,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp; OutputIterator result )<br>{<br>&nbsp;for ( Size i =3D S=
ize(); i !=3D n; ++i, ++first, ++result ) *result =3D *first;<br>&nbsp;<br>=
&nbsp;return result;<br>}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp; </div><div>int main() <br>{<br>&nbsp;{<br>&nbsp;&nbsp;std::list&lt;=
int&gt; l =3D { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };</div><div>&nbsp;&nbsp;auto =
it =3D l.begin();</div><div>&nbsp;&nbsp;::copy_n&lt;decltype( it ) &amp;&gt=
;( it, l.size() / 2, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp; std::ostream_iterator&lt;int&gt;( std::cout, " " ) );<b=
r>&nbsp;&nbsp;std::cout &lt;&lt; std::endl;<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;=
l.insert( it, 0 );<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;for ( int x : l ) std::co=
ut &lt;&lt; x &lt;&lt; ' ';<br>&nbsp;&nbsp;std::cout &lt;&lt; std::endl;<br=
>&nbsp;}</div><div>&nbsp;{<br>&nbsp;&nbsp;const size_t N =3D 3;<br>&nbsp;&n=
bsp;int a[N][N] =3D<br>&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;{ 1, 2, 3 },<br>&=
nbsp;&nbsp;&nbsp;{ 4, 5, 6 },<br>&nbsp;&nbsp;&nbsp;{ 7, 8, 9 }<br>&nbsp;&nb=
sp;};<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;int b[2 * N + 1];<br>&nbsp;&nbsp;<br>&=
nbsp;&nbsp;int *last =3D b;<br>&nbsp;&nbsp;size_t i =3D 0;<br>&nbsp;&nbsp;<=
br>&nbsp;&nbsp;while ( i &lt; N &amp;&amp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp; &nbsp;::copy&lt;int *, int * &amp;&gt;( std::begin( a[i=
] ), <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::end( a[i] ), <br>&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; last ) &lt;=3D std::prev( std::en=
d( b ), N ) ) ++i;</div><div>&nbsp;&nbsp;for ( auto it =3D b; it !=3D last;=
 ++it ) std::cout &lt;&lt; *it &lt;&lt; ' ';<br>&nbsp;&nbsp;std::cout &lt;&=
lt; std::endl;<br>&nbsp;}<br>}&nbsp;</div><div><br></div><div>The program o=
utput is</div><div><br></div><div>0 1 2 3 4 <br>0 1 2 3 4 0 5 6 7 8 9 <br>1=
 2 3 4 5 6 </div><div><br></div><div>Thus simply for some algorithms there =
should be written&nbsp;moreclearly in the C++ Standard what is the value of=
 the iterator passed by reference after exiting the algorithm<br></div><div=
><br><br>On Friday, February 20, 2015 at 10:51:11 PM UTC+3, Vlad from Mosco=
w wrote:</div><blockquote class=3D"gmail_quote" 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;"><div dir=3D"ltr"><div>I would no=
t change the return type of the algorithms. Instead of this I suggest to al=
low to use iterators for some algorithms by reference.</div><div><br></div>=
<div>See this thread with the corresponding discussion.</div><div><br></div=
><div><a onmousedown=3D"this.href=3D'https://groups.google.com/a/isocpp.org=
/forum/#!topic/std-discussion/lCuvU-2MPes';return true;" onclick=3D"this.hr=
ef=3D'https://groups.google.com/a/isocpp.org/forum/#!topic/std-discussion/l=
CuvU-2MPes';return true;" href=3D"https://groups.google.com/a/isocpp.org/fo=
rum/#!topic/std-discussion/lCuvU-2MPes" target=3D"_blank" rel=3D"nofollow">=
https://groups.google.com/a/<wbr>isocpp.org/forum/#!topic/std-<wbr>discussi=
on/lCuvU-2MPes</a><br><br>On Friday, February 20, 2015 at 10:31:22 PM UTC+3=
, Martin Ho=C5=99e=C5=88ovsk=C3=BD wrote:</div><blockquote class=3D"gmail_q=
uote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-co=
lor: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;"=
><div dir=3D"ltr">I would like to make couple of changes to algorithm heade=
r, mostly additions for symmetry and convenience.<div><br><div><b>MOVE_N</b=
></div><div>move_n in the following form to the algorithm header, for symme=
try with copy_n.<div><br></div><div><div style=3D"border: 1px solid rgb(187=
, 187, 187); border-image: none; background-color: rgb(250, 250, 250);"><co=
de><div><table style=3D'color: rgb(0, 0, 0); line-height: 15.36px; padding-=
top: 0.5em; padding-bottom: 0.5em; font-family: DejaVuSans,"DejaVu Sans",ar=
ial,sans-serif; font-size: 12.8px; display: block; background-color: rgb(25=
5, 255, 255);'><tbody><tr><td style=3D"padding: 0.3em 2em 0.2em 1em; font-s=
ize: 1em; border-top-color: rgb(204, 204, 204); border-top-width: 1px; bord=
er-top-style: solid;"><span style=3D"line-height: 1.1em; font-family: monos=
pace; white-space: nowrap;"><span style=3D"color: rgb(0, 0, 221); line-heig=
ht: 1.1em;"><span style=3D"color: rgb(0, 0, 136);">template</span></span><s=
pan style=3D"color: rgb(0, 0, 128); line-height: 1.1em;"><span style=3D"col=
or: rgb(102, 102, 0);">&lt;</span></span><span style=3D"color: rgb(0, 0, 0)=
;"> </span><span style=3D"color: rgb(0, 0, 221); line-height: 1.1em;"><span=
 style=3D"color: rgb(0, 0, 136);">class</span></span><span style=3D"color: =
rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 0, 102);">InputIt</sp=
an><span style=3D"color: rgb(102, 102, 0);">,</span><span style=3D"color: r=
gb(0, 0, 0);"> </span><span style=3D"color: rgb(0, 0, 221); line-height: 1.=
1em;"><span style=3D"color: rgb(0, 0, 136);">class</span></span><span style=
=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 0, 102);">=
Size</span><span style=3D"color: rgb(102, 102, 0);">,</span><span style=3D"=
color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(0, 0, 221); line-he=
ight: 1.1em;"><span style=3D"color: rgb(0, 0, 136);">class</span></span><sp=
an style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 0,=
 102);">OutputIt</span><span style=3D"color: rgb(0, 0, 0);"> </span><span s=
tyle=3D"color: rgb(0, 0, 128); line-height: 1.1em;"><span style=3D"color: r=
gb(102, 102, 0);">&gt;</span></span><span style=3D"color: rgb(0, 0, 0);"><b=
r>std</span><span style=3D"color: rgb(102, 102, 0);">::</span><span style=
=3D"color: rgb(0, 0, 0);">pair</span><span style=3D"color: rgb(102, 102, 0)=
;">&lt;</span><span style=3D"color: rgb(102, 0, 102);">InputIt</span><span =
style=3D"color: rgb(102, 102, 0);">,</span><span style=3D"color: rgb(0, 0, =
0);"> </span><span style=3D"color: rgb(102, 0, 102);">OutputIt</span><span =
style=3D"color: rgb(102, 102, 0);">&gt;</span><span style=3D"color: rgb(0, =
0, 0);"> move_n</span><span style=3D"color: rgb(0, 128, 0); line-height: 1.=
1em;"><span style=3D"color: rgb(102, 102, 0);">(</span></span><span style=
=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 0, 102);">=
InputIt</span><span style=3D"color: rgb(0, 0, 0);"> first</span><span style=
=3D"color: rgb(102, 102, 0);">,</span><span style=3D"color: rgb(0, 0, 0);">=
 </span><span style=3D"color: rgb(102, 0, 102);">Size</span><span style=3D"=
color: rgb(0, 0, 0);"> count</span><span style=3D"color: rgb(102, 102, 0);"=
>,</span><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color:=
 rgb(102, 0, 102);">OutputIt</span><span style=3D"color: rgb(0, 0, 0);"> re=
sult </span><span style=3D"color: rgb(0, 128, 0); line-height: 1.1em;"><spa=
n style=3D"color: rgb(102, 102, 0);">)</span></span><span style=3D"color: r=
gb(0, 128, 128); line-height: 1.1em;"><span style=3D"color: rgb(102, 102, 0=
);">;</span></span></span></td><td style=3D"padding-right: 1.5em; font-size=
: 0.8em; border-top-color: rgb(204, 204, 204); border-top-width: 1px; borde=
r-top-style: solid;"></td></tr></tbody></table></div></code></div><div><br>=
</div><div>The return type is different from copy_n, because copy_n's retur=
n type is wrong, and I also want to suggest fixing it to</div><div><br></di=
v><div><div style=3D"border: 1px solid rgb(187, 187, 187); border-image: no=
ne; background-color: rgb(250, 250, 250);"><code><div><table style=3D'color=
: rgb(0, 0, 0); line-height: 15.36px; padding-top: 0.5em; padding-bottom: 0=
..5em; font-family: DejaVuSans,"DejaVu Sans",arial,sans-serif; font-size: 12=
..8px; display: block; background-color: rgb(255, 255, 255);'><tbody><tr><td=
 style=3D"padding: 0.3em 2em 0.2em 1em; font-size: 1em; border-top-color: r=
gb(204, 204, 204); border-top-width: 1px; border-top-style: solid;"><span s=
tyle=3D"line-height: 1.1em; font-family: monospace; white-space: nowrap;"><=
span style=3D"color: rgb(0, 0, 221); line-height: 1.1em;"><span style=3D"co=
lor: rgb(0, 0, 136);">template</span></span><span style=3D"color: rgb(0, 0,=
 128); line-height: 1.1em;"><span style=3D"color: rgb(102, 102, 0);">&lt;</=
span></span><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"col=
or: rgb(0, 0, 221); line-height: 1.1em;"><span style=3D"color: rgb(0, 0, 13=
6);">class</span></span><span style=3D"color: rgb(0, 0, 0);"> </span><span =
style=3D"color: rgb(102, 0, 102);">InputIt</span><span style=3D"color: rgb(=
102, 102, 0);">,</span><span style=3D"color: rgb(0, 0, 0);"> </span><span s=
tyle=3D"color: rgb(0, 0, 221); line-height: 1.1em;"><span style=3D"color: r=
gb(0, 0, 136);">class</span></span><span style=3D"color: rgb(0, 0, 0);"> </=
span><span style=3D"color: rgb(102, 0, 102);">Size</span><span style=3D"col=
or: rgb(102, 102, 0);">,</span><span style=3D"color: rgb(0, 0, 0);"> </span=
><span style=3D"color: rgb(0, 0, 221); line-height: 1.1em;"><span style=3D"=
color: rgb(0, 0, 136);">class</span></span><span style=3D"color: rgb(0, 0, =
0);"> </span><span style=3D"color: rgb(102, 0, 102);">OutputIt</span><span =
style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(0, 0, 128)=
; line-height: 1.1em;"><span style=3D"color: rgb(102, 102, 0);">&gt;</span>=
</span><span style=3D"color: rgb(0, 0, 0);"><br>std</span><span style=3D"co=
lor: rgb(102, 102, 0);">::</span><span style=3D"color: rgb(0, 0, 0);">pair<=
/span><span style=3D"color: rgb(102, 102, 0);">&lt;</span><span style=3D"co=
lor: rgb(102, 0, 102);">InputIt</span><span style=3D"color: rgb(102, 102, 0=
);">,</span><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"col=
or: rgb(102, 0, 102);">OutputIt</span><span style=3D"color: rgb(102, 102, 0=
);">&gt;</span><span style=3D"color: rgb(0, 0, 0);"> copy_n</span><span sty=
le=3D"color: rgb(0, 128, 0); line-height: 1.1em;"><span style=3D"color: rgb=
(102, 102, 0);">(</span></span><span style=3D"color: rgb(0, 0, 0);"> </span=
><span style=3D"color: rgb(102, 0, 102);">InputIt</span><span style=3D"colo=
r: rgb(0, 0, 0);"> first</span><span style=3D"color: rgb(102, 102, 0);">,</=
span><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb=
(102, 0, 102);">Size</span><span style=3D"color: rgb(0, 0, 0);"> count</spa=
n><span style=3D"color: rgb(102, 102, 0);">,</span><span style=3D"color: rg=
b(0, 0, 0);"> </span><span style=3D"color: rgb(102, 0, 102);">OutputIt</spa=
n><span style=3D"color: rgb(0, 0, 0);"> result </span><span style=3D"color:=
 rgb(0, 128, 0); line-height: 1.1em;"><span style=3D"color: rgb(102, 102, 0=
);">)</span></span><span style=3D"color: rgb(0, 128, 128); line-height: 1.1=
em;"><span style=3D"color: rgb(102, 102, 0);">;</span></span></span></td><t=
d style=3D"padding-right: 1.5em; font-size: 0.8em; border-top-color: rgb(20=
4, 204, 204); border-top-width: 1px; border-top-style: solid;"></td></tr></=
tbody></table></div></code></div><br>but I am afraid the ship has sailed on=
 that one. (But please remember that it was added only in C++11 and there w=
on't be that much code depending on it yet. The longer we wait, the farther=
 the proverbial ship gets.)</div><div><br></div><div>The position of return=
ed iterators should be equivalent to position of first and result iterators=
 after calling std::advance(first, count) and std::advance(result, count) r=
espectively.</div><div><br></div><div>The reason to return InputIt as well =
is that otherwise we have to iterate over the elements twice (IE when using=
 std::list&lt;&gt;) and it prevents composition, ie I have to write this:</=
div><div><div style=3D"border: 1px solid rgb(187, 187, 187); border-image: =
none; background-color: rgb(250, 250, 250);"><code><div><span><div><div>std=
::list&lt;int&gt; data;</div><div>std::vector&lt;int&gt; start, rest;</div>=
<div>/* fill in data */</div><div><span style=3D"white-space: pre;"><br>s</=
span>td::copy_n(begin(data), 5, std::back_inserter(start)); //Iterating ove=
r list for the first time<br>auto foo =3D begin(data);<br>std::advance(foo,=
 5); //Iterating over list again<br></div><div>std::copy(foo,&nbsp;<span st=
yle=3D"font-family: Arial,Helvetica,sans-serif;">end(data),&nbsp;</span><sp=
an style=3D"font-family: Arial,Helvetica,sans-serif;">std:<wbr>:back_insert=
er(rest));</span></div><div><br></div></div></span></div></code></div><br><=
/div><div>instead of this</div><div><div style=3D"border: 1px solid rgb(187=
, 187, 187); border-image: none; background-color: rgb(250, 250, 250);"><co=
de><div><div><div>std::list&lt;int&gt; data;</div><div>std::vector&lt;int&g=
t; start, rest;</div><div>/* fill in data */</div><div><span style=3D"font-=
family: Arial,Helvetica,sans-serif;"><br>std::copy(std::copy_n(begin(<wbr>d=
ata), 5, std::back_inserter(start)).<wbr>first,</span><br></div><div>&nbsp;=
 &nbsp; &nbsp; &nbsp; end(data),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; std:=
:back_inserter(rest));<br><br></div></div></div></code></div></div></div><d=
iv><br></div><div><br></div><div><b>MOVE_IF</b></div><div>There also seems =
to be missing move_if, but I am not sure if it should be added. On one hand=
, I can easily see where it can be useful, on the other, it seems that it w=
ould be too easy to use it wrong and try to work with moved-from objects.</=
div><div>Pros&nbsp;</div><div><ul><li><span style=3D"line-height: normal;">=
There are cases where it could be useful.</span></li><li><span style=3D"lin=
e-height: normal;">Convenience over for loops and move_iterators</span></li=
><li><span style=3D"line-height: normal;">Symmetry</span></li></ul></div><d=
iv>Cons</div><div><ul><li><span style=3D"line-height: normal;">Possibly eas=
y to misuse.</span></li><li><span style=3D"line-height: normal;">Is only co=
nvenience over for loops and using move_iterators</span></li></ul></div><di=
v><br></div><div><b>REVERSE_MOVE, UNIQUE_MOVE, ROTATE_MOVE</b></div><div>Th=
ere are also missing convenience functions reverse_move, unique_move, rotat=
e_move (to complement reverse_copy, unique_copy and rotate_copy). I suggest=
 putting these in as well, but I think they have the least priority.</div><=
div>Pros</div><div><ul><li><span style=3D"line-height: normal;">There are c=
ases where they could be useful</span></li><li><span style=3D"line-height: =
normal;">Convenience over using move_iterators</span></li><li><span style=
=3D"line-height: normal;">Symmetry</span></li></ul><div>Cons</div></div><di=
v><ul><li><span style=3D"line-height: normal;">Possibly easy to misuse.</sp=
an></li><li><span style=3D"line-height: normal;">Probably will be used only=
 rarely</span></li></ul><div><b><br></b></div><div><b>PARTITION_MOVE</b></d=
iv></div><div>Complement to partition_copy. I really don't have anything ne=
w to say about it.</div><div><br></div><div><br></div><div><br></div><div><=
br></div><div><br></div><div>I might have forgotten some algorithms and inc=
onsistencies, if so please tell me.</div><div><br></div><div>Also I am horr=
ibly sorry if some of the formatting is broken.</div></div></div></div></bl=
ockquote></div></blockquote></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_181_346620285.1424516743411--
------=_Part_180_2122844049.1424516743411--

.


Author: Scott Prager <splinterofchaos@gmail.com>
Date: Sat, 21 Feb 2015 10:08:57 -0800 (PST)
Raw View
------=_Part_273_477696331.1424542137908
Content-Type: multipart/alternative;
 boundary="----=_Part_274_1348362631.1424542137908"

------=_Part_274_1348362631.1424542137908
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

move_n: std::copy(std::make_move_iterator(first), count, result);
move_if: std::copy_if(std::make_move_iterator(first), count, result, pred);

One could say that *std::transform* should have *_if* and *_n* variants.
What about a *copy_if_n*?=20

IMO, we should be looking at the concepts of iterator adaptors rather than
adapting every algorithm. Any copying algorithm can already be made a
moving one by using a move_iterator, and that seems much more general
to me.

As for *_n* and *_if* variants, section 3.3.5 of the ranges proposal [1]=20
alone would
allow for one two efficiently write iterator adaptors to solve this=20
problem. I spent
a just couple days looking into how this would work [2] and it would allow=
=20
things
like this:

auto mfirst =3D std::make_move_iterator(first);
move_n: std::copy(counted(mfirst), take(n), result);
transform_n: std::transform(counted(first), take(n), result, bin_op);

move_if: std::copy(filter(mfirst, last, pred), seq_end{}, result);

Although, I think the interface of *copy_n* should be changed as well,=20
I'm afraid that would break existing code. Making *move_n* have the
correct result would be inconsistent...

[1]: https://ericniebler.github.io/std/wg21/D4128.html#an-iterables-end-may=
-have-a-different-type-than-its-begin
[2]: https://github.com/splinterofchaos/algo-term

On Friday, February 20, 2015 at 2:31:22 PM UTC-5, Martin Ho=C5=99e=C5=88ovs=
k=C3=BD wrote:
>
> I would like to make couple of changes to algorithm header, mostly=20
> additions for symmetry and convenience.
>
> *MOVE_N*
> move_n in the following form to the algorithm header, for symmetry with=
=20
> copy_n.
>
> template< class InputIt, class Size, class OutputIt >
> std::pair<InputIt, OutputIt> move_n( InputIt first, Size count, OutputIt=
=20
> result );
>
> The return type is different from copy_n, because copy_n's return type is=
=20
> wrong, and I also want to suggest fixing it to
>
> template< class InputIt, class Size, class OutputIt >
> std::pair<InputIt, OutputIt> copy_n( InputIt first, Size count, OutputIt=
=20
> result );
>
> but I am afraid the ship has sailed on that one. (But please remember tha=
t=20
> it was added only in C++11 and there won't be that much code depending on=
=20
> it yet. The longer we wait, the farther the proverbial ship gets.)
>
> The position of returned iterators should be equivalent to position of=20
> first and result iterators after calling std::advance(first, count) and=
=20
> std::advance(result, count) respectively.
>
> The reason to return InputIt as well is that otherwise we have to iterate=
=20
> over the elements twice (IE when using std::list<>) and it prevents=20
> composition, ie I have to write this:
> std::list<int> data;
> std::vector<int> start, rest;
> /* fill in data */
>
> std::copy_n(begin(data), 5, std::back_inserter(start)); //Iterating over=
=20
> list for the first time
> auto foo =3D begin(data);
> std::advance(foo, 5); //Iterating over list again
> std::copy(foo, end(data), std::back_inserter(rest));
>
>
> instead of this
> std::list<int> data;
> std::vector<int> start, rest;
> /* fill in data */
>
> std::copy(std::copy_n(begin(data), 5, std::back_inserter(start)).first,
>         end(data),
>         std::back_inserter(rest));
>
>
>
> *MOVE_IF*
> There also seems to be missing move_if, but I am not sure if it should be=
=20
> added. On one hand, I can easily see where it can be useful, on the other=
,=20
> it seems that it would be too easy to use it wrong and try to work with=
=20
> moved-from objects.
> Pros=20
>
>    - There are cases where it could be useful.
>    - Convenience over for loops and move_iterators
>    - Symmetry
>
> Cons
>
>    - Possibly easy to misuse.
>    - Is only convenience over for loops and using move_iterators
>
>
> *REVERSE_MOVE, UNIQUE_MOVE, ROTATE_MOVE*
> There are also missing convenience functions reverse_move, unique_move,=
=20
> rotate_move (to complement reverse_copy, unique_copy and rotate_copy). I=
=20
> suggest putting these in as well, but I think they have the least priorit=
y.
> Pros
>
>    - There are cases where they could be useful
>    - Convenience over using move_iterators
>    - Symmetry
>
> Cons
>
>    - Possibly easy to misuse.
>    - Probably will be used only rarely
>
>
> *PARTITION_MOVE*
> Complement to partition_copy. I really don't have anything new to say=20
> about it.
>
>
>
>
>
> I might have forgotten some algorithms and inconsistencies, if so please=
=20
> tell me.
>
> Also I am horribly sorry if some of the formatting is broken.
>

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

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

<div dir=3D"ltr">move_n: std::copy(std::make_move_iterator(first), count, r=
esult);<div>move_if: std::copy_if(std::make_move_iterator(first), count, re=
sult, pred);</div><div><br></div><div>One could say that <i>std::transform<=
/i>&nbsp;should have <i>_if</i>&nbsp;and <i>_n</i>&nbsp;variants.</div><div=
>What about a&nbsp;<i>copy_if_n</i>?&nbsp;</div><div><br></div><div>IMO, we=
 should be looking at the concepts of iterator adaptors rather than</div><d=
iv>adapting every algorithm. Any copying algorithm can already be made a</d=
iv><div>moving one by using a move_iterator, and that seems much more gener=
al</div><div>to me.</div><div><br></div><div>As for <i>_n</i>&nbsp;and <i>_=
if</i>&nbsp;variants,&nbsp;section 3.3.5 of the ranges proposal [1] alone w=
ould</div><div>allow for one two efficiently write iterator adaptors to sol=
ve this problem. I spent</div><div>a just couple days looking into how this=
 would work [2] and it would allow things</div><div>like this:</div><div><b=
r></div><div>auto mfirst =3D std::make_move_iterator(first);</div><div>move=
_n: std::copy(counted(mfirst), take(n), result);</div><div>transform_n: std=
::transform(counted(first), take(n), result, bin_op);</div><div><br></div><=
div>move_if: std::copy(filter(mfirst, last, pred), seq_end{}, result);</div=
><div><br></div><div>Although, I think the interface of <i>copy_n</i>&nbsp;=
should be changed as well,&nbsp;</div><div>I'm afraid that would break exis=
ting code. Making <i>move_n</i>&nbsp;have the</div><div>correct result woul=
d be inconsistent...</div><div><br></div><div>[1]:&nbsp;https://ericniebler=
..github.io/std/wg21/D4128.html#an-iterables-end-may-have-a-different-type-t=
han-its-begin</div><div>[2]:&nbsp;https://github.com/splinterofchaos/algo-t=
erm<br><br>On Friday, February 20, 2015 at 2:31:22 PM UTC-5, Martin Ho=C5=
=99e=C5=88ovsk=C3=BD wrote:<blockquote class=3D"gmail_quote" style=3D"margi=
n: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><di=
v dir=3D"ltr">I would like to make couple of changes to algorithm header, m=
ostly additions for symmetry and convenience.<div><br><div><b>MOVE_N</b></d=
iv><div>move_n in the following form to the algorithm header, for symmetry =
with copy_n.<div><br></div><div><div style=3D"border:1px solid rgb(187,187,=
187);word-wrap:break-word;background-color:rgb(250,250,250)"><code><div><ta=
ble style=3D"font-size:12.8000001907349px;display:block;padding-top:0.5em;p=
adding-bottom:0.5em;color:rgb(0,0,0);font-family:DejaVuSans,'DejaVu Sans',a=
rial,sans-serif;line-height:15.3600006103516px;background-color:rgb(255,255=
,255)"><tbody><tr><td style=3D"border-top-width:1px;border-top-style:solid;=
border-top-color:rgb(204,204,204);padding:0.3em 2em 0.2em 1em;font-size:1em=
"><span style=3D"font-family:monospace;line-height:1.1em;white-space:nowrap=
"><span style=3D"line-height:1.1em;color:rgb(0,0,221)"><span style=3D"color=
:#008">template</span></span><span style=3D"line-height:1.1em;color:rgb(0,0=
,128)"><span style=3D"color:#660">&lt;</span></span><span style=3D"color:#0=
00"> </span><span style=3D"line-height:1.1em;color:rgb(0,0,221)"><span styl=
e=3D"color:#008">class</span></span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#606">InputIt</span><span style=3D"color:#660">,</span><sp=
an style=3D"color:#000"> </span><span style=3D"line-height:1.1em;color:rgb(=
0,0,221)"><span style=3D"color:#008">class</span></span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#606">Size</span><span style=3D"color:=
#660">,</span><span style=3D"color:#000"> </span><span style=3D"line-height=
:1.1em;color:rgb(0,0,221)"><span style=3D"color:#008">class</span></span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#606">OutputIt</span>=
<span style=3D"color:#000"> </span><span style=3D"line-height:1.1em;color:r=
gb(0,0,128)"><span style=3D"color:#660">&gt;</span></span><span style=3D"co=
lor:#000"><br>std</span><span style=3D"color:#660">::</span><span style=3D"=
color:#000">pair</span><span style=3D"color:#660">&lt;</span><span style=3D=
"color:#606">InputIt</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#606">OutputIt</span><span sty=
le=3D"color:#660">&gt;</span><span style=3D"color:#000"> move_n</span><span=
 style=3D"line-height:1.1em;color:rgb(0,128,0)"><span style=3D"color:#660">=
(</span></span><span style=3D"color:#000"> </span><span style=3D"color:#606=
">InputIt</span><span style=3D"color:#000"> first</span><span style=3D"colo=
r:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:#60=
6">Size</span><span style=3D"color:#000"> count</span><span style=3D"color:=
#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:#606"=
>OutputIt</span><span style=3D"color:#000"> result </span><span style=3D"li=
ne-height:1.1em;color:rgb(0,128,0)"><span style=3D"color:#660">)</span></sp=
an><span style=3D"line-height:1.1em;color:rgb(0,128,128)"><span style=3D"co=
lor:#660">;</span></span></span></td><td style=3D"padding-right:1.5em;borde=
r-top-width:1px;border-top-style:solid;border-top-color:rgb(204,204,204);fo=
nt-size:0.8em"></td></tr></tbody></table></div></code></div><div><br></div>=
<div>The return type is different from copy_n, because copy_n's return type=
 is wrong, and I also want to suggest fixing it to</div><div><br></div><div=
><div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;backg=
round-color:rgb(250,250,250)"><code><div><table style=3D"font-size:12.80000=
01907349px;display:block;padding-top:0.5em;padding-bottom:0.5em;color:rgb(0=
,0,0);font-family:DejaVuSans,'DejaVu Sans',arial,sans-serif;line-height:15.=
3600006103516px;background-color:rgb(255,255,255)"><tbody><tr><td style=3D"=
border-top-width:1px;border-top-style:solid;border-top-color:rgb(204,204,20=
4);padding:0.3em 2em 0.2em 1em;font-size:1em"><span style=3D"font-family:mo=
nospace;line-height:1.1em;white-space:nowrap"><span style=3D"line-height:1.=
1em;color:rgb(0,0,221)"><span style=3D"color:#008">template</span></span><s=
pan style=3D"line-height:1.1em;color:rgb(0,0,128)"><span style=3D"color:#66=
0">&lt;</span></span><span style=3D"color:#000"> </span><span style=3D"line=
-height:1.1em;color:rgb(0,0,221)"><span style=3D"color:#008">class</span></=
span><span style=3D"color:#000"> </span><span style=3D"color:#606">InputIt<=
/span><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span=
><span style=3D"line-height:1.1em;color:rgb(0,0,221)"><span style=3D"color:=
#008">class</span></span><span style=3D"color:#000"> </span><span style=3D"=
color:#606">Size</span><span style=3D"color:#660">,</span><span style=3D"co=
lor:#000"> </span><span style=3D"line-height:1.1em;color:rgb(0,0,221)"><spa=
n style=3D"color:#008">class</span></span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#606">OutputIt</span><span style=3D"color:#000"> </s=
pan><span style=3D"line-height:1.1em;color:rgb(0,0,128)"><span style=3D"col=
or:#660">&gt;</span></span><span style=3D"color:#000"><br>std</span><span s=
tyle=3D"color:#660">::</span><span style=3D"color:#000">pair</span><span st=
yle=3D"color:#660">&lt;</span><span style=3D"color:#606">InputIt</span><spa=
n style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#606">OutputIt</span><span style=3D"color:#660">&gt;</span><spa=
n style=3D"color:#000"> copy_n</span><span style=3D"line-height:1.1em;color=
:rgb(0,128,0)"><span style=3D"color:#660">(</span></span><span style=3D"col=
or:#000"> </span><span style=3D"color:#606">InputIt</span><span style=3D"co=
lor:#000"> first</span><span style=3D"color:#660">,</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#606">Size</span><span style=3D"colo=
r:#000"> count</span><span style=3D"color:#660">,</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#606">OutputIt</span><span style=3D"co=
lor:#000"> result </span><span style=3D"line-height:1.1em;color:rgb(0,128,0=
)"><span style=3D"color:#660">)</span></span><span style=3D"line-height:1.1=
em;color:rgb(0,128,128)"><span style=3D"color:#660">;</span></span></span><=
/td><td style=3D"padding-right:1.5em;border-top-width:1px;border-top-style:=
solid;border-top-color:rgb(204,204,204);font-size:0.8em"></td></tr></tbody>=
</table></div></code></div><br>but I am afraid the ship has sailed on that =
one. (But please remember that it was added only in C++11 and there won't b=
e that much code depending on it yet. The longer we wait, the farther the p=
roverbial ship gets.)</div><div><br></div><div>The position of returned ite=
rators should be equivalent to position of first and result iterators after=
 calling std::advance(first, count) and std::advance(result, count) respect=
ively.</div><div><br></div><div>The reason to return InputIt as well is tha=
t otherwise we have to iterate over the elements twice (IE when using std::=
list&lt;&gt;) and it prevents composition, ie I have to write this:</div><d=
iv><div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;bac=
kground-color:rgb(250,250,250)"><code><div><span><div><div>std::list&lt;int=
&gt; data;</div><div>std::vector&lt;int&gt; start, rest;</div><div>/* fill =
in data */</div><div><span style=3D"white-space:pre"><br>s</span>td::copy_n=
(begin(data), 5, std::back_inserter(start)); //Iterating over list for the =
first time<br>auto foo =3D begin(data);<br>std::advance(foo, 5); //Iteratin=
g over list again<br></div><div>std::copy(foo,&nbsp;<span style=3D"font-fam=
ily:Arial,Helvetica,sans-serif">end(data),&nbsp;</span><span style=3D"font-=
family:Arial,Helvetica,sans-serif">std:<wbr>:back_inserter(rest));</span></=
div><div><br></div></div></span></div></code></div><br></div><div>instead o=
f this</div><div><div style=3D"border:1px solid rgb(187,187,187);word-wrap:=
break-word;background-color:rgb(250,250,250)"><code><div><div><div>std::lis=
t&lt;int&gt; data;</div><div>std::vector&lt;int&gt; start, rest;</div><div>=
/* fill in data */</div><div><span style=3D"font-family:Arial,Helvetica,san=
s-serif"><br>std::copy(std::copy_n(begin(<wbr>data), 5, std::back_inserter(=
start)).<wbr>first,</span><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; end(da=
ta),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; std::back_inserter(rest));<br><b=
r></div></div></div></code></div></div></div><div><br></div><div><br></div>=
<div><b>MOVE_IF</b></div><div>There also seems to be missing move_if, but I=
 am not sure if it should be added. On one hand, I can easily see where it =
can be useful, on the other, it seems that it would be too easy to use it w=
rong and try to work with moved-from objects.</div><div>Pros&nbsp;</div><di=
v><ul><li><span style=3D"line-height:normal">There are cases where it could=
 be useful.</span></li><li><span style=3D"line-height:normal">Convenience o=
ver for loops and move_iterators</span></li><li><span style=3D"line-height:=
normal">Symmetry</span></li></ul></div><div>Cons</div><div><ul><li><span st=
yle=3D"line-height:normal">Possibly easy to misuse.</span></li><li><span st=
yle=3D"line-height:normal">Is only convenience over for loops and using mov=
e_iterators</span></li></ul></div><div><br></div><div><b>REVERSE_MOVE, UNIQ=
UE_MOVE, ROTATE_MOVE</b></div><div>There are also missing convenience funct=
ions reverse_move, unique_move, rotate_move (to complement reverse_copy, un=
ique_copy and rotate_copy). I suggest putting these in as well, but I think=
 they have the least priority.</div><div>Pros</div><div><ul><li><span style=
=3D"line-height:normal">There are cases where they could be useful</span></=
li><li><span style=3D"line-height:normal">Convenience over using move_itera=
tors</span></li><li><span style=3D"line-height:normal">Symmetry</span></li>=
</ul><div>Cons</div></div><div><ul><li><span style=3D"line-height:normal">P=
ossibly easy to misuse.</span></li><li><span style=3D"line-height:normal">P=
robably will be used only rarely</span></li></ul><div><b><br></b></div><div=
><b>PARTITION_MOVE</b></div></div><div>Complement to partition_copy. I real=
ly don't have anything new to say about it.</div><div><br></div><div><br></=
div><div><br></div><div><br></div><div><br></div><div>I might have forgotte=
n some algorithms and inconsistencies, if so please tell me.</div><div><br>=
</div><div>Also I am horribly sorry if some of the formatting is broken.</d=
iv></div></div></div></blockquote></div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_274_1348362631.1424542137908--
------=_Part_273_477696331.1424542137908--

.


Author: =?UTF-8?Q?Martin_Ho=C5=99e=C5=88ovsk=C3=BD?= <martin.horenovsky@gmail.com>
Date: Sat, 21 Feb 2015 10:26:28 -0800 (PST)
Raw View
------=_Part_2_1824048330.1424543188026
Content-Type: multipart/alternative;
 boundary="----=_Part_3_1451221385.1424543188026"

------=_Part_3_1451221385.1424543188026
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

But also
move: copy(make_move_iterator(first), make_move_iterator(end));

and yet, std::move for ranges is in the current standard. The question then=
=20
becomes whether the saved convenience is worth it or not (personally I feel=
=20
that it is for move_n, not so much for the other ones) and whether we can=
=20
fix return type of copy_n.=20

Also I would probably rather have inconsistent return types, than two=20
algorithms with wrong return type, and I would rather have move_n than not,=
=20
so... (Also, isn't some breakage expected with the Concept-enabled STL? It=
=20
could be a chance to fix this particular error.)

On Saturday, 21 February 2015 19:08:57 UTC+1, Scott Prager wrote:
>
> move_n: std::copy(std::make_move_iterator(first), count, result);
> move_if: std::copy_if(std::make_move_iterator(first), count, result, pred=
);
>
> One could say that *std::transform* should have *_if* and *_n* variants.
> What about a *copy_if_n*?=20
>
> IMO, we should be looking at the concepts of iterator adaptors rather tha=
n
> adapting every algorithm. Any copying algorithm can already be made a
> moving one by using a move_iterator, and that seems much more general
> to me.
>
> As for *_n* and *_if* variants, section 3.3.5 of the ranges proposal [1]=
=20
> alone would
> allow for one two efficiently write iterator adaptors to solve this=20
> problem. I spent
> a just couple days looking into how this would work [2] and it would allo=
w=20
> things
> like this:
>
> auto mfirst =3D std::make_move_iterator(first);
> move_n: std::copy(counted(mfirst), take(n), result);
> transform_n: std::transform(counted(first), take(n), result, bin_op);
>
> move_if: std::copy(filter(mfirst, last, pred), seq_end{}, result);
>
> Although, I think the interface of *copy_n* should be changed as well,=20
> I'm afraid that would break existing code. Making *move_n* have the
> correct result would be inconsistent...
>
> [1]:=20
> https://ericniebler.github.io/std/wg21/D4128.html#an-iterables-end-may-ha=
ve-a-different-type-than-its-begin
> [2]: https://github.com/splinterofchaos/algo-term
>
> On Friday, February 20, 2015 at 2:31:22 PM UTC-5, Martin Ho=C5=99e=C5=88o=
vsk=C3=BD wrote:
>>
>> I would like to make couple of changes to algorithm header, mostly=20
>> additions for symmetry and convenience.
>>
>> *MOVE_N*
>> move_n in the following form to the algorithm header, for symmetry with=
=20
>> copy_n.
>>
>> template< class InputIt, class Size, class OutputIt >
>> std::pair<InputIt, OutputIt> move_n( InputIt first, Size count, OutputIt=
=20
>> result );
>>
>> The return type is different from copy_n, because copy_n's return type i=
s=20
>> wrong, and I also want to suggest fixing it to
>>
>> template< class InputIt, class Size, class OutputIt >
>> std::pair<InputIt, OutputIt> copy_n( InputIt first, Size count, OutputIt=
=20
>> result );
>>
>> but I am afraid the ship has sailed on that one. (But please remember=20
>> that it was added only in C++11 and there won't be that much code depend=
ing=20
>> on it yet. The longer we wait, the farther the proverbial ship gets.)
>>
>> The position of returned iterators should be equivalent to position of=
=20
>> first and result iterators after calling std::advance(first, count) and=
=20
>> std::advance(result, count) respectively.
>>
>> The reason to return InputIt as well is that otherwise we have to iterat=
e=20
>> over the elements twice (IE when using std::list<>) and it prevents=20
>> composition, ie I have to write this:
>> std::list<int> data;
>> std::vector<int> start, rest;
>> /* fill in data */
>>
>> std::copy_n(begin(data), 5, std::back_inserter(start)); //Iterating over=
=20
>> list for the first time
>> auto foo =3D begin(data);
>> std::advance(foo, 5); //Iterating over list again
>> std::copy(foo, end(data), std::back_inserter(rest));
>>
>>
>> instead of this
>> std::list<int> data;
>> std::vector<int> start, rest;
>> /* fill in data */
>>
>> std::copy(std::copy_n(begin(data), 5, std::back_inserter(start)).first,
>>         end(data),
>>         std::back_inserter(rest));
>>
>>
>>
>> *MOVE_IF*
>> There also seems to be missing move_if, but I am not sure if it should b=
e=20
>> added. On one hand, I can easily see where it can be useful, on the othe=
r,=20
>> it seems that it would be too easy to use it wrong and try to work with=
=20
>> moved-from objects.
>> Pros=20
>>
>>    - There are cases where it could be useful.
>>    - Convenience over for loops and move_iterators
>>    - Symmetry
>>
>> Cons
>>
>>    - Possibly easy to misuse.
>>    - Is only convenience over for loops and using move_iterators
>>
>>
>> *REVERSE_MOVE, UNIQUE_MOVE, ROTATE_MOVE*
>> There are also missing convenience functions reverse_move, unique_move,=
=20
>> rotate_move (to complement reverse_copy, unique_copy and rotate_copy). I=
=20
>> suggest putting these in as well, but I think they have the least priori=
ty.
>> Pros
>>
>>    - There are cases where they could be useful
>>    - Convenience over using move_iterators
>>    - Symmetry
>>
>> Cons
>>
>>    - Possibly easy to misuse.
>>    - Probably will be used only rarely
>>
>>
>> *PARTITION_MOVE*
>> Complement to partition_copy. I really don't have anything new to say=20
>> about it.
>>
>>
>>
>>
>>
>> I might have forgotten some algorithms and inconsistencies, if so please=
=20
>> tell me.
>>
>> Also I am horribly sorry if some of the formatting is broken.
>>
>

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

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

<div dir=3D"ltr">But also<div>move: copy(make_move_iterator(first), make_mo=
ve_iterator(end));</div><div><br></div><div>and yet, std::move for ranges i=
s in the current standard. The question then becomes whether the saved conv=
enience is worth it or not (personally I feel that it is for move_n, not so=
 much for the other ones) and whether we can fix return type of copy_n.&nbs=
p;</div><div><br></div><div>Also I would probably rather have inconsistent =
return types, than two algorithms with wrong return type, and I would rathe=
r have move_n than not, so... (Also, isn't some breakage expected with the =
Concept-enabled STL? It could be a chance to fix this particular error.)</d=
iv><div><br>On Saturday, 21 February 2015 19:08:57 UTC+1, Scott Prager  wro=
te:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;=
border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">move_n: st=
d::copy(std::make_move_<wbr>iterator(first), count, result);<div>move_if: s=
td::copy_if(std::make_move_<wbr>iterator(first), count, result, pred);</div=
><div><br></div><div>One could say that <i>std::transform</i>&nbsp;should h=
ave <i>_if</i>&nbsp;and <i>_n</i>&nbsp;variants.</div><div>What about a&nbs=
p;<i>copy_if_n</i>?&nbsp;</div><div><br></div><div>IMO, we should be lookin=
g at the concepts of iterator adaptors rather than</div><div>adapting every=
 algorithm. Any copying algorithm can already be made a</div><div>moving on=
e by using a move_iterator, and that seems much more general</div><div>to m=
e.</div><div><br></div><div>As for <i>_n</i>&nbsp;and <i>_if</i>&nbsp;varia=
nts,&nbsp;section 3.3.5 of the ranges proposal [1] alone would</div><div>al=
low for one two efficiently write iterator adaptors to solve this problem. =
I spent</div><div>a just couple days looking into how this would work [2] a=
nd it would allow things</div><div>like this:</div><div><br></div><div>auto=
 mfirst =3D std::make_move_iterator(first)<wbr>;</div><div>move_n: std::cop=
y(counted(mfirst), take(n), result);</div><div>transform_n: std::transform(=
counted(first), take(n), result, bin_op);</div><div><br></div><div>move_if:=
 std::copy(filter(mfirst, last, pred), seq_end{}, result);</div><div><br></=
div><div>Although, I think the interface of <i>copy_n</i>&nbsp;should be ch=
anged as well,&nbsp;</div><div>I'm afraid that would break existing code. M=
aking <i>move_n</i>&nbsp;have the</div><div>correct result would be inconsi=
stent...</div><div><br></div><div>[1]:&nbsp;<a href=3D"https://ericniebler.=
github.io/std/wg21/D4128.html#an-iterables-end-may-have-a-different-type-th=
an-its-begin" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=
=3D'https://www.google.com/url?q\75https%3A%2F%2Fericniebler.github.io%2Fst=
d%2Fwg21%2FD4128.html%23an-iterables-end-may-have-a-different-type-than-its=
-begin\46sa\75D\46sntz\0751\46usg\75AFQjCNHkKO7tbq1yJeK_GRKsu-EOAPGAtg';ret=
urn true;" onclick=3D"this.href=3D'https://www.google.com/url?q\75https%3A%=
2F%2Fericniebler.github.io%2Fstd%2Fwg21%2FD4128.html%23an-iterables-end-may=
-have-a-different-type-than-its-begin\46sa\75D\46sntz\0751\46usg\75AFQjCNHk=
KO7tbq1yJeK_GRKsu-EOAPGAtg';return true;">https://ericniebler.<wbr>github.i=
o/std/wg21/D4128.html#<wbr>an-iterables-end-may-have-a-<wbr>different-type-=
than-its-begin</a></div><div>[2]:&nbsp;<a href=3D"https://github.com/splint=
erofchaos/algo-term" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this=
..href=3D'https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Fsplinter=
ofchaos%2Falgo-term\46sa\75D\46sntz\0751\46usg\75AFQjCNEk2576PeN1o3zviOFgdc=
01Ja1UyA';return true;" onclick=3D"this.href=3D'https://www.google.com/url?=
q\75https%3A%2F%2Fgithub.com%2Fsplinterofchaos%2Falgo-term\46sa\75D\46sntz\=
0751\46usg\75AFQjCNEk2576PeN1o3zviOFgdc01Ja1UyA';return true;">https://gith=
ub.com/<wbr>splinterofchaos/algo-term</a><br><br>On Friday, February 20, 20=
15 at 2:31:22 PM UTC-5, Martin Ho=C5=99e=C5=88ovsk=C3=BD wrote:<blockquote =
class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #=
ccc solid;padding-left:1ex"><div dir=3D"ltr">I would like to make couple of=
 changes to algorithm header, mostly additions for symmetry and convenience=
..<div><br><div><b>MOVE_N</b></div><div>move_n in the following form to the =
algorithm header, for symmetry with copy_n.<div><br></div><div><div style=
=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;background-color=
:rgb(250,250,250)"><code><div><table style=3D"font-size:12.8000001907349px;=
display:block;padding-top:0.5em;padding-bottom:0.5em;color:rgb(0,0,0);font-=
family:DejaVuSans,'DejaVu Sans',arial,sans-serif;line-height:15.36000061035=
16px;background-color:rgb(255,255,255)"><tbody><tr><td style=3D"border-top-=
width:1px;border-top-style:solid;border-top-color:rgb(204,204,204);padding:=
0.3em 2em 0.2em 1em;font-size:1em"><span style=3D"font-family:monospace;lin=
e-height:1.1em;white-space:nowrap"><span style=3D"line-height:1.1em;color:r=
gb(0,0,221)"><span style=3D"color:#008">template</span></span><span style=
=3D"line-height:1.1em;color:rgb(0,0,128)"><span style=3D"color:#660">&lt;</=
span></span><span style=3D"color:#000"> </span><span style=3D"line-height:1=
..1em;color:rgb(0,0,221)"><span style=3D"color:#008">class</span></span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#606">InputIt</span><sp=
an style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span st=
yle=3D"line-height:1.1em;color:rgb(0,0,221)"><span style=3D"color:#008">cla=
ss</span></span><span style=3D"color:#000"> </span><span style=3D"color:#60=
6">Size</span><span style=3D"color:#660">,</span><span style=3D"color:#000"=
> </span><span style=3D"line-height:1.1em;color:rgb(0,0,221)"><span style=
=3D"color:#008">class</span></span><span style=3D"color:#000"> </span><span=
 style=3D"color:#606">OutputIt</span><span style=3D"color:#000"> </span><sp=
an style=3D"line-height:1.1em;color:rgb(0,0,128)"><span style=3D"color:#660=
">&gt;</span></span><span style=3D"color:#000"><br>std</span><span style=3D=
"color:#660">::</span><span style=3D"color:#000">pair</span><span style=3D"=
color:#660">&lt;</span><span style=3D"color:#606">InputIt</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#606">OutputIt</span><span style=3D"color:#660">&gt;</span><span style=
=3D"color:#000"> move_n</span><span style=3D"line-height:1.1em;color:rgb(0,=
128,0)"><span style=3D"color:#660">(</span></span><span style=3D"color:#000=
"> </span><span style=3D"color:#606">InputIt</span><span style=3D"color:#00=
0"> first</span><span style=3D"color:#660">,</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#606">Size</span><span style=3D"color:#000"=
> count</span><span style=3D"color:#660">,</span><span style=3D"color:#000"=
> </span><span style=3D"color:#606">OutputIt</span><span style=3D"color:#00=
0"> result </span><span style=3D"line-height:1.1em;color:rgb(0,128,0)"><spa=
n style=3D"color:#660">)</span></span><span style=3D"line-height:1.1em;colo=
r:rgb(0,128,128)"><span style=3D"color:#660">;</span></span></span></td><td=
 style=3D"padding-right:1.5em;border-top-width:1px;border-top-style:solid;b=
order-top-color:rgb(204,204,204);font-size:0.8em"></td></tr></tbody></table=
></div></code></div><div><br></div><div>The return type is different from c=
opy_n, because copy_n's return type is wrong, and I also want to suggest fi=
xing it to</div><div><br></div><div><div style=3D"border:1px solid rgb(187,=
187,187);word-wrap:break-word;background-color:rgb(250,250,250)"><code><div=
><table style=3D"font-size:12.8000001907349px;display:block;padding-top:0.5=
em;padding-bottom:0.5em;color:rgb(0,0,0);font-family:DejaVuSans,'DejaVu San=
s',arial,sans-serif;line-height:15.3600006103516px;background-color:rgb(255=
,255,255)"><tbody><tr><td style=3D"border-top-width:1px;border-top-style:so=
lid;border-top-color:rgb(204,204,204);padding:0.3em 2em 0.2em 1em;font-size=
:1em"><span style=3D"font-family:monospace;line-height:1.1em;white-space:no=
wrap"><span style=3D"line-height:1.1em;color:rgb(0,0,221)"><span style=3D"c=
olor:#008">template</span></span><span style=3D"line-height:1.1em;color:rgb=
(0,0,128)"><span style=3D"color:#660">&lt;</span></span><span style=3D"colo=
r:#000"> </span><span style=3D"line-height:1.1em;color:rgb(0,0,221)"><span =
style=3D"color:#008">class</span></span><span style=3D"color:#000"> </span>=
<span style=3D"color:#606">InputIt</span><span style=3D"color:#660">,</span=
><span style=3D"color:#000"> </span><span style=3D"line-height:1.1em;color:=
rgb(0,0,221)"><span style=3D"color:#008">class</span></span><span style=3D"=
color:#000"> </span><span style=3D"color:#606">Size</span><span style=3D"co=
lor:#660">,</span><span style=3D"color:#000"> </span><span style=3D"line-he=
ight:1.1em;color:rgb(0,0,221)"><span style=3D"color:#008">class</span></spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#606">OutputIt</s=
pan><span style=3D"color:#000"> </span><span style=3D"line-height:1.1em;col=
or:rgb(0,0,128)"><span style=3D"color:#660">&gt;</span></span><span style=
=3D"color:#000"><br>std</span><span style=3D"color:#660">::</span><span sty=
le=3D"color:#000">pair</span><span style=3D"color:#660">&lt;</span><span st=
yle=3D"color:#606">InputIt</span><span style=3D"color:#660">,</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#606">OutputIt</span><span=
 style=3D"color:#660">&gt;</span><span style=3D"color:#000"> copy_n</span><=
span style=3D"line-height:1.1em;color:rgb(0,128,0)"><span style=3D"color:#6=
60">(</span></span><span style=3D"color:#000"> </span><span style=3D"color:=
#606">InputIt</span><span style=3D"color:#000"> first</span><span style=3D"=
color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color=
:#606">Size</span><span style=3D"color:#000"> count</span><span style=3D"co=
lor:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:#=
606">OutputIt</span><span style=3D"color:#000"> result </span><span style=
=3D"line-height:1.1em;color:rgb(0,128,0)"><span style=3D"color:#660">)</spa=
n></span><span style=3D"line-height:1.1em;color:rgb(0,128,128)"><span style=
=3D"color:#660">;</span></span></span></td><td style=3D"padding-right:1.5em=
;border-top-width:1px;border-top-style:solid;border-top-color:rgb(204,204,2=
04);font-size:0.8em"></td></tr></tbody></table></div></code></div><br>but I=
 am afraid the ship has sailed on that one. (But please remember that it wa=
s added only in C++11 and there won't be that much code depending on it yet=
.. The longer we wait, the farther the proverbial ship gets.)</div><div><br>=
</div><div>The position of returned iterators should be equivalent to posit=
ion of first and result iterators after calling std::advance(first, count) =
and std::advance(result, count) respectively.</div><div><br></div><div>The =
reason to return InputIt as well is that otherwise we have to iterate over =
the elements twice (IE when using std::list&lt;&gt;) and it prevents compos=
ition, ie I have to write this:</div><div><div style=3D"border:1px solid rg=
b(187,187,187);word-wrap:break-word;background-color:rgb(250,250,250)"><cod=
e><div><span><div><div>std::list&lt;int&gt; data;</div><div>std::vector&lt;=
int&gt; start, rest;</div><div>/* fill in data */</div><div><span style=3D"=
white-space:pre"><br>s</span>td::copy_n(begin(data), 5, std::back_inserter(=
start)); //Iterating over list for the first time<br>auto foo =3D begin(dat=
a);<br>std::advance(foo, 5); //Iterating over list again<br></div><div>std:=
:copy(foo,&nbsp;<span style=3D"font-family:Arial,Helvetica,sans-serif">end(=
data),&nbsp;</span><span style=3D"font-family:Arial,Helvetica,sans-serif">s=
td:<wbr>:back_inserter(rest));</span></div><div><br></div></div></span></di=
v></code></div><br></div><div>instead of this</div><div><div style=3D"borde=
r:1px solid rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,=
250,250)"><code><div><div><div>std::list&lt;int&gt; data;</div><div>std::ve=
ctor&lt;int&gt; start, rest;</div><div>/* fill in data */</div><div><span s=
tyle=3D"font-family:Arial,Helvetica,sans-serif"><br>std::copy(std::copy_n(b=
egin(<wbr>data), 5, std::back_inserter(start)).<wbr>first,</span><br></div>=
<div>&nbsp; &nbsp; &nbsp; &nbsp; end(data),</div><div>&nbsp; &nbsp; &nbsp; =
&nbsp; std::back_inserter(rest));<br><br></div></div></div></code></div></d=
iv></div><div><br></div><div><br></div><div><b>MOVE_IF</b></div><div>There =
also seems to be missing move_if, but I am not sure if it should be added. =
On one hand, I can easily see where it can be useful, on the other, it seem=
s that it would be too easy to use it wrong and try to work with moved-from=
 objects.</div><div>Pros&nbsp;</div><div><ul><li><span style=3D"line-height=
:normal">There are cases where it could be useful.</span></li><li><span sty=
le=3D"line-height:normal">Convenience over for loops and move_iterators</sp=
an></li><li><span style=3D"line-height:normal">Symmetry</span></li></ul></d=
iv><div>Cons</div><div><ul><li><span style=3D"line-height:normal">Possibly =
easy to misuse.</span></li><li><span style=3D"line-height:normal">Is only c=
onvenience over for loops and using move_iterators</span></li></ul></div><d=
iv><br></div><div><b>REVERSE_MOVE, UNIQUE_MOVE, ROTATE_MOVE</b></div><div>T=
here are also missing convenience functions reverse_move, unique_move, rota=
te_move (to complement reverse_copy, unique_copy and rotate_copy). I sugges=
t putting these in as well, but I think they have the least priority.</div>=
<div>Pros</div><div><ul><li><span style=3D"line-height:normal">There are ca=
ses where they could be useful</span></li><li><span style=3D"line-height:no=
rmal">Convenience over using move_iterators</span></li><li><span style=3D"l=
ine-height:normal">Symmetry</span></li></ul><div>Cons</div></div><div><ul><=
li><span style=3D"line-height:normal">Possibly easy to misuse.</span></li><=
li><span style=3D"line-height:normal">Probably will be used only rarely</sp=
an></li></ul><div><b><br></b></div><div><b>PARTITION_MOVE</b></div></div><d=
iv>Complement to partition_copy. I really don't have anything new to say ab=
out it.</div><div><br></div><div><br></div><div><br></div><div><br></div><d=
iv><br></div><div>I might have forgotten some algorithms and inconsistencie=
s, if so please tell me.</div><div><br></div><div>Also I am horribly sorry =
if some of the formatting is broken.</div></div></div></div></blockquote></=
div></div></blockquote></div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_3_1451221385.1424543188026--
------=_Part_2_1824048330.1424543188026--

.


Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@gmail.com>
Date: Tue, 24 Feb 2015 13:31:42 +0100
Raw View
--089e013d175c86f577050fd4b35d
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

2015-02-20 20:31 GMT+01:00 Martin Ho=C5=99e=C5=88ovsk=C3=BD <martin.horenov=
sky@gmail.com>:
>
> I would like to make couple of changes to algorithm header, mostly
additions for symmetry and convenience.
>
> MOVE_N
> move_n in the following form to the algorithm header, for symmetry with
copy_n.
>
> template< class InputIt, class Size, class OutputIt >
> std::pair<InputIt, OutputIt> move_n( InputIt first, Size count, OutputIt
result );
>
> The return type is different from copy_n, because copy_n's return type is
wrong, and I also want to suggest fixing it to
>
> template< class InputIt, class Size, class OutputIt >
> std::pair<InputIt, OutputIt> copy_n( InputIt first, Size count, OutputIt
result );
>
> but I am afraid the ship has sailed on that one. (But please remember
that it was added only in C++11 and there won't be that much code depending
on it yet. The longer we wait, the farther the proverbial ship gets.)

The ship is not necessarily sailed, see

http://cplusplus.github.io/LWG/lwg-active.html#2242

There will certainly be some resistance based on the compatibility reasons
you mention, but it doesn't necessarily mean that this issue is doomed to
be resolved as NAD.

- Daniel

--=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/.

--089e013d175c86f577050fd4b35d
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><div>2015-02-20 20:31 GMT+01:00 Martin Ho=C5=99e=C5=
=88ovsk=C3=BD &lt;<a href=3D"mailto:martin.horenovsky@gmail.com">martin.hor=
enovsky@gmail.com</a>&gt;:<br>&gt;<br>&gt; I would like to make couple of c=
hanges to algorithm header, mostly additions for symmetry and convenience.<=
br>&gt;<br>&gt; MOVE_N<br>&gt; move_n in the following form to the algorith=
m header, for symmetry with copy_n.<br>&gt;<br>&gt; template&lt; class Inpu=
tIt, class Size, class OutputIt &gt;<br>&gt; std::pair&lt;InputIt, OutputIt=
&gt; move_n( InputIt first, Size count, OutputIt result );<br>&gt;<br>&gt; =
The return type is different from copy_n, because copy_n&#39;s return type =
is wrong, and I also want to suggest fixing it to<br>&gt;<br>&gt; template&=
lt; class InputIt, class Size, class OutputIt &gt;<br>&gt; std::pair&lt;Inp=
utIt, OutputIt&gt; copy_n( InputIt first, Size count, OutputIt result );<br=
>&gt;<br>&gt; but I am afraid the ship has sailed on that one. (But please =
remember that it was added only in C++11 and there won&#39;t be that much c=
ode depending on it yet. The longer we wait, the farther the proverbial shi=
p gets.)<br><br>The ship is not necessarily sailed, see<br><br><a href=3D"h=
ttp://cplusplus.github.io/LWG/lwg-active.html#2242">http://cplusplus.github=
..io/LWG/lwg-active.html#2242</a><br><br></div>There will certainly be some =
resistance based on the compatibility reasons you mention, but it doesn&#39=
;t necessarily mean that this issue is doomed to be resolved as NAD.<br><br=
></div>- Daniel<br><br></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--089e013d175c86f577050fd4b35d--

.