Topic: Some thoughts about coroutines
Author: asaelr@gmail.com
Date: Wed, 26 Jun 2013 18:40:58 -0700 (PDT)
Raw View
------=_Part_2129_3026738.1372297258221
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
Recently, I=92ve thought a lot about coroutines, and how they should behave=
=20
if became a part of c++.
I found two (main) proposals:
a.=20
https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/3g6ZIWed=
GJ8
It has the advantage of not requiring to change the syntax, but in force a=
=20
new model of stack-based calls. It does so in purpose to let nested=20
functions to yield value, which I think is not really necessary. (If we let=
=20
nested functions return value on behalf of their callee, we should start=20
this in regular functions). Also, Its syntax is somehow complex.
b.=20
https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/PPZJVTDd=
DVQ
It is easy to use and doesn=92t require a new stack, and I think that this =
is=20
the right direction. However, it ignores some technical details (lifetime=
=20
of locals, etc). Also, adding a keyword may break too many working code,=20
and my personal opinion is that it is ugly. Sentences like =93void numbers(=
)=20
yields int=94 reminds me too many things I hate in Java. The alternative=20
syntax (described at the end of this proposal) is not so ugly, but still=20
complex.
There is even a nice implementation of coroutines (using macros):=20
http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
but it has 2 major disadvantages: while using it, we can=92t yield a value=
=20
from within a switch statement, and, much more important, we have to define=
=20
all the local variables at the top of the function - back to C90 days! (and=
=20
with constructors this is much worst.)
Another thing that was very little talk about, is for-range loops native=20
support. Let=92s say we have a Fibonacci number generator (a very common=20
example):
(Using Denis Bredelet=92s proposal syntax)
void fib(int n) yields int {
int a=3D0,b=3D1;
while(n--) {
int c=3Da+b;
a=3Db;
b=3Dc;
yield c;
}
}
We want the possibility to write for (int i : fib(10)) std::cout<<i<<=92\n=
=92;to print the first 10 Fibonacci numbers.
So what am I suggest?
First, to the syntax. Since we want it to work natively with for-range=20
loops, and since the language concept is =93declare it the way you will us=
e=20
it=94, I would suggest using colon in the function signature. The nicest id=
ea=20
I managed to think so far is int : fib(int n)
Also, there is no reason to add the keyword yield, when we can stick to=20
good old return.
Now, to the real stuff: What does fib(10) mean? What=92s the type of=20
fib(10).begin()?
I suggest this meaning: fib will be (auto-generated) class, and an object=
=20
of it will represent calling the =93function=94 with specific parameters. T=
he=20
member function begin (and end) will return some sort of iterator, which=20
will represent the actual call.
Some details: the fib class should have some members, to contain the=20
parameters it called with, but the real fun is in the iterator class: it=20
will have (in addition to the parameters), as (not exactly, I will explain=
=20
below) members, all the local variables of the =93function=94 (including th=
e=20
return value), and also the information about where it stopped last time=20
(and should resume from) - let=92s call it, from now on, =93position data=
=94.
To be more precise: an iterator should contain the memory for the local=20
variables (like every member variable), but their lifetime will be as if=20
they were local variables of the =93function=94. I mean - they will been=20
constructed only when the =93function=94 will decide so, and not automatica=
lly=20
when the iterator is been constructed.
When the =93function=94 ends (either by falling through the ending brace, n=
ot=20
catching exception, or simply saying return; without a value), the position=
=20
data should contain this information, and (like every function), every=20
local variable should be destructed.
Knowing the position data let us easily determine which variables are=20
alive, and so I think that the following member functions can be=20
automatically created:
copy constructor - should copy the position data, the parameters, and every=
=20
living local variable
move constructor - the same, but move instead of copy
destructor - destroy the parameters, and every living local variable.
(Of course, if some local variable is noncopyable, so is the iterator)
I think that it should not be assignable - If one iterator have a live=20
object, and another one have not, it=92s a real mess.
Some example:
Suppose that we want to yield the number 0, and then, the first n Fibonacci=
=20
numbers and the first n even number, alternately. To add more interest (and=
=20
to demonstrate more rules), I want to create and destroy some objects=20
(assume A is a copyable, moveable, and int-constructive class), so I=92ve=
=20
written the following code:
int : fib_even(int n) {
A a(7);
int fib1=3D0,fib2=3D1,even=3D0;
return 0;
while(n--) {
int fib3=3Dfib1+fib2;
fib1=3Dfib2;
fib2=3Dfib3;
return fib3;
A b=3Dn;
return even+=3D2;
}
}
A compiler may expand it to something like:
(Note: I=92m using dynamic memory allocation, but It=92s not really how it=
=20
should be implemented - I just don=92t want some constructors and destructo=
rs=20
to been invoked automatically)
class fib_even {
class iterator {
int n;
int *fib1,*fib2,*fib3,*even;
A *a,*b;
int *ret_value;
enum {p0,p1,p2,p3,p4} pos; //resuming points
void next() {
switch (pos) {
case p0: break;
case p1: goto label1;
case p2: goto label2;
case p3: goto label3;
case p4: return;
}
//construct automatic variables of the function
a=3Dnew A(7);
fib1=3Dnew int(0);
fib2=3Dnew int(1);
even=3Dnew int(0);
//the return process - create the value, save the resuming point, and retur=
n
ret_value=3Dnew int(0);
pos=3Dp1;
return;
label1:
while(n--) {
fib3=3Dnew int(*fib1+*fib2); //being constructed only now
*fib1=3D*fib2;
*fib2=3D*fib3;
ret_value=3Dnew int(*fib3);
pos=3Dp2;
return;
label2:
b=3Dnew A(n);
ret_value=3Dnew int((*even)+=3D2);
pos=3Dp3;
return;
label3:
//automatic variables going out of scope, and should be destructed
delete b;
delete fib3;
}
delete even;
delete fib2;
delete fib1;
delete a;
pos=3Dp4;
}
iterator(int n) : n(n),pos(p0) {
next(); //get the first value
}
iterator() : pos(p4) {}
public:
iterator &operator++() {
delete ret_value;
next();
return *this;
}
int &operator*() {
return *ret_value;
}
iterator(const iterator &it) : n(it.n),pos(it.pos) {
//copy only living members
if (pos>p0 && pos<p4) {
ret_value=3Dnew int(*it.ret_value);
a=3Dnew A(*it.a);
fib1=3Dnew int(*it.fib1);
fib2=3Dnew int(*it.fib2);
even=3Dnew int(*it.even);
}
if (pos>p1 && pos<p4) fib3=3Dnew int(*it.fib3);
if (pos>p2 && pos<p4) b=3Dnew A(*it.b);
}
iterator(iterator &&it) : n(std::move(it.n)),pos(it.pos) {
if (pos>p0 && pos<p4) {
ret_value=3Dnew int(std::move(*it.ret_value));
a=3Dnew A(std::move(*it.a));
fib1=3Dnew int(std::move(*it.fib1));
fib2=3Dnew int(std::move(*it.fib2));
even=3Dnew int(std::move(*it.even));
}
if (pos>p1 && pos<p4) fib3=3Dnew int(std::move(*it.fib3));
if (pos>p2 && pos<p4) b=3Dnew A(std::move(*it.b));
}
~iterator() {
if (pos>p2 && pos<p4) delete b;
if (pos>p1 && pos<p4) delete fib3;
if (pos>p0 && pos<p4) {
delete even;
delete fib2;
delete fib1;
delete a;
delete ret_value;
}
}
bool operator!=3D(const iterator &it) {
return pos!=3Dit.pos;
}
operator bool() {
return pos<p4; //still hasn't ended
}
iterator &operator=3D(const iterator&) =3D delete;
friend fib_even;
};
int n;
public:
fib_even(int n) : n(n) {}
iterator begin() {
return iterator(n);
}
iterator end() {
return iterator();
}
};
So, what do you think?
--=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_2129_3026738.1372297258221
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
<p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"=
id=3D"docs-internal-guid--bd7c543-833d-2981-81c4-c5055c650915"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline;">Recently, I=92ve thought a lot about coro=
utines, and how they should behave if became a part of c++.</span></p><p di=
r=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><spa=
n style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:=
transparent;font-weight:normal;font-style:normal;font-variant:normal;text-d=
ecoration:none;vertical-align:baseline;">I found two (main) proposals:</spa=
n></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom=
:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgr=
ound-color:transparent;font-weight:normal;font-style:normal;font-variant:no=
rmal;text-decoration:none;vertical-align:baseline;">a. </span><a href=3D"ht=
tps://groups.google.com/a/isocpp.org/forum/#%21topic/std-proposals/3g6ZIWed=
GJ8" style=3D"text-decoration:none;"><span style=3D"font-size:15px;font-fam=
ily:Arial;color:#1155cc;background-color:transparent;font-weight:normal;fon=
t-style:normal;font-variant:normal;text-decoration:underline;vertical-align=
:baseline;">https://groups.google.com/a/isocpp.org/forum/#!topic/std-propos=
als/3g6ZIWedGJ8</span></a><span style=3D"font-size:15px;font-family:Arial;c=
olor:#000000;background-color:transparent;font-weight:normal;font-style:nor=
mal;font-variant:normal;text-decoration:none;vertical-align:baseline;"></sp=
an></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-botto=
m:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backg=
round-color:transparent;font-weight:normal;font-style:normal;font-variant:n=
ormal;text-decoration:none;vertical-align:baseline;">It
has the advantage of not requiring to change the syntax, but in force a
new model of stack-based calls. It does so in purpose to let nested=20
functions to yield value, which I think is not really necessary. (If we=20
let nested functions return value on behalf of their callee, we should=20
start this in regular functions). Also, Its syntax is somehow complex.</spa=
n></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom=
:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgr=
ound-color:transparent;font-weight:normal;font-style:normal;font-variant:no=
rmal;text-decoration:none;vertical-align:baseline;">b. </span><a href=3D"ht=
tps://groups.google.com/a/isocpp.org/forum/#%21topic/std-proposals/PPZJVTDd=
DVQ" style=3D"text-decoration:none;"><span style=3D"font-size:15px;font-fam=
ily:Arial;color:#1155cc;background-color:transparent;font-weight:normal;fon=
t-style:normal;font-variant:normal;text-decoration:underline;vertical-align=
:baseline;">https://groups.google.com/a/isocpp.org/forum/#!topic/std-propos=
als/PPZJVTDdDVQ</span></a><span style=3D"font-size:15px;font-family:Arial;c=
olor:#000000;background-color:transparent;font-weight:normal;font-style:nor=
mal;font-variant:normal;text-decoration:none;vertical-align:baseline;"></sp=
an></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-botto=
m:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backg=
round-color:transparent;font-weight:normal;font-style:normal;font-variant:n=
ormal;text-decoration:none;vertical-align:baseline;">It
is easy to use and doesn=92t require a new stack, and I think that this=20
is the right direction. However, it ignores some technical details=20
(lifetime of locals, etc). Also, adding a keyword may break too many=20
working code, and my personal opinion is that it is ugly. Sentences like
=93void numbers() yields int=94 reminds me too many things I hate in Java.=
=20
The alternative syntax (described at the end of this proposal) is not so
ugly, but still complex.</span></p><p dir=3D"ltr" style=3D"line-height:1.1=
5;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-fam=
ily:Arial;color:#000000;background-color:transparent;font-weight:normal;fon=
t-style:normal;font-variant:normal;text-decoration:none;vertical-align:base=
line;">There is even a nice implementation of coroutines (using macros): </=
span><a href=3D"http://www.chiark.greenend.org.uk/%7Esgtatham/coroutines.ht=
ml" style=3D"text-decoration:none;"><span style=3D"font-size:15px;font-fami=
ly:Arial;color:#1155cc;background-color:transparent;font-weight:normal;font=
-style:normal;font-variant:normal;text-decoration:underline;vertical-align:=
baseline;">http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html</spa=
n></a><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgro=
und-color:transparent;font-weight:normal;font-style:normal;font-variant:nor=
mal;text-decoration:none;vertical-align:baseline;"></span></p><p dir=3D"ltr=
" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline;">but
it has 2 major disadvantages: while using it, we can=92t yield a value=20
from within a switch statement, and, much more important, we have to=20
define all the local variables at the top of the function - back to C90=20
days! (and with constructors this is much worst.)</span></p><br><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline;"></span><p dir=3D"ltr" style=3D"line-heigh=
t:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;fon=
t-family:Arial;color:#000000;background-color:transparent;font-weight:norma=
l;font-style:normal;font-variant:normal;text-decoration:none;vertical-align=
:baseline;">Another
thing that was very little talk about, is for-range loops native=20
support. Let=92s say we have a Fibonacci number generator (a very common=20
example):</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt=
;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:=
#000000;background-color:transparent;font-weight:normal;font-style:normal;f=
ont-variant:normal;text-decoration:none;vertical-align:baseline;">(Using De=
nis Bredelet=92s proposal syntax)</span></p><p dir=3D"ltr" style=3D"line-he=
ight:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;=
font-family:Arial;color:#000000;background-color:transparent;font-weight:no=
rmal;font-style:normal;font-variant:normal;text-decoration:none;vertical-al=
ign:baseline;">void fib(int n) yields int {</span></p><p dir=3D"ltr" style=
=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font=
-size:15px;font-family:Arial;color:#000000;background-color:transparent;fon=
t-weight:normal;font-style:normal;font-variant:normal;text-decoration:none;=
vertical-align:baseline;"> int a=3D0,b=3D1;</span></p><p dir=3D"ltr" =
style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D=
"font-size:15px;font-family:Arial;color:#000000;background-color:transparen=
t;font-weight:normal;font-style:normal;font-variant:normal;text-decoration:=
none;vertical-align:baseline;"> while(n--) {</span></p><p dir=3D"ltr"=
style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline;"> int c=3Da+b;</span></p=
><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;=
"><span style=3D"font-size:15px;font-family:Arial;color:#000000;background-=
color:transparent;font-weight:normal;font-style:normal;font-variant:normal;=
text-decoration:none;vertical-align:baseline;"> a=3Db;</s=
pan></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bott=
om:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;back=
ground-color:transparent;font-weight:normal;font-style:normal;font-variant:=
normal;text-decoration:none;vertical-align:baseline;"> b=
=3Dc;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;mar=
gin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000=
000;background-color:transparent;font-weight:normal;font-style:normal;font-=
variant:normal;text-decoration:none;vertical-align:baseline;"> =
yield c;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-to=
p:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;c=
olor:#000000;background-color:transparent;font-weight:normal;font-style:nor=
mal;font-variant:normal;text-decoration:none;vertical-align:baseline;"> &nb=
sp;}</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;marg=
in-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#0000=
00;background-color:transparent;font-weight:normal;font-style:normal;font-v=
ariant:normal;text-decoration:none;vertical-align:baseline;">}</span></p><p=
dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><=
span style=3D"font-size:15px;font-family:Arial;color:#000000;background-col=
or:transparent;font-weight:normal;font-style:normal;font-variant:normal;tex=
t-decoration:none;vertical-align:baseline;">We want the possibility to writ=
e </span><span style=3D"font-size:15px;font-family:Arial;color:#000000;back=
ground-color:transparent;font-weight:normal;font-style:italic;font-variant:=
normal;text-decoration:none;vertical-align:baseline;">for (int i : fib(10))=
std::cout<<i<<=92\n=92;</span><span style=3D"font-size:15px;fo=
nt-family:Arial;color:#000000;background-color:transparent;font-weight:norm=
al;font-style:normal;font-variant:normal;text-decoration:none;vertical-alig=
n:baseline;"> to print the first 10 Fibonacci numbers.</span></p><br><span =
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:tr=
ansparent;font-weight:normal;font-style:normal;font-variant:normal;text-dec=
oration:none;vertical-align:baseline;"></span><p dir=3D"ltr" style=3D"line-=
height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15p=
x;font-family:Arial;color:#000000;background-color:transparent;font-weight:=
normal;font-style:normal;font-variant:normal;text-decoration:none;vertical-=
align:baseline;">So what am I suggest?</span></p><p dir=3D"ltr" style=3D"li=
ne-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:=
15px;font-family:Arial;color:#000000;background-color:transparent;font-weig=
ht:normal;font-style:normal;font-variant:normal;text-decoration:none;vertic=
al-align:baseline;">First,
to the syntax. Since we want it to work natively with for-range loops,=20
and since the language concept is =93declare it the way you will use =
it=94,
I would suggest using colon in the function signature. The nicest idea I
managed to think so far is </span><span style=3D"font-size:15px;font-famil=
y:Arial;color:#000000;background-color:transparent;font-weight:normal;font-=
style:italic;font-variant:normal;text-decoration:none;vertical-align:baseli=
ne;">int : fib(int n)</span></p><p dir=3D"ltr" style=3D"line-height:1.15;ma=
rgin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:=
Arial;color:#000000;background-color:transparent;font-weight:normal;font-st=
yle:normal;font-variant:normal;text-decoration:none;vertical-align:baseline=
;">Also, there is no reason to add the keyword </span><span style=3D"font-s=
ize:15px;font-family:Arial;color:#000000;background-color:transparent;font-=
weight:normal;font-style:italic;font-variant:normal;text-decoration:none;ve=
rtical-align:baseline;">yield</span><span style=3D"font-size:15px;font-fami=
ly:Arial;color:#000000;background-color:transparent;font-weight:normal;font=
-style:normal;font-variant:normal;text-decoration:none;vertical-align:basel=
ine;">, when we can stick to good old </span><span style=3D"font-size:15px;=
font-family:Arial;color:#000000;background-color:transparent;font-weight:no=
rmal;font-style:italic;font-variant:normal;text-decoration:none;vertical-al=
ign:baseline;">return</span><span style=3D"font-size:15px;font-family:Arial=
;color:#000000;background-color:transparent;font-weight:normal;font-style:n=
ormal;font-variant:normal;text-decoration:none;vertical-align:baseline;">.<=
/span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bo=
ttom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;ba=
ckground-color:transparent;font-weight:normal;font-style:normal;font-varian=
t:normal;text-decoration:none;vertical-align:baseline;">Now, to the real st=
uff: What does </span><span style=3D"font-size:15px;font-family:Arial;color=
:#000000;background-color:transparent;font-weight:normal;font-style:italic;=
font-variant:normal;text-decoration:none;vertical-align:baseline;">fib(10)<=
/span><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgro=
und-color:transparent;font-weight:normal;font-style:normal;font-variant:nor=
mal;text-decoration:none;vertical-align:baseline;"> mean? What=92s the type=
of </span><span style=3D"font-size:15px;font-family:Arial;color:#000000;ba=
ckground-color:transparent;font-weight:normal;font-style:italic;font-varian=
t:normal;text-decoration:none;vertical-align:baseline;">fib(10).begin()</sp=
an><span style=3D"font-size:15px;font-family:Arial;color:#000000;background=
-color:transparent;font-weight:normal;font-style:normal;font-variant:normal=
;text-decoration:none;vertical-align:baseline;">?</span></p><p dir=3D"ltr" =
style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D=
"font-size:15px;font-family:Arial;color:#000000;background-color:transparen=
t;font-weight:normal;font-style:normal;font-variant:normal;text-decoration:=
none;vertical-align:baseline;">I
suggest this meaning: fib will be (auto-generated) class, and an object
of it will represent calling the =93function=94 with specific parameters.=
=20
The member function </span><span style=3D"font-size:15px;font-family:Arial;=
color:#000000;background-color:transparent;font-weight:normal;font-style:it=
alic;font-variant:normal;text-decoration:none;vertical-align:baseline;">beg=
in</span><span style=3D"font-size:15px;font-family:Arial;color:#000000;back=
ground-color:transparent;font-weight:normal;font-style:normal;font-variant:=
normal;text-decoration:none;vertical-align:baseline;"> (and </span><span st=
yle=3D"font-size:15px;font-family:Arial;color:#000000;background-color:tran=
sparent;font-weight:normal;font-style:italic;font-variant:normal;text-decor=
ation:none;vertical-align:baseline;">end</span><span style=3D"font-size:15p=
x;font-family:Arial;color:#000000;background-color:transparent;font-weight:=
normal;font-style:normal;font-variant:normal;text-decoration:none;vertical-=
align:baseline;">) will return some sort of iterator, which will represent =
the actual call.</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-=
top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial=
;color:#000000;background-color:transparent;font-weight:normal;font-style:n=
ormal;font-variant:normal;text-decoration:none;vertical-align:baseline;">So=
me details: the </span><span style=3D"font-size:15px;font-family:Arial;colo=
r:#000000;background-color:transparent;font-weight:normal;font-style:italic=
;font-variant:normal;text-decoration:none;vertical-align:baseline;">fib</sp=
an><span style=3D"font-size:15px;font-family:Arial;color:#000000;background=
-color:transparent;font-weight:normal;font-style:normal;font-variant:normal=
;text-decoration:none;vertical-align:baseline;"> class should have some mem=
bers, to contain the parameters it called with, but the real fun is in the =
</span><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgr=
ound-color:transparent;font-weight:normal;font-style:italic;font-variant:no=
rmal;text-decoration:none;vertical-align:baseline;">iterator</span><span st=
yle=3D"font-size:15px;font-family:Arial;color:#000000;background-color:tran=
sparent;font-weight:normal;font-style:normal;font-variant:normal;text-decor=
ation:none;vertical-align:baseline;">
class: it will have (in addition to the parameters), as (not exactly=
, I
will explain below) members, all the local variables of the =93function=94=
=20
(including the return value), and also the information about where it=20
stopped last time (and should resume from) - let=92s call it, from now on,
=93position data=94.</span></p><p dir=3D"ltr" style=3D"line-height:1.15;ma=
rgin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:=
Arial;color:#000000;background-color:transparent;font-weight:normal;font-st=
yle:normal;font-variant:normal;text-decoration:none;vertical-align:baseline=
;">To be more precise: an </span><span style=3D"font-size:15px;font-family:=
Arial;color:#000000;background-color:transparent;font-weight:normal;font-st=
yle:italic;font-variant:normal;text-decoration:none;vertical-align:baseline=
;">iterator</span><span style=3D"font-size:15px;font-family:Arial;color:#00=
0000;background-color:transparent;font-weight:normal;font-style:normal;font=
-variant:normal;text-decoration:none;vertical-align:baseline;">
should contain the memory for the local variables (like every member=20
variable), but their lifetime will be as if they were local variables of
the =93function=94. I mean - they will been constructed only when the=20
=93function=94 will decide so, and not automatically when the </span><span =
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:tr=
ansparent;font-weight:normal;font-style:italic;font-variant:normal;text-dec=
oration:none;vertical-align:baseline;">iterator</span><span style=3D"font-s=
ize:15px;font-family:Arial;color:#000000;background-color:transparent;font-=
weight:normal;font-style:normal;font-variant:normal;text-decoration:none;ve=
rtical-align:baseline;"> is been constructed.</span></p><p dir=3D"ltr" styl=
e=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"fon=
t-size:15px;font-family:Arial;color:#000000;background-color:transparent;fo=
nt-weight:normal;font-style:normal;font-variant:normal;text-decoration:none=
;vertical-align:baseline;">When the =93function=94 ends (either by falling =
through the ending brace, not catching exception, or simply saying </span><=
span style=3D"font-size:15px;font-family:Arial;color:#000000;background-col=
or:transparent;font-weight:normal;font-style:italic;font-variant:normal;tex=
t-decoration:none;vertical-align:baseline;">return;</span><span style=3D"fo=
nt-size:15px;font-family:Arial;color:#000000;background-color:transparent;f=
ont-weight:normal;font-style:normal;font-variant:normal;text-decoration:non=
e;vertical-align:baseline;">
without a value), the position data should contain this information,=20
and (like every function), every local variable should be destructed.</span=
></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:=
0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgro=
und-color:transparent;font-weight:normal;font-style:normal;font-variant:nor=
mal;text-decoration:none;vertical-align:baseline;">Knowing
the position data let us easily determine which variables are alive,=20
and so I think that the following member functions can be automatically=20
created:</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;=
margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#=
000000;background-color:transparent;font-weight:normal;font-style:normal;fo=
nt-variant:normal;text-decoration:none;vertical-align:baseline;">copy const=
ructor - should copy the position data, the parameters, and every living lo=
cal variable</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:=
0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;col=
or:#000000;background-color:transparent;font-weight:normal;font-style:norma=
l;font-variant:normal;text-decoration:none;vertical-align:baseline;">move c=
onstructor - the same, but move instead of copy</span></p><p dir=3D"ltr" st=
yle=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"f=
ont-size:15px;font-family:Arial;color:#000000;background-color:transparent;=
font-weight:normal;font-style:normal;font-variant:normal;text-decoration:no=
ne;vertical-align:baseline;">destructor - destroy the parameters, and every=
living local variable.</span></p><p dir=3D"ltr" style=3D"line-height:1.15;=
margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-famil=
y:Arial;color:#000000;background-color:transparent;font-weight:normal;font-=
style:normal;font-variant:normal;text-decoration:none;vertical-align:baseli=
ne;">(Of course, if some local variable is noncopyable, so is the iterator)=
</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-b=
ottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;b=
ackground-color:transparent;font-weight:normal;font-style:normal;font-varia=
nt:normal;text-decoration:none;vertical-align:baseline;">I think that it sh=
ould not be assignable - If one iterator have a live object, and another on=
e have not, it=92s a real mess.</span></p><br><span style=3D"font-size:15px=
;font-family:Arial;color:#000000;background-color:transparent;font-weight:n=
ormal;font-style:normal;font-variant:normal;text-decoration:none;vertical-a=
lign:baseline;"></span><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:=
0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;col=
or:#000000;background-color:transparent;font-weight:normal;font-style:norma=
l;font-variant:normal;text-decoration:none;vertical-align:baseline;">Some e=
xample:</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;m=
argin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#0=
00000;background-color:transparent;font-weight:normal;font-style:normal;fon=
t-variant:normal;text-decoration:none;vertical-align:baseline;">Suppose
that we want to yield the number 0, and then, the first n Fibonacci=20
numbers and the first n even number, alternately. To add more interest=20
(and to demonstrate more rules), I want to create and destroy some=20
objects (assume </span><span style=3D"font-size:15px;font-family:Arial;colo=
r:#000000;background-color:transparent;font-weight:normal;font-style:italic=
;font-variant:normal;text-decoration:none;vertical-align:baseline;">A</span=
><span style=3D"font-size:15px;font-family:Arial;color:#000000;background-c=
olor:transparent;font-weight:normal;font-style:normal;font-variant:normal;t=
ext-decoration:none;vertical-align:baseline;"> is a copyable, moveable, and=
int-constructive class), so I=92ve written the following code:</span></p><=
p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;">=
<span style=3D"font-size:15px;font-family:Arial;color:#000000;background-co=
lor:transparent;font-weight:normal;font-style:normal;font-variant:normal;te=
xt-decoration:none;vertical-align:baseline;">int : fib_even(int n) {</span>=
</p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0=
pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgrou=
nd-color:transparent;font-weight:normal;font-style:normal;font-variant:norm=
al;text-decoration:none;vertical-align:baseline;"> A a(7)=
;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-=
bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;=
background-color:transparent;font-weight:normal;font-style:normal;font-vari=
ant:normal;text-decoration:none;vertical-align:baseline;"> &nbs=
p;int fib1=3D0,fib2=3D1,even=3D0;</span></p><p dir=3D"ltr" style=3D"line-he=
ight:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;=
font-family:Arial;color:#000000;background-color:transparent;font-weight:no=
rmal;font-style:normal;font-variant:normal;text-decoration:none;vertical-al=
ign:baseline;"> return 0;</span></p><p dir=3D"ltr" style=
=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font=
-size:15px;font-family:Arial;color:#000000;background-color:transparent;fon=
t-weight:normal;font-style:normal;font-variant:normal;text-decoration:none;=
vertical-align:baseline;"> while(n--) {</span></p><p dir=
=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span=
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:t=
ransparent;font-weight:normal;font-style:normal;font-variant:normal;text-de=
coration:none;vertical-align:baseline;"> &nb=
sp;int fib3=3Dfib1+fib2;</span></p><p dir=3D"ltr" style=3D"line-height:1.15=
;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-fami=
ly:Arial;color:#000000;background-color:transparent;font-weight:normal;font=
-style:normal;font-variant:normal;text-decoration:none;vertical-align:basel=
ine;"> fib1=3Dfib2;</span></p><p dir=
=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span=
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:t=
ransparent;font-weight:normal;font-style:normal;font-variant:normal;text-de=
coration:none;vertical-align:baseline;"> &nb=
sp;fib2=3Dfib3;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-t=
op:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;=
color:#000000;background-color:transparent;font-weight:normal;font-style:no=
rmal;font-variant:normal;text-decoration:none;vertical-align:baseline;"> &n=
bsp; return fib3;</span></p><p dir=3D"ltr" st=
yle=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"f=
ont-size:15px;font-family:Arial;color:#000000;background-color:transparent;=
font-weight:normal;font-style:normal;font-variant:normal;text-decoration:no=
ne;vertical-align:baseline;"> A b=3Dn;=
</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-b=
ottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;b=
ackground-color:transparent;font-weight:normal;font-style:normal;font-varia=
nt:normal;text-decoration:none;vertical-align:baseline;">  =
; return even+=3D2;</span></p><p dir=3D"ltr" style=3D"lin=
e-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:1=
5px;font-family:Arial;color:#000000;background-color:transparent;font-weigh=
t:normal;font-style:normal;font-variant:normal;text-decoration:none;vertica=
l-align:baseline;"> }</span></p><p dir=3D"ltr" style=3D"l=
ine-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size=
:15px;font-family:Arial;color:#000000;background-color:transparent;font-wei=
ght:normal;font-style:normal;font-variant:normal;text-decoration:none;verti=
cal-align:baseline;">}</span></p><br><span style=3D"font-size:15px;font-fam=
ily:Arial;color:#000000;background-color:transparent;font-weight:normal;fon=
t-style:normal;font-variant:normal;text-decoration:none;vertical-align:base=
line;"></span><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margi=
n-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#00000=
0;background-color:transparent;font-weight:normal;font-style:normal;font-va=
riant:normal;text-decoration:none;vertical-align:baseline;">A compiler may =
expand it to something like:</span></p><p dir=3D"ltr" style=3D"line-height:=
1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-=
family:Arial;color:#000000;background-color:transparent;font-weight:normal;=
font-style:normal;font-variant:normal;text-decoration:none;vertical-align:b=
aseline;">(Note:
I=92m using dynamic memory allocation, but It=92s not really how it should=
=20
be implemented - I just don=92t want some constructors and destructors to=
=20
been invoked automatically)</span></p><br><span style=3D"font-size:15px;fon=
t-family:Arial;color:#000000;background-color:transparent;font-weight:norma=
l;font-style:normal;font-variant:normal;text-decoration:none;vertical-align=
:baseline;"></span><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;=
margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#=
000000;background-color:transparent;font-weight:normal;font-style:normal;fo=
nt-variant:normal;text-decoration:none;vertical-align:baseline;">class fib_=
even {</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;ma=
rgin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#00=
0000;background-color:transparent;font-weight:normal;font-style:normal;font=
-variant:normal;text-decoration:none;vertical-align:baseline;">  =
; class iterator {</span></p><p dir=3D"ltr" style=3D"line-height:1.15;=
margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-famil=
y:Arial;color:#000000;background-color:transparent;font-weight:normal;font-=
style:normal;font-variant:normal;text-decoration:none;vertical-align:baseli=
ne;"> int n;</span></p><p dir=3D"ltr" =
style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D=
"font-size:15px;font-family:Arial;color:#000000;background-color:transparen=
t;font-weight:normal;font-style:normal;font-variant:normal;text-decoration:=
none;vertical-align:baseline;"> int *f=
ib1,*fib2,*fib3,*even;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;m=
argin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family=
:Arial;color:#000000;background-color:transparent;font-weight:normal;font-s=
tyle:normal;font-variant:normal;text-decoration:none;vertical-align:baselin=
e;"> A *a,*b;</span></p><p dir=3D"ltr"=
style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline;"> int=
*ret_value;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:=
0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;col=
or:#000000;background-color:transparent;font-weight:normal;font-style:norma=
l;font-variant:normal;text-decoration:none;vertical-align:baseline;">  =
; enum {p0,p1,p2,p3,p4} pos; //resuming point=
s<br></span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;mar=
gin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000=
000;background-color:transparent;font-weight:normal;font-style:normal;font-=
variant:normal;text-decoration:none;vertical-align:baseline;"> =
void next() {</span></p><p dir=3D"ltr" style=3D"li=
ne-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:=
15px;font-family:Arial;color:#000000;background-color:transparent;font-weig=
ht:normal;font-style:normal;font-variant:normal;text-decoration:none;vertic=
al-align:baseline;"> &nbs=
p;switch (pos) {</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-=
top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial=
;color:#000000;background-color:transparent;font-weight:normal;font-style:n=
ormal;font-variant:normal;text-decoration:none;vertical-align:baseline;"> &=
nbsp; c=
ase p0: break;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-to=
p:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;c=
olor:#000000;background-color:transparent;font-weight:normal;font-style:nor=
mal;font-variant:normal;text-decoration:none;vertical-align:baseline;"> &nb=
sp; cas=
e p1: goto label1;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margi=
n-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Ari=
al;color:#000000;background-color:transparent;font-weight:normal;font-style=
:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;">=
 =
;case p2: goto label2;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;m=
argin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family=
:Arial;color:#000000;background-color:transparent;font-weight:normal;font-s=
tyle:normal;font-variant:normal;text-decoration:none;vertical-align:baselin=
e;"> &=
nbsp;case p3: goto label3;</span></p><p dir=3D"ltr" style=3D"line-height:1.=
15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-fa=
mily:Arial;color:#000000;background-color:transparent;font-weight:normal;fo=
nt-style:normal;font-variant:normal;text-decoration:none;vertical-align:bas=
eline;"> &nbs=
p; case p4: return;</span></p><p dir=3D"ltr" style=3D"line-height:1.1=
5;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-fam=
ily:Arial;color:#000000;background-color:transparent;font-weight:normal;fon=
t-style:normal;font-variant:normal;text-decoration:none;vertical-align:base=
line;"> }</span></p=
><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;=
"><span style=3D"font-size:15px;font-family:Arial;color:#000000;background-=
color:transparent;font-weight:normal;font-style:normal;font-variant:normal;=
text-decoration:none;vertical-align:baseline;">//construct automatic variab=
les of t</span><span style=3D"font-size:15px;font-family:Arial;color:#00000=
0;background-color:transparent;font-weight:normal;font-style:normal;font-va=
riant:normal;text-decoration:none;vertical-align:baseline;">he function<br>=
</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-b=
ottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;b=
ackground-color:transparent;font-weight:normal;font-style:normal;font-varia=
nt:normal;text-decoration:none;vertical-align:baseline;">  =
; a=3Dnew A(7);</span></p><p dir=3D"lt=
r" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline;"> &nb=
sp; fib1=3Dnew int(0);</span></p><p dir=3D"ltr" style=3D"line-h=
eight:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px=
;font-family:Arial;color:#000000;background-color:transparent;font-weight:n=
ormal;font-style:normal;font-variant:normal;text-decoration:none;vertical-a=
lign:baseline;"> fi=
b2=3Dnew int(1);</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-=
top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial=
;color:#000000;background-color:transparent;font-weight:normal;font-style:n=
ormal;font-variant:normal;text-decoration:none;vertical-align:baseline;"> &=
nbsp; even=3Dnew int(0);</=
span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bot=
tom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;bac=
kground-color:transparent;font-weight:normal;font-style:normal;font-variant=
:normal;text-decoration:none;vertical-align:baseline;">//t</span><span styl=
e=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transp=
arent;font-weight:normal;font-style:normal;font-variant:normal;text-decorat=
ion:none;vertical-align:baseline;">he return process - create t</span><span=
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:t=
ransparent;font-weight:normal;font-style:normal;font-variant:normal;text-de=
coration:none;vertical-align:baseline;">he value, save t</span><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline;">he resuming point, and return<br></span><=
/p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0p=
t;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgroun=
d-color:transparent;font-weight:normal;font-style:normal;font-variant:norma=
l;text-decoration:none;vertical-align:baseline;"> &=
nbsp; ret_value=3Dnew int(0);</span></p><p dir=3D"=
ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span sty=
le=3D"font-size:15px;font-family:Arial;color:#000000;background-color:trans=
parent;font-weight:normal;font-style:normal;font-variant:normal;text-decora=
tion:none;vertical-align:baseline;"> &=
nbsp; pos=3Dp1;</span></p><p dir=3D"ltr" style=3D"line-height:1=
..15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-f=
amily:Arial;color:#000000;background-color:transparent;font-weight:normal;f=
ont-style:normal;font-variant:normal;text-decoration:none;vertical-align:ba=
seline;"> return;</=
span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bot=
tom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;bac=
kground-color:transparent;font-weight:normal;font-style:normal;font-variant=
:normal;text-decoration:none;vertical-align:baseline;"> &=
nbsp; label1:<br></span></p><p dir=3D"ltr" style=3D"line-height=
:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font=
-family:Arial;color:#000000;background-color:transparent;font-weight:normal=
;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:=
baseline;"> while(n=
--) {</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;mar=
gin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000=
000;background-color:transparent;font-weight:normal;font-style:normal;font-=
variant:normal;text-decoration:none;vertical-align:baseline;"> =
fib3=3Dnew i=
nt(*fib1+*fib2); //being constructed only now<br></span></p><p dir=3D"ltr" =
style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D=
"font-size:15px;font-family:Arial;color:#000000;background-color:transparen=
t;font-weight:normal;font-style:normal;font-variant:normal;text-decoration:=
none;vertical-align:baseline;"> =
*fib1=3D*fib2;</span></p><p dir=3D"ltr" sty=
le=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"fo=
nt-size:15px;font-family:Arial;color:#000000;background-color:transparent;f=
ont-weight:normal;font-style:normal;font-variant:normal;text-decoration:non=
e;vertical-align:baseline;"> &nb=
sp; *fib2=3D*fib3;</span></p><p dir=3D"ltr" style=
=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font=
-size:15px;font-family:Arial;color:#000000;background-color:transparent;fon=
t-weight:normal;font-style:normal;font-variant:normal;text-decoration:none;=
vertical-align:baseline;">  =
; ret_value=3Dnew int(*fib3);</span></p><p dir=3D"=
ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span sty=
le=3D"font-size:15px;font-family:Arial;color:#000000;background-color:trans=
parent;font-weight:normal;font-style:normal;font-variant:normal;text-decora=
tion:none;vertical-align:baseline;"> &=
nbsp; pos=3Dp2;</span></p><p dir=3D"ltr" sty=
le=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"fo=
nt-size:15px;font-family:Arial;color:#000000;background-color:transparent;f=
ont-weight:normal;font-style:normal;font-variant:normal;text-decoration:non=
e;vertical-align:baseline;"> &nb=
sp; return;</span></p><p dir=3D"ltr" style=3D"line=
-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15=
px;font-family:Arial;color:#000000;background-color:transparent;font-weight=
:normal;font-style:normal;font-variant:normal;text-decoration:none;vertical=
-align:baseline;"> label2:</span></p><=
p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;">=
<span style=3D"font-size:15px;font-family:Arial;color:#000000;background-co=
lor:transparent;font-weight:normal;font-style:normal;font-variant:normal;te=
xt-decoration:none;vertical-align:baseline;">  =
; b=3Dnew A(n);</span></p><p di=
r=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><spa=
n style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:=
transparent;font-weight:normal;font-style:normal;font-variant:normal;text-d=
ecoration:none;vertical-align:baseline;"> &n=
bsp; ret_value=3Dnew int((*even)+=3D2)=
;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-=
bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;=
background-color:transparent;font-weight:normal;font-style:normal;font-vari=
ant:normal;text-decoration:none;vertical-align:baseline;"> &nbs=
p; pos=3Dp3;</span>=
</p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0=
pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgrou=
nd-color:transparent;font-weight:normal;font-style:normal;font-variant:norm=
al;text-decoration:none;vertical-align:baseline;"> =
return;</span></p><p dir=
=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span=
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:t=
ransparent;font-weight:normal;font-style:normal;font-variant:normal;text-de=
coration:none;vertical-align:baseline;"> &nb=
sp;label3:</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0p=
t;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color=
:#000000;background-color:transparent;font-weight:normal;font-style:normal;=
font-variant:normal;text-decoration:none;vertical-align:baseline;">//automa=
tic variables going out of scope, and s</span><span style=3D"font-size:15px=
;font-family:Arial;color:#000000;background-color:transparent;font-weight:n=
ormal;font-style:normal;font-variant:normal;text-decoration:none;vertical-a=
lign:baseline;"><span style=3D"font-size:15px;font-family:Arial;color:#0000=
00;background-color:transparent;font-weight:normal;font-style:normal;font-v=
ariant:normal;text-decoration:none;vertical-align:baseline;">h</span>ould b=
e destructed<br></span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-=
top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial=
;color:#000000;background-color:transparent;font-weight:normal;font-style:n=
ormal;font-variant:normal;text-decoration:none;vertical-align:baseline;"> &=
nbsp; d=
elete b;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;=
margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#=
000000;background-color:transparent;font-weight:normal;font-style:normal;fo=
nt-variant:normal;text-decoration:none;vertical-align:baseline;"> &nb=
sp; delete fi=
b3;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margi=
n-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#00000=
0;background-color:transparent;font-weight:normal;font-style:normal;font-va=
riant:normal;text-decoration:none;vertical-align:baseline;"> &n=
bsp; }</span></p><p dir=3D"ltr" style=
=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font=
-size:15px;font-family:Arial;color:#000000;background-color:transparent;fon=
t-weight:normal;font-style:normal;font-variant:normal;text-decoration:none;=
vertical-align:baseline;">  =
; delete even;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;mar=
gin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:A=
rial;color:#000000;background-color:transparent;font-weight:normal;font-sty=
le:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;=
"> delete fib2;</sp=
an></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-botto=
m:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backg=
round-color:transparent;font-weight:normal;font-style:normal;font-variant:n=
ormal;text-decoration:none;vertical-align:baseline;"> &nb=
sp; delete fib1;</span></p><p dir=3D"ltr" st=
yle=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"f=
ont-size:15px;font-family:Arial;color:#000000;background-color:transparent;=
font-weight:normal;font-style:normal;font-variant:normal;text-decoration:no=
ne;vertical-align:baseline;"> &n=
bsp; delete a;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;mar=
gin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:A=
rial;color:#000000;background-color:transparent;font-weight:normal;font-sty=
le:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;=
"> pos=3Dp4;</span>=
</p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0=
pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgrou=
nd-color:transparent;font-weight:normal;font-style:normal;font-variant:norm=
al;text-decoration:none;vertical-align:baseline;"> =
}</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-to=
p:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;c=
olor:#000000;background-color:transparent;font-weight:normal;font-style:nor=
mal;font-variant:normal;text-decoration:none;vertical-align:baseline;"> &nb=
sp; iterator(int n) : n(n),pos(p0) {</span></=
p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt=
;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;background=
-color:transparent;font-weight:normal;font-style:normal;font-variant:normal=
;text-decoration:none;vertical-align:baseline;"> &n=
bsp; next(); //get t</span><span style=3D"font-siz=
e:15px;font-family:Arial;color:#000000;background-color:transparent;font-we=
ight:normal;font-style:normal;font-variant:normal;text-decoration:none;vert=
ical-align:baseline;">he first value<br></span></p><p dir=3D"ltr" style=3D"=
line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-siz=
e:15px;font-family:Arial;color:#000000;background-color:transparent;font-we=
ight:normal;font-style:normal;font-variant:normal;text-decoration:none;vert=
ical-align:baseline;"> }</span></p><p =
dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><s=
pan style=3D"font-size:15px;font-family:Arial;color:#000000;background-colo=
r:transparent;font-weight:normal;font-style:normal;font-variant:normal;text=
-decoration:none;vertical-align:baseline;"> =
iterator() : pos(p4) {}</span></p><p dir=3D"ltr" style=3D"line-height=
:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font=
-family:Arial;color:#000000;background-color:transparent;font-weight:normal=
;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:=
baseline;"> public:</span></p><p dir=3D"ltr" style=3D"lin=
e-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:1=
5px;font-family:Arial;color:#000000;background-color:transparent;font-weigh=
t:normal;font-style:normal;font-variant:normal;text-decoration:none;vertica=
l-align:baseline;"> iterator &oper=
ator++() {</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0p=
t;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color=
:#000000;background-color:transparent;font-weight:normal;font-style:normal;=
font-variant:normal;text-decoration:none;vertical-align:baseline;"> &=
nbsp; delete ret_value;</span></=
p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt=
;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;background=
-color:transparent;font-weight:normal;font-style:normal;font-variant:normal=
;text-decoration:none;vertical-align:baseline;"> &n=
bsp; next();</span></p><p dir=3D"ltr" style=3D"lin=
e-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:1=
5px;font-family:Arial;color:#000000;background-color:transparent;font-weigh=
t:normal;font-style:normal;font-variant:normal;text-decoration:none;vertica=
l-align:baseline;">  =
;return *this;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-to=
p:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;c=
olor:#000000;background-color:transparent;font-weight:normal;font-style:nor=
mal;font-variant:normal;text-decoration:none;vertical-align:baseline;"> &nb=
sp; }</span></p><p dir=3D"ltr" style=3D"line-=
height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15p=
x;font-family:Arial;color:#000000;background-color:transparent;font-weight:=
normal;font-style:normal;font-variant:normal;text-decoration:none;vertical-=
align:baseline;"> int &operator*()=
{</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin=
-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000=
;background-color:transparent;font-weight:normal;font-style:normal;font-var=
iant:normal;text-decoration:none;vertical-align:baseline;"> &nb=
sp; return *ret_value;</span></p><p di=
r=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><spa=
n style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:=
transparent;font-weight:normal;font-style:normal;font-variant:normal;text-d=
ecoration:none;vertical-align:baseline;"> &n=
bsp;}</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;mar=
gin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000=
000;background-color:transparent;font-weight:normal;font-style:normal;font-=
variant:normal;text-decoration:none;vertical-align:baseline;"> =
iterator(const iterator &it) : n(it.n),pos(it.=
pos) {</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;ma=
rgin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#00=
0000;background-color:transparent;font-weight:normal;font-style:normal;font=
-variant:normal;text-decoration:none;vertical-align:baseline;">//copy only =
living members<br></span></p><p dir=3D"ltr" style=3D"line-height:1.15;margi=
n-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Ari=
al;color:#000000;background-color:transparent;font-weight:normal;font-style=
:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;">=
if (pos>p0 &=
;& pos<p4) {</span></p><p dir=3D"ltr" style=3D"line-height:1.15;marg=
in-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Ar=
ial;color:#000000;background-color:transparent;font-weight:normal;font-styl=
e:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;"=
> &nbs=
p;ret_value=3Dnew int(*it.ret_value);</span></p><p dir=3D"ltr" style=3D"lin=
e-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:1=
5px;font-family:Arial;color:#000000;background-color:transparent;font-weigh=
t:normal;font-style:normal;font-variant:normal;text-decoration:none;vertica=
l-align:baseline;">  =
; a=3Dnew A(*it.a);</span></p><p dir=3D"ltr" style=3D"lin=
e-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:1=
5px;font-family:Arial;color:#000000;background-color:transparent;font-weigh=
t:normal;font-style:normal;font-variant:normal;text-decoration:none;vertica=
l-align:baseline;">  =
; fib1=3Dnew int(*it.fib1);</span></p><p dir=3D"ltr" styl=
e=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"fon=
t-size:15px;font-family:Arial;color:#000000;background-color:transparent;fo=
nt-weight:normal;font-style:normal;font-variant:normal;text-decoration:none=
;vertical-align:baseline;"> &nbs=
p; fib2=3Dnew int(*it.fib2);</span></p><p dir=3D"l=
tr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span styl=
e=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transp=
arent;font-weight:normal;font-style:normal;font-variant:normal;text-decorat=
ion:none;vertical-align:baseline;"> &n=
bsp; even=3Dnew int(*it.even);</span></p><p =
dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><s=
pan style=3D"font-size:15px;font-family:Arial;color:#000000;background-colo=
r:transparent;font-weight:normal;font-style:normal;font-variant:normal;text=
-decoration:none;vertical-align:baseline;"> =
}</span></p><p dir=3D"ltr" style=3D"line-height:1.=
15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-fa=
mily:Arial;color:#000000;background-color:transparent;font-weight:normal;fo=
nt-style:normal;font-variant:normal;text-decoration:none;vertical-align:bas=
eline;"> if (pos>=
;p1 && pos<p4) fib3=3Dnew int(*it.fib3);</span></p><p dir=3D"ltr=
" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline;"> &nb=
sp; if (pos>p2 && pos<p4) b=3Dnew A(*it.b);</span=
></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:=
0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgro=
und-color:transparent;font-weight:normal;font-style:normal;font-variant:nor=
mal;text-decoration:none;vertical-align:baseline;">  =
; }</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-t=
op:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;=
color:#000000;background-color:transparent;font-weight:normal;font-style:no=
rmal;font-variant:normal;text-decoration:none;vertical-align:baseline;"> &n=
bsp; iterator(iterator &&it) : n(std:=
:move(it.n)),pos(it.pos) {</span></p><p dir=3D"ltr" style=3D"line-height:1.=
15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-fa=
mily:Arial;color:#000000;background-color:transparent;font-weight:normal;fo=
nt-style:normal;font-variant:normal;text-decoration:none;vertical-align:bas=
eline;"> if (pos>=
;p0 && pos<p4) {</span></p><p dir=3D"ltr" style=3D"line-height:1=
..15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-f=
amily:Arial;color:#000000;background-color:transparent;font-weight:normal;f=
ont-style:normal;font-variant:normal;text-decoration:none;vertical-align:ba=
seline;"> &nb=
sp; ret_value=3Dnew int(std::move(*it.ret_value));</span></p><p dir=
=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span=
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:t=
ransparent;font-weight:normal;font-style:normal;font-variant:normal;text-de=
coration:none;vertical-align:baseline;"> &nb=
sp; a=3Dnew A(std::move(*it.a));</span=
></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:=
0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgro=
und-color:transparent;font-weight:normal;font-style:normal;font-variant:nor=
mal;text-decoration:none;vertical-align:baseline;">  =
; fib1=3Dnew int(std::mov=
e(*it.fib1));</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top=
:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;co=
lor:#000000;background-color:transparent;font-weight:normal;font-style:norm=
al;font-variant:normal;text-decoration:none;vertical-align:baseline;"> &nbs=
p; fib2=
=3Dnew int(std::move(*it.fib2));</span></p><p dir=3D"ltr" style=3D"line-hei=
ght:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;f=
ont-family:Arial;color:#000000;background-color:transparent;font-weight:nor=
mal;font-style:normal;font-variant:normal;text-decoration:none;vertical-ali=
gn:baseline;"> &nbs=
p; even=3Dnew int(std::move(*it.even));</span></p><p dir=3D"ltr=
" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline;"> &nb=
sp; }</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin=
-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Aria=
l;color:#000000;background-color:transparent;font-weight:normal;font-style:=
normal;font-variant:normal;text-decoration:none;vertical-align:baseline;"> =
if (pos>p1 &=
& pos<p4) fib3=3Dnew int(std::move(*it.fib3));</span></p><p dir=3D"l=
tr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span styl=
e=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transp=
arent;font-weight:normal;font-style:normal;font-variant:normal;text-decorat=
ion:none;vertical-align:baseline;"> &n=
bsp; if (pos>p2 && pos<p4) b=3Dnew A(std::move(*i=
t.b));</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;ma=
rgin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#00=
0000;background-color:transparent;font-weight:normal;font-style:normal;font=
-variant:normal;text-decoration:none;vertical-align:baseline;">  =
; }</span></p><p dir=3D"ltr" style=3D"line-height:1=
..15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-f=
amily:Arial;color:#000000;background-color:transparent;font-weight:normal;f=
ont-style:normal;font-variant:normal;text-decoration:none;vertical-align:ba=
seline;"> ~iterator() {</span></p><p d=
ir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><sp=
an style=3D"font-size:15px;font-family:Arial;color:#000000;background-color=
:transparent;font-weight:normal;font-style:normal;font-variant:normal;text-=
decoration:none;vertical-align:baseline;"> &=
nbsp; if (pos>p2 && pos<p4) delete b;</span=
></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:=
0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgro=
und-color:transparent;font-weight:normal;font-style:normal;font-variant:nor=
mal;text-decoration:none;vertical-align:baseline;">  =
; if (pos>p1 && pos<p4) delete=
fib3;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;ma=
rgin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#00=
0000;background-color:transparent;font-weight:normal;font-style:normal;font=
-variant:normal;text-decoration:none;vertical-align:baseline;">  =
; if (pos>p0 && pos&l=
t;p4) {</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;m=
argin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#0=
00000;background-color:transparent;font-weight:normal;font-style:normal;fon=
t-variant:normal;text-decoration:none;vertical-align:baseline;"> &nbs=
p; delete eve=
n;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin=
-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000=
;background-color:transparent;font-weight:normal;font-style:normal;font-var=
iant:normal;text-decoration:none;vertical-align:baseline;"> &nb=
sp; delete fib2;</s=
pan></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bott=
om:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;back=
ground-color:transparent;font-weight:normal;font-style:normal;font-variant:=
normal;text-decoration:none;vertical-align:baseline;"> &n=
bsp; delete fib1;</span><=
/p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0p=
t;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgroun=
d-color:transparent;font-weight:normal;font-style:normal;font-variant:norma=
l;text-decoration:none;vertical-align:baseline;"> &=
nbsp; delete a;</span></p><p di=
r=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><spa=
n style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:=
transparent;font-weight:normal;font-style:normal;font-variant:normal;text-d=
ecoration:none;vertical-align:baseline;"> &n=
bsp; delete ret_value;</span></p><p di=
r=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><spa=
n style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:=
transparent;font-weight:normal;font-style:normal;font-variant:normal;text-d=
ecoration:none;vertical-align:baseline;"> &n=
bsp; }</span></p><p dir=3D"ltr" style=3D"line-height:1.15=
;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-fami=
ly:Arial;color:#000000;background-color:transparent;font-weight:normal;font=
-style:normal;font-variant:normal;text-decoration:none;vertical-align:basel=
ine;"> }</span></p><p dir=3D"ltr" styl=
e=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"fon=
t-size:15px;font-family:Arial;color:#000000;background-color:transparent;fo=
nt-weight:normal;font-style:normal;font-variant:normal;text-decoration:none=
;vertical-align:baseline;"> bool opera=
tor!=3D(const iterator &it) {</span></p><p dir=3D"ltr" style=3D"line-he=
ight:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;=
font-family:Arial;color:#000000;background-color:transparent;font-weight:no=
rmal;font-style:normal;font-variant:normal;text-decoration:none;vertical-al=
ign:baseline;"> ret=
urn pos!=3Dit.pos;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margi=
n-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Ari=
al;color:#000000;background-color:transparent;font-weight:normal;font-style=
:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;">=
}</span></p><p dir=3D"ltr" style=3D"l=
ine-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size=
:15px;font-family:Arial;color:#000000;background-color:transparent;font-wei=
ght:normal;font-style:normal;font-variant:normal;text-decoration:none;verti=
cal-align:baseline;"> operator bool() =
{</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-=
bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;=
background-color:transparent;font-weight:normal;font-style:normal;font-vari=
ant:normal;text-decoration:none;vertical-align:baseline;"> &nbs=
p; return pos<p4; //still </span><s=
pan style=3D"font-size:15px;font-family:Arial;color:#000000;background-colo=
r:transparent;font-weight:normal;font-style:normal;font-variant:normal;text=
-decoration:none;vertical-align:baseline;">hasn't ended<br></span></p><p di=
r=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><spa=
n style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:=
transparent;font-weight:normal;font-style:normal;font-variant:normal;text-d=
ecoration:none;vertical-align:baseline;"> &n=
bsp;}</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;mar=
gin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000=
000;background-color:transparent;font-weight:normal;font-style:normal;font-=
variant:normal;text-decoration:none;vertical-align:baseline;"> =
iterator &operator=3D(const iterator&) =3D=
delete;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;=
margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#=
000000;background-color:transparent;font-weight:normal;font-style:normal;fo=
nt-variant:normal;text-decoration:none;vertical-align:baseline;"> &nb=
sp; friend fib_even;</span></p><p dir=3D"ltr" style=
=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font=
-size:15px;font-family:Arial;color:#000000;background-color:transparent;fon=
t-weight:normal;font-style:normal;font-variant:normal;text-decoration:none;=
vertical-align:baseline;"> };</span></p><p dir=3D"ltr" st=
yle=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"f=
ont-size:15px;font-family:Arial;color:#000000;background-color:transparent;=
font-weight:normal;font-style:normal;font-variant:normal;text-decoration:no=
ne;vertical-align:baseline;"> int n;</span></p><p dir=3D"=
ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span sty=
le=3D"font-size:15px;font-family:Arial;color:#000000;background-color:trans=
parent;font-weight:normal;font-style:normal;font-variant:normal;text-decora=
tion:none;vertical-align:baseline;">public:</span></p><p dir=3D"ltr" style=
=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font=
-size:15px;font-family:Arial;color:#000000;background-color:transparent;fon=
t-weight:normal;font-style:normal;font-variant:normal;text-decoration:none;=
vertical-align:baseline;"> fib_even(int n) : n(n) {}</spa=
n></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom=
:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgr=
ound-color:transparent;font-weight:normal;font-style:normal;font-variant:no=
rmal;text-decoration:none;vertical-align:baseline;"> iter=
ator begin() {</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-to=
p:0pt;margin-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;c=
olor:#000000;background-color:transparent;font-weight:normal;font-style:nor=
mal;font-variant:normal;text-decoration:none;vertical-align:baseline;"> &nb=
sp; return iterator(n);</span></p><p dir=3D"l=
tr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span styl=
e=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transp=
arent;font-weight:normal;font-style:normal;font-variant:normal;text-decorat=
ion:none;vertical-align:baseline;"> }</span></p><p dir=3D=
"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span st=
yle=3D"font-size:15px;font-family:Arial;color:#000000;background-color:tran=
sparent;font-weight:normal;font-style:normal;font-variant:normal;text-decor=
ation:none;vertical-align:baseline;"> iterator end() {</s=
pan></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bott=
om:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000;back=
ground-color:transparent;font-weight:normal;font-style:normal;font-variant:=
normal;text-decoration:none;vertical-align:baseline;"> &n=
bsp; return iterator();</span></p><p dir=3D"ltr" style=3D"line-=
height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:15p=
x;font-family:Arial;color:#000000;background-color:transparent;font-weight:=
normal;font-style:normal;font-variant:normal;text-decoration:none;vertical-=
align:baseline;"> }</span></p><p dir=3D"ltr" style=3D"lin=
e-height:1.15;margin-top:0pt;margin-bottom:0pt;"><span style=3D"font-size:1=
5px;font-family:Arial;color:#000000;background-color:transparent;font-weigh=
t:normal;font-style:normal;font-variant:normal;text-decoration:none;vertica=
l-align:baseline;">};</span></p><br><span style=3D"font-size:15px;font-fami=
ly:Arial;color:#000000;background-color:transparent;font-weight:normal;font=
-style:normal;font-variant:normal;text-decoration:none;vertical-align:basel=
ine;"></span><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin=
-bottom:0pt;"><span style=3D"font-size:15px;font-family:Arial;color:#000000=
;background-color:transparent;font-weight:normal;font-style:normal;font-var=
iant:normal;text-decoration:none;vertical-align:baseline;">So, what do you =
think?</span></p>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
<br />
<br />
------=_Part_2129_3026738.1372297258221--
.
Author: Xeo <hivemaster@hotmail.de>
Date: Thu, 27 Jun 2013 01:53:53 -0700 (PDT)
Raw View
------=_Part_87_21569202.1372323233185
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
While I really want to get my hands on native coroutines, I don't think=20
your approach works very well.
1) Who says we always want to use coroutines as `for(auto r : coro(args))`?=
=20
I don't think that's necessarily the main form of use
2) How would the transformation to a class work for template argument=20
deduction?
I think a better course would be to transform the return type of such a=20
function, as would be done with async/await-style functions.
The returned type would then simply have an `operator()` and if you wanted=
=20
a range from that, it could be quite easily done with a general=20
function-adaptor.
On Thursday, June 27, 2013 3:40:58 AM UTC+2, asa...@gmail.com wrote:
>
> Recently, I=92ve thought a lot about coroutines, and how they should beha=
ve=20
> if became a part of c++.
>
> I found two (main) proposals:
>
> a.=20
> https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/3g6ZIW=
edGJ8
>
> It has the advantage of not requiring to change the syntax, but in force =
a=20
> new model of stack-based calls. It does so in purpose to let nested=20
> functions to yield value, which I think is not really necessary. (If we l=
et=20
> nested functions return value on behalf of their callee, we should start=
=20
> this in regular functions). Also, Its syntax is somehow complex.
>
> b.=20
> https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/PPZJVT=
DdDVQ
>
> It is easy to use and doesn=92t require a new stack, and I think that thi=
s=20
> is the right direction. However, it ignores some technical details=20
> (lifetime of locals, etc). Also, adding a keyword may break too many=20
> working code, and my personal opinion is that it is ugly. Sentences like=
=20
> =93void numbers() yields int=94 reminds me too many things I hate in Java=
.. The=20
> alternative syntax (described at the end of this proposal) is not so ugly=
,=20
> but still complex.
>
> There is even a nice implementation of coroutines (using macros):=20
> http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
>
> but it has 2 major disadvantages: while using it, we can=92t yield a valu=
e=20
> from within a switch statement, and, much more important, we have to defi=
ne=20
> all the local variables at the top of the function - back to C90 days! (a=
nd=20
> with constructors this is much worst.)
>
> Another thing that was very little talk about, is for-range loops native=
=20
> support. Let=92s say we have a Fibonacci number generator (a very common=
=20
> example):
>
> (Using Denis Bredelet=92s proposal syntax)
>
> void fib(int n) yields int {
>
> int a=3D0,b=3D1;
>
> while(n--) {
>
> int c=3Da+b;
>
> a=3Db;
>
> b=3Dc;
>
> yield c;
>
> }
>
> }
>
> We want the possibility to write for (int i : fib(10)) std::cout<<i<<=92\=
n=92;to print the first 10 Fibonacci numbers.
>
> So what am I suggest?
>
> First, to the syntax. Since we want it to work natively with for-range=20
> loops, and since the language concept is =93declare it the way you will =
use=20
> it=94, I would suggest using colon in the function signature. The nicest =
idea=20
> I managed to think so far is int : fib(int n)
>
> Also, there is no reason to add the keyword yield, when we can stick to=
=20
> good old return.
>
> Now, to the real stuff: What does fib(10) mean? What=92s the type of=20
> fib(10).begin()?
>
> I suggest this meaning: fib will be (auto-generated) class, and an object=
=20
> of it will represent calling the =93function=94 with specific parameters.=
The=20
> member function begin (and end) will return some sort of iterator, which=
=20
> will represent the actual call.
>
> Some details: the fib class should have some members, to contain the=20
> parameters it called with, but the real fun is in the iterator class: it=
=20
> will have (in addition to the parameters), as (not exactly, I will expla=
in=20
> below) members, all the local variables of the =93function=94 (including =
the=20
> return value), and also the information about where it stopped last time=
=20
> (and should resume from) - let=92s call it, from now on, =93position data=
=94.
>
> To be more precise: an iterator should contain the memory for the local=
=20
> variables (like every member variable), but their lifetime will be as if=
=20
> they were local variables of the =93function=94. I mean - they will been=
=20
> constructed only when the =93function=94 will decide so, and not automati=
cally=20
> when the iterator is been constructed.
>
> When the =93function=94 ends (either by falling through the ending brace,=
not=20
> catching exception, or simply saying return; without a value), the=20
> position data should contain this information, and (like every function),=
=20
> every local variable should be destructed.
>
> Knowing the position data let us easily determine which variables are=20
> alive, and so I think that the following member functions can be=20
> automatically created:
>
> copy constructor - should copy the position data, the parameters, and=20
> every living local variable
>
> move constructor - the same, but move instead of copy
>
> destructor - destroy the parameters, and every living local variable.
>
> (Of course, if some local variable is noncopyable, so is the iterator)
>
> I think that it should not be assignable - If one iterator have a live=20
> object, and another one have not, it=92s a real mess.
>
> Some example:
>
> Suppose that we want to yield the number 0, and then, the first n=20
> Fibonacci numbers and the first n even number, alternately. To add more=
=20
> interest (and to demonstrate more rules), I want to create and destroy so=
me=20
> objects (assume A is a copyable, moveable, and int-constructive class),=
=20
> so I=92ve written the following code:
>
> int : fib_even(int n) {
>
> A a(7);
>
> int fib1=3D0,fib2=3D1,even=3D0;
>
> return 0;
>
> while(n--) {
>
> int fib3=3Dfib1+fib2;
>
> fib1=3Dfib2;
>
> fib2=3Dfib3;
>
> return fib3;
>
> A b=3Dn;
>
> return even+=3D2;
>
> }
>
> }
>
> A compiler may expand it to something like:
>
> (Note: I=92m using dynamic memory allocation, but It=92s not really how i=
t=20
> should be implemented - I just don=92t want some constructors and destruc=
tors=20
> to been invoked automatically)
>
> class fib_even {
>
> class iterator {
>
> int n;
>
> int *fib1,*fib2,*fib3,*even;
>
> A *a,*b;
>
> int *ret_value;
>
> enum {p0,p1,p2,p3,p4} pos; //resuming points
>
> void next() {
>
> switch (pos) {
>
> case p0: break;
>
> case p1: goto label1;
>
> case p2: goto label2;
>
> case p3: goto label3;
>
> case p4: return;
>
> }
>
> //construct automatic variables of the function
>
> a=3Dnew A(7);
>
> fib1=3Dnew int(0);
>
> fib2=3Dnew int(1);
>
> even=3Dnew int(0);
>
> //the return process - create the value, save the resuming point, and=20
> return
>
> ret_value=3Dnew int(0);
>
> pos=3Dp1;
>
> return;
>
> label1:
>
> while(n--) {
>
> fib3=3Dnew int(*fib1+*fib2); //being constructed only now
>
> *fib1=3D*fib2;
>
> *fib2=3D*fib3;
>
> ret_value=3Dnew int(*fib3);
>
> pos=3Dp2;
>
> return;
>
> label2:
>
> b=3Dnew A(n);
>
> ret_value=3Dnew int((*even)+=3D2);
>
> pos=3Dp3;
>
> return;
>
> label3:
>
> //automatic variables going out of scope, and should be destructed
>
> delete b;
>
> delete fib3;
>
> }
>
> delete even;
>
> delete fib2;
>
> delete fib1;
>
> delete a;
>
> pos=3Dp4;
>
> }
>
> iterator(int n) : n(n),pos(p0) {
>
> next(); //get the first value
>
> }
>
> iterator() : pos(p4) {}
>
> public:
>
> iterator &operator++() {
>
> delete ret_value;
>
> next();
>
> return *this;
>
> }
>
> int &operator*() {
>
> return *ret_value;
>
> }
>
> iterator(const iterator &it) : n(it.n),pos(it.pos) {
>
> //copy only living members
>
> if (pos>p0 && pos<p4) {
>
> ret_value=3Dnew int(*it.ret_value);
>
> a=3Dnew A(*it.a);
>
> fib1=3Dnew int(*it.fib1);
>
> fib2=3Dnew int(*it.fib2);
>
> even=3Dnew int(*it.even);
>
> }
>
> if (pos>p1 && pos<p4) fib3=3Dnew int(*it.fib3);
>
> if (pos>p2 && pos<p4) b=3Dnew A(*it.b);
>
> }
>
> iterator(iterator &&it) : n(std::move(it.n)),pos(it.pos) {
>
> if (pos>p0 && pos<p4) {
>
> ret_value=3Dnew int(std::move(*it.ret_value));
>
> a=3Dnew A(std::move(*it.a));
>
> fib1=3Dnew int(std::move(*it.fib1));
>
> fib2=3Dnew int(std::move(*it.fib2));
>
> even=3Dnew int(std::move(*it.even));
>
> }
>
> if (pos>p1 && pos<p4) fib3=3Dnew int(std::move(*it.fib3));
>
> if (pos>p2 && pos<p4) b=3Dnew A(std::move(*it.b));
>
> }
>
> ~iterator() {
>
> if (pos>p2 && pos<p4) delete b;
>
> if (pos>p1 && pos<p4) delete fib3;
>
> if (pos>p0 && pos<p4) {
>
> delete even;
>
> delete fib2;
>
> delete fib1;
>
> delete a;
>
> delete ret_value;
>
> }
>
> }
>
> bool operator!=3D(const iterator &it) {
>
> return pos!=3Dit.pos;
>
> }
>
> operator bool() {
>
> return pos<p4; //still hasn't ended
>
> }
>
> iterator &operator=3D(const iterator&) =3D delete;
>
> friend fib_even;
>
> };
>
> int n;
>
> public:
>
> fib_even(int n) : n(n) {}
>
> iterator begin() {
>
> return iterator(n);
>
> }
>
> iterator end() {
>
> return iterator();
>
> }
>
> };
>
> So, what do you think?
>
--=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_87_21569202.1372323233185
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
While I really want to get my hands on native coroutines, I don't think you=
r approach works very well.<br><br>1) Who says we always want to use corout=
ines as `for(auto r : coro(args))`? I don't think that's necessarily the ma=
in form of use<br>2) How would the transformation to a class work for templ=
ate argument deduction?<br><br>I think a better course would be to transfor=
m the return type of such a function, as would be done with async/await-sty=
le functions.<br>The returned type would then simply have an `operator()` a=
nd if you wanted a range from that, it could be quite easily done with a ge=
neral function-adaptor.<br><br>On Thursday, June 27, 2013 3:40:58 AM UTC+2,=
asa...@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: =
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><p dir=
=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span =
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:tr=
ansparent;font-weight:normal;font-style:normal;font-variant:normal;text-dec=
oration:none;vertical-align:baseline">Recently, I=92ve thought a lot about =
coroutines, and how they should behave if became a part of c++.</span></p><=
p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><=
span style=3D"font-size:15px;font-family:Arial;color:#000000;background-col=
or:transparent;font-weight:normal;font-style:normal;font-variant:normal;tex=
t-decoration:none;vertical-align:baseline">I found two (main) proposals:</s=
pan></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bott=
om:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backg=
round-color:transparent;font-weight:normal;font-style:normal;font-variant:n=
ormal;text-decoration:none;vertical-align:baseline">a. </span><a href=3D"ht=
tps://groups.google.com/a/isocpp.org/forum/#%21topic/std-proposals/3g6ZIWed=
GJ8" style=3D"text-decoration:none" target=3D"_blank"><span style=3D"font-s=
ize:15px;font-family:Arial;color:#1155cc;background-color:transparent;font-=
weight:normal;font-style:normal;font-variant:normal;text-decoration:underli=
ne;vertical-align:baseline">https://groups.google.com/a/<wbr>isocpp.org/for=
um/#!topic/std-<wbr>proposals/3g6ZIWedGJ8</span></a><span style=3D"font-siz=
e:15px;font-family:Arial;color:#000000;background-color:transparent;font-we=
ight:normal;font-style:normal;font-variant:normal;text-decoration:none;vert=
ical-align:baseline"></span></p><p dir=3D"ltr" style=3D"line-height:1.15;ma=
rgin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:A=
rial;color:#000000;background-color:transparent;font-weight:normal;font-sty=
le:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"=
>It
has the advantage of not requiring to change the syntax, but in force a
new model of stack-based calls. It does so in purpose to let nested=20
functions to yield value, which I think is not really necessary. (If we=20
let nested functions return value on behalf of their callee, we should=20
start this in regular functions). Also, Its syntax is somehow complex.</spa=
n></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom=
:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgro=
und-color:transparent;font-weight:normal;font-style:normal;font-variant:nor=
mal;text-decoration:none;vertical-align:baseline">b. </span><a href=3D"http=
s://groups.google.com/a/isocpp.org/forum/#%21topic/std-proposals/PPZJVTDdDV=
Q" style=3D"text-decoration:none" target=3D"_blank"><span style=3D"font-siz=
e:15px;font-family:Arial;color:#1155cc;background-color:transparent;font-we=
ight:normal;font-style:normal;font-variant:normal;text-decoration:underline=
;vertical-align:baseline">https://groups.google.com/a/<wbr>isocpp.org/forum=
/#!topic/std-<wbr>proposals/PPZJVTDdDVQ</span></a><span style=3D"font-size:=
15px;font-family:Arial;color:#000000;background-color:transparent;font-weig=
ht:normal;font-style:normal;font-variant:normal;text-decoration:none;vertic=
al-align:baseline"></span></p><p dir=3D"ltr" style=3D"line-height:1.15;marg=
in-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Ari=
al;color:#000000;background-color:transparent;font-weight:normal;font-style=
:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">I=
t
is easy to use and doesn=92t require a new stack, and I think that this=20
is the right direction. However, it ignores some technical details=20
(lifetime of locals, etc). Also, adding a keyword may break too many=20
working code, and my personal opinion is that it is ugly. Sentences like
=93void numbers() yields int=94 reminds me too many things I hate in Java.=
=20
The alternative syntax (described at the end of this proposal) is not so
ugly, but still complex.</span></p><p dir=3D"ltr" style=3D"line-height:1.1=
5;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-fami=
ly:Arial;color:#000000;background-color:transparent;font-weight:normal;font=
-style:normal;font-variant:normal;text-decoration:none;vertical-align:basel=
ine">There is even a nice implementation of coroutines (using macros): </sp=
an><a href=3D"http://www.chiark.greenend.org.uk/%7Esgtatham/coroutines.html=
" style=3D"text-decoration:none" target=3D"_blank"><span style=3D"font-size=
:15px;font-family:Arial;color:#1155cc;background-color:transparent;font-wei=
ght:normal;font-style:normal;font-variant:normal;text-decoration:underline;=
vertical-align:baseline">http://www.chiark.greenend.<wbr>org.uk/~sgtatham/c=
oroutines.<wbr>html</span></a><span style=3D"font-size:15px;font-family:Ari=
al;color:#000000;background-color:transparent;font-weight:normal;font-style=
:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"><=
/span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bo=
ttom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;bac=
kground-color:transparent;font-weight:normal;font-style:normal;font-variant=
:normal;text-decoration:none;vertical-align:baseline">but
it has 2 major disadvantages: while using it, we can=92t yield a value=20
from within a switch statement, and, much more important, we have to=20
define all the local variables at the top of the function - back to C90=20
days! (and with constructors this is much worst.)</span></p><br><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline"></span><p dir=3D"ltr" style=3D"line-height=
:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-=
family:Arial;color:#000000;background-color:transparent;font-weight:normal;=
font-style:normal;font-variant:normal;text-decoration:none;vertical-align:b=
aseline">Another
thing that was very little talk about, is for-range loops native=20
support. Let=92s say we have a Fibonacci number generator (a very common=20
example):</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt=
;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#=
000000;background-color:transparent;font-weight:normal;font-style:normal;fo=
nt-variant:normal;text-decoration:none;vertical-align:baseline">(Using Deni=
s Bredelet=92s proposal syntax)</span></p><p dir=3D"ltr" style=3D"line-heig=
ht:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;fon=
t-family:Arial;color:#000000;background-color:transparent;font-weight:norma=
l;font-style:normal;font-variant:normal;text-decoration:none;vertical-align=
:baseline">void fib(int n) yields int {</span></p><p dir=3D"ltr" style=3D"l=
ine-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:=
15px;font-family:Arial;color:#000000;background-color:transparent;font-weig=
ht:normal;font-style:normal;font-variant:normal;text-decoration:none;vertic=
al-align:baseline"> int a=3D0,b=3D1;</span></p><p dir=3D"ltr" style=
=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-=
size:15px;font-family:Arial;color:#000000;background-color:transparent;font=
-weight:normal;font-style:normal;font-variant:normal;text-decoration:none;v=
ertical-align:baseline"> while(n--) {</span></p><p dir=3D"ltr" style=
=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-=
size:15px;font-family:Arial;color:#000000;background-color:transparent;font=
-weight:normal;font-style:normal;font-variant:normal;text-decoration:none;v=
ertical-align:baseline"> int c=3Da+b;</span></p><p dir=3D=
"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span sty=
le=3D"font-size:15px;font-family:Arial;color:#000000;background-color:trans=
parent;font-weight:normal;font-style:normal;font-variant:normal;text-decora=
tion:none;vertical-align:baseline"> a=3Db;</span></p><p d=
ir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><spa=
n style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:=
transparent;font-weight:normal;font-style:normal;font-variant:normal;text-d=
ecoration:none;vertical-align:baseline"> b=3Dc;</span></p=
><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"=
><span style=3D"font-size:15px;font-family:Arial;color:#000000;background-c=
olor:transparent;font-weight:normal;font-style:normal;font-variant:normal;t=
ext-decoration:none;vertical-align:baseline"> yield c;</s=
pan></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bott=
om:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backg=
round-color:transparent;font-weight:normal;font-style:normal;font-variant:n=
ormal;text-decoration:none;vertical-align:baseline"> }</span></p><p d=
ir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><spa=
n style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:=
transparent;font-weight:normal;font-style:normal;font-variant:normal;text-d=
ecoration:none;vertical-align:baseline">}</span></p><p dir=3D"ltr" style=3D=
"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-siz=
e:15px;font-family:Arial;color:#000000;background-color:transparent;font-we=
ight:normal;font-style:normal;font-variant:normal;text-decoration:none;vert=
ical-align:baseline">We want the possibility to write </span><span style=3D=
"font-size:15px;font-family:Arial;color:#000000;background-color:transparen=
t;font-weight:normal;font-style:italic;font-variant:normal;text-decoration:=
none;vertical-align:baseline">for (int i : fib(10)) std::cout<<i<&=
lt;=92\n=92;</span><span style=3D"font-size:15px;font-family:Arial;color:#0=
00000;background-color:transparent;font-weight:normal;font-style:normal;fon=
t-variant:normal;text-decoration:none;vertical-align:baseline"> to print th=
e first 10 Fibonacci numbers.</span></p><br><span style=3D"font-size:15px;f=
ont-family:Arial;color:#000000;background-color:transparent;font-weight:nor=
mal;font-style:normal;font-variant:normal;text-decoration:none;vertical-ali=
gn:baseline"></span><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt=
;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#=
000000;background-color:transparent;font-weight:normal;font-style:normal;fo=
nt-variant:normal;text-decoration:none;vertical-align:baseline">So what am =
I suggest?</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0p=
t;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:=
#000000;background-color:transparent;font-weight:normal;font-style:normal;f=
ont-variant:normal;text-decoration:none;vertical-align:baseline">First,
to the syntax. Since we want it to work natively with for-range loops,=20
and since the language concept is =93declare it the way you will use =
it=94,
I would suggest using colon in the function signature. The nicest idea I
managed to think so far is </span><span style=3D"font-size:15px;font-famil=
y:Arial;color:#000000;background-color:transparent;font-weight:normal;font-=
style:italic;font-variant:normal;text-decoration:none;vertical-align:baseli=
ne">int : fib(int n)</span></p><p dir=3D"ltr" style=3D"line-height:1.15;mar=
gin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Ar=
ial;color:#000000;background-color:transparent;font-weight:normal;font-styl=
e:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">=
Also, there is no reason to add the keyword </span><span style=3D"font-size=
:15px;font-family:Arial;color:#000000;background-color:transparent;font-wei=
ght:normal;font-style:italic;font-variant:normal;text-decoration:none;verti=
cal-align:baseline">yield</span><span style=3D"font-size:15px;font-family:A=
rial;color:#000000;background-color:transparent;font-weight:normal;font-sty=
le:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"=
>, when we can stick to good old </span><span style=3D"font-size:15px;font-=
family:Arial;color:#000000;background-color:transparent;font-weight:normal;=
font-style:italic;font-variant:normal;text-decoration:none;vertical-align:b=
aseline">return</span><span style=3D"font-size:15px;font-family:Arial;color=
:#000000;background-color:transparent;font-weight:normal;font-style:normal;=
font-variant:normal;text-decoration:none;vertical-align:baseline">.</span><=
/p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0p=
t"><span style=3D"font-size:15px;font-family:Arial;color:#000000;background=
-color:transparent;font-weight:normal;font-style:normal;font-variant:normal=
;text-decoration:none;vertical-align:baseline">Now, to the real stuff: What=
does </span><span style=3D"font-size:15px;font-family:Arial;color:#000000;=
background-color:transparent;font-weight:normal;font-style:italic;font-vari=
ant:normal;text-decoration:none;vertical-align:baseline">fib(10)</span><spa=
n style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:=
transparent;font-weight:normal;font-style:normal;font-variant:normal;text-d=
ecoration:none;vertical-align:baseline"> mean? What=92s the type of </span>=
<span style=3D"font-size:15px;font-family:Arial;color:#000000;background-co=
lor:transparent;font-weight:normal;font-style:italic;font-variant:normal;te=
xt-decoration:none;vertical-align:baseline">fib(10).begin()</span><span sty=
le=3D"font-size:15px;font-family:Arial;color:#000000;background-color:trans=
parent;font-weight:normal;font-style:normal;font-variant:normal;text-decora=
tion:none;vertical-align:baseline">?</span></p><p dir=3D"ltr" style=3D"line=
-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15p=
x;font-family:Arial;color:#000000;background-color:transparent;font-weight:=
normal;font-style:normal;font-variant:normal;text-decoration:none;vertical-=
align:baseline">I
suggest this meaning: fib will be (auto-generated) class, and an object
of it will represent calling the =93function=94 with specific parameters.=
=20
The member function </span><span style=3D"font-size:15px;font-family:Arial;=
color:#000000;background-color:transparent;font-weight:normal;font-style:it=
alic;font-variant:normal;text-decoration:none;vertical-align:baseline">begi=
n</span><span style=3D"font-size:15px;font-family:Arial;color:#000000;backg=
round-color:transparent;font-weight:normal;font-style:normal;font-variant:n=
ormal;text-decoration:none;vertical-align:baseline"> (and </span><span styl=
e=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transp=
arent;font-weight:normal;font-style:italic;font-variant:normal;text-decorat=
ion:none;vertical-align:baseline">end</span><span style=3D"font-size:15px;f=
ont-family:Arial;color:#000000;background-color:transparent;font-weight:nor=
mal;font-style:normal;font-variant:normal;text-decoration:none;vertical-ali=
gn:baseline">) will return some sort of iterator, which will represent the =
actual call.</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:=
0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;colo=
r:#000000;background-color:transparent;font-weight:normal;font-style:normal=
;font-variant:normal;text-decoration:none;vertical-align:baseline">Some det=
ails: the </span><span style=3D"font-size:15px;font-family:Arial;color:#000=
000;background-color:transparent;font-weight:normal;font-style:italic;font-=
variant:normal;text-decoration:none;vertical-align:baseline">fib</span><spa=
n style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:=
transparent;font-weight:normal;font-style:normal;font-variant:normal;text-d=
ecoration:none;vertical-align:baseline"> class should have some members, to=
contain the parameters it called with, but the real fun is in the </span><=
span style=3D"font-size:15px;font-family:Arial;color:#000000;background-col=
or:transparent;font-weight:normal;font-style:italic;font-variant:normal;tex=
t-decoration:none;vertical-align:baseline">iterator</span><span style=3D"fo=
nt-size:15px;font-family:Arial;color:#000000;background-color:transparent;f=
ont-weight:normal;font-style:normal;font-variant:normal;text-decoration:non=
e;vertical-align:baseline">
class: it will have (in addition to the parameters), as (not exactly=
, I
will explain below) members, all the local variables of the =93function=94=
=20
(including the return value), and also the information about where it=20
stopped last time (and should resume from) - let=92s call it, from now on,
=93position data=94.</span></p><p dir=3D"ltr" style=3D"line-height:1.15;ma=
rgin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:A=
rial;color:#000000;background-color:transparent;font-weight:normal;font-sty=
le:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"=
>To be more precise: an </span><span style=3D"font-size:15px;font-family:Ar=
ial;color:#000000;background-color:transparent;font-weight:normal;font-styl=
e:italic;font-variant:normal;text-decoration:none;vertical-align:baseline">=
iterator</span><span style=3D"font-size:15px;font-family:Arial;color:#00000=
0;background-color:transparent;font-weight:normal;font-style:normal;font-va=
riant:normal;text-decoration:none;vertical-align:baseline">
should contain the memory for the local variables (like every member=20
variable), but their lifetime will be as if they were local variables of
the =93function=94. I mean - they will been constructed only when the=20
=93function=94 will decide so, and not automatically when the </span><span =
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:tr=
ansparent;font-weight:normal;font-style:italic;font-variant:normal;text-dec=
oration:none;vertical-align:baseline">iterator</span><span style=3D"font-si=
ze:15px;font-family:Arial;color:#000000;background-color:transparent;font-w=
eight:normal;font-style:normal;font-variant:normal;text-decoration:none;ver=
tical-align:baseline"> is been constructed.</span></p><p dir=3D"ltr" style=
=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-=
size:15px;font-family:Arial;color:#000000;background-color:transparent;font=
-weight:normal;font-style:normal;font-variant:normal;text-decoration:none;v=
ertical-align:baseline">When the =93function=94 ends (either by falling thr=
ough the ending brace, not catching exception, or simply saying </span><spa=
n style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:=
transparent;font-weight:normal;font-style:italic;font-variant:normal;text-d=
ecoration:none;vertical-align:baseline">return;</span><span style=3D"font-s=
ize:15px;font-family:Arial;color:#000000;background-color:transparent;font-=
weight:normal;font-style:normal;font-variant:normal;text-decoration:none;ve=
rtical-align:baseline">
without a value), the position data should contain this information,=20
and (like every function), every local variable should be destructed.</span=
></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:=
0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgrou=
nd-color:transparent;font-weight:normal;font-style:normal;font-variant:norm=
al;text-decoration:none;vertical-align:baseline">Knowing
the position data let us easily determine which variables are alive,=20
and so I think that the following member functions can be automatically=20
created:</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;=
margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#0=
00000;background-color:transparent;font-weight:normal;font-style:normal;fon=
t-variant:normal;text-decoration:none;vertical-align:baseline">copy constru=
ctor - should copy the position data, the parameters, and every living loca=
l variable</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0p=
t;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:=
#000000;background-color:transparent;font-weight:normal;font-style:normal;f=
ont-variant:normal;text-decoration:none;vertical-align:baseline">move const=
ructor - the same, but move instead of copy</span></p><p dir=3D"ltr" style=
=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-=
size:15px;font-family:Arial;color:#000000;background-color:transparent;font=
-weight:normal;font-style:normal;font-variant:normal;text-decoration:none;v=
ertical-align:baseline">destructor - destroy the parameters, and every livi=
ng local variable.</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margi=
n-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Aria=
l;color:#000000;background-color:transparent;font-weight:normal;font-style:=
normal;font-variant:normal;text-decoration:none;vertical-align:baseline">(O=
f course, if some local variable is noncopyable, so is the iterator)</span>=
</p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0=
pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgroun=
d-color:transparent;font-weight:normal;font-style:normal;font-variant:norma=
l;text-decoration:none;vertical-align:baseline">I think that it should not =
be assignable - If one iterator have a live object, and another one have no=
t, it=92s a real mess.</span></p><br><span style=3D"font-size:15px;font-fam=
ily:Arial;color:#000000;background-color:transparent;font-weight:normal;fon=
t-style:normal;font-variant:normal;text-decoration:none;vertical-align:base=
line"></span><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin=
-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;=
background-color:transparent;font-weight:normal;font-style:normal;font-vari=
ant:normal;text-decoration:none;vertical-align:baseline">Some example:</spa=
n></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom=
:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgro=
und-color:transparent;font-weight:normal;font-style:normal;font-variant:nor=
mal;text-decoration:none;vertical-align:baseline">Suppose
that we want to yield the number 0, and then, the first n Fibonacci=20
numbers and the first n even number, alternately. To add more interest=20
(and to demonstrate more rules), I want to create and destroy some=20
objects (assume </span><span style=3D"font-size:15px;font-family:Arial;colo=
r:#000000;background-color:transparent;font-weight:normal;font-style:italic=
;font-variant:normal;text-decoration:none;vertical-align:baseline">A</span>=
<span style=3D"font-size:15px;font-family:Arial;color:#000000;background-co=
lor:transparent;font-weight:normal;font-style:normal;font-variant:normal;te=
xt-decoration:none;vertical-align:baseline"> is a copyable, moveable, and i=
nt-constructive class), so I=92ve written the following code:</span></p><p =
dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><sp=
an style=3D"font-size:15px;font-family:Arial;color:#000000;background-color=
:transparent;font-weight:normal;font-style:normal;font-variant:normal;text-=
decoration:none;vertical-align:baseline">int : fib_even(int n) {</span></p>=
<p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt">=
<span style=3D"font-size:15px;font-family:Arial;color:#000000;background-co=
lor:transparent;font-weight:normal;font-style:normal;font-variant:normal;te=
xt-decoration:none;vertical-align:baseline"> A a(7);</spa=
n></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom=
:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgro=
und-color:transparent;font-weight:normal;font-style:normal;font-variant:nor=
mal;text-decoration:none;vertical-align:baseline"> int fi=
b1=3D0,fib2=3D1,even=3D0;</span></p><p dir=3D"ltr" style=3D"line-height:1.1=
5;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-fami=
ly:Arial;color:#000000;background-color:transparent;font-weight:normal;font=
-style:normal;font-variant:normal;text-decoration:none;vertical-align:basel=
ine"> return 0;</span></p><p dir=3D"ltr" style=3D"line-he=
ight:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;f=
ont-family:Arial;color:#000000;background-color:transparent;font-weight:nor=
mal;font-style:normal;font-variant:normal;text-decoration:none;vertical-ali=
gn:baseline"> while(n--) {</span></p><p dir=3D"ltr" style=
=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-=
size:15px;font-family:Arial;color:#000000;background-color:transparent;font=
-weight:normal;font-style:normal;font-variant:normal;text-decoration:none;v=
ertical-align:baseline"> int fib3=3Dfi=
b1+fib2;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;=
margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#0=
00000;background-color:transparent;font-weight:normal;font-style:normal;fon=
t-variant:normal;text-decoration:none;vertical-align:baseline">  =
; fib1=3Dfib2;</span></p><p dir=3D"ltr" style=3D"li=
ne-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:1=
5px;font-family:Arial;color:#000000;background-color:transparent;font-weigh=
t:normal;font-style:normal;font-variant:normal;text-decoration:none;vertica=
l-align:baseline"> fib2=3Dfib3;</span>=
</p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0=
pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgroun=
d-color:transparent;font-weight:normal;font-style:normal;font-variant:norma=
l;text-decoration:none;vertical-align:baseline"> &n=
bsp; return fib3;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;=
margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family=
:Arial;color:#000000;background-color:transparent;font-weight:normal;font-s=
tyle:normal;font-variant:normal;text-decoration:none;vertical-align:baselin=
e"> A b=3Dn;</span></p><p dir=3D"ltr" =
style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"=
font-size:15px;font-family:Arial;color:#000000;background-color:transparent=
;font-weight:normal;font-style:normal;font-variant:normal;text-decoration:n=
one;vertical-align:baseline"> return e=
ven+=3D2;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt=
;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#=
000000;background-color:transparent;font-weight:normal;font-style:normal;fo=
nt-variant:normal;text-decoration:none;vertical-align:baseline"> &nbs=
p; }</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt=
;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#=
000000;background-color:transparent;font-weight:normal;font-style:normal;fo=
nt-variant:normal;text-decoration:none;vertical-align:baseline">}</span></p=
><br><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgrou=
nd-color:transparent;font-weight:normal;font-style:normal;font-variant:norm=
al;text-decoration:none;vertical-align:baseline"></span><p dir=3D"ltr" styl=
e=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font=
-size:15px;font-family:Arial;color:#000000;background-color:transparent;fon=
t-weight:normal;font-style:normal;font-variant:normal;text-decoration:none;=
vertical-align:baseline">A compiler may expand it to something like:</span>=
</p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0=
pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgroun=
d-color:transparent;font-weight:normal;font-style:normal;font-variant:norma=
l;text-decoration:none;vertical-align:baseline">(Note:
I=92m using dynamic memory allocation, but It=92s not really how it should=
=20
be implemented - I just don=92t want some constructors and destructors to=
=20
been invoked automatically)</span></p><br><span style=3D"font-size:15px;fon=
t-family:Arial;color:#000000;background-color:transparent;font-weight:norma=
l;font-style:normal;font-variant:normal;text-decoration:none;vertical-align=
:baseline"></span><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;m=
argin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#00=
0000;background-color:transparent;font-weight:normal;font-style:normal;font=
-variant:normal;text-decoration:none;vertical-align:baseline">class fib_eve=
n {</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margi=
n-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000=
;background-color:transparent;font-weight:normal;font-style:normal;font-var=
iant:normal;text-decoration:none;vertical-align:baseline"> &nbs=
p;class iterator {</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margi=
n-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Aria=
l;color:#000000;background-color:transparent;font-weight:normal;font-style:=
normal;font-variant:normal;text-decoration:none;vertical-align:baseline"> &=
nbsp; int n;</span></p><p dir=3D"ltr" style=
=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-=
size:15px;font-family:Arial;color:#000000;background-color:transparent;font=
-weight:normal;font-style:normal;font-variant:normal;text-decoration:none;v=
ertical-align:baseline"> int *fib1,*fi=
b2,*fib3,*even;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-t=
op:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;c=
olor:#000000;background-color:transparent;font-weight:normal;font-style:nor=
mal;font-variant:normal;text-decoration:none;vertical-align:baseline"> &nbs=
p; A *a,*b;</span></p><p dir=3D"ltr" style=3D=
"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-siz=
e:15px;font-family:Arial;color:#000000;background-color:transparent;font-we=
ight:normal;font-style:normal;font-variant:normal;text-decoration:none;vert=
ical-align:baseline"> int *ret_value;<=
/span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bo=
ttom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;bac=
kground-color:transparent;font-weight:normal;font-style:normal;font-variant=
:normal;text-decoration:none;vertical-align:baseline"> &n=
bsp; enum {p0,p1,p2,p3,p4} pos; //resuming points<br></span></p=
><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"=
><span style=3D"font-size:15px;font-family:Arial;color:#000000;background-c=
olor:transparent;font-weight:normal;font-style:normal;font-variant:normal;t=
ext-decoration:none;vertical-align:baseline">  =
; void next() {</span></p><p dir=3D"ltr" style=3D"line-height:1.15;ma=
rgin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:A=
rial;color:#000000;background-color:transparent;font-weight:normal;font-sty=
le:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"=
> switch (pos) {</s=
pan></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bott=
om:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backg=
round-color:transparent;font-weight:normal;font-style:normal;font-variant:n=
ormal;text-decoration:none;vertical-align:baseline"> &nbs=
p; case p0: break;</span>=
</p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0=
pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgroun=
d-color:transparent;font-weight:normal;font-style:normal;font-variant:norma=
l;text-decoration:none;vertical-align:baseline"> &n=
bsp; case p1: goto label1;</spa=
n></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom=
:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgro=
und-color:transparent;font-weight:normal;font-style:normal;font-variant:nor=
mal;text-decoration:none;vertical-align:baseline"> =
case p2: goto label2;</s=
pan></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bott=
om:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backg=
round-color:transparent;font-weight:normal;font-style:normal;font-variant:n=
ormal;text-decoration:none;vertical-align:baseline"> &nbs=
p; case p3: goto label3;<=
/span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bo=
ttom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;bac=
kground-color:transparent;font-weight:normal;font-style:normal;font-variant=
:normal;text-decoration:none;vertical-align:baseline"> &n=
bsp; case p4: return;</sp=
an></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-botto=
m:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgr=
ound-color:transparent;font-weight:normal;font-style:normal;font-variant:no=
rmal;text-decoration:none;vertical-align:baseline">  =
; }</span></p><p dir=3D"ltr" style=3D"line-h=
eight:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;=
font-family:Arial;color:#000000;background-color:transparent;font-weight:no=
rmal;font-style:normal;font-variant:normal;text-decoration:none;vertical-al=
ign:baseline">//construct automatic variables of t</span><span style=3D"fon=
t-size:15px;font-family:Arial;color:#000000;background-color:transparent;fo=
nt-weight:normal;font-style:normal;font-variant:normal;text-decoration:none=
;vertical-align:baseline">he function<br></span></p><p dir=3D"ltr" style=3D=
"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-siz=
e:15px;font-family:Arial;color:#000000;background-color:transparent;font-we=
ight:normal;font-style:normal;font-variant:normal;text-decoration:none;vert=
ical-align:baseline"> &nb=
sp;a=3Dnew A(7);</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-=
top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;=
color:#000000;background-color:transparent;font-weight:normal;font-style:no=
rmal;font-variant:normal;text-decoration:none;vertical-align:baseline"> &nb=
sp; fib1=3Dnew int(0);</sp=
an></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-botto=
m:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgr=
ound-color:transparent;font-weight:normal;font-style:normal;font-variant:no=
rmal;text-decoration:none;vertical-align:baseline">  =
; fib2=3Dnew int(1);</span></p><p dir=3D"ltr=
" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline"> &nbs=
p; even=3Dnew int(0);</span></p><p dir=3D"ltr" style=3D"line-he=
ight:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;f=
ont-family:Arial;color:#000000;background-color:transparent;font-weight:nor=
mal;font-style:normal;font-variant:normal;text-decoration:none;vertical-ali=
gn:baseline">//t</span><span style=3D"font-size:15px;font-family:Arial;colo=
r:#000000;background-color:transparent;font-weight:normal;font-style:normal=
;font-variant:normal;text-decoration:none;vertical-align:baseline">he retur=
n process - create t</span><span style=3D"font-size:15px;font-family:Arial;=
color:#000000;background-color:transparent;font-weight:normal;font-style:no=
rmal;font-variant:normal;text-decoration:none;vertical-align:baseline">he v=
alue, save t</span><span style=3D"font-size:15px;font-family:Arial;color:#0=
00000;background-color:transparent;font-weight:normal;font-style:normal;fon=
t-variant:normal;text-decoration:none;vertical-align:baseline">he resuming =
point, and return<br></span></p><p dir=3D"ltr" style=3D"line-height:1.15;ma=
rgin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:A=
rial;color:#000000;background-color:transparent;font-weight:normal;font-sty=
le:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"=
> ret_value=3Dnew i=
nt(0);</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;ma=
rgin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000=
000;background-color:transparent;font-weight:normal;font-style:normal;font-=
variant:normal;text-decoration:none;vertical-align:baseline"> &=
nbsp; pos=3Dp1;</span></p><p dir=3D"lt=
r" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline"> &nbs=
p; return;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;m=
argin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:=
Arial;color:#000000;background-color:transparent;font-weight:normal;font-st=
yle:normal;font-variant:normal;text-decoration:none;vertical-align:baseline=
"> label1:<br></span></p><p dir=3D"ltr=
" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline"> &nbs=
p; while(n--) {</span></p><p dir=3D"ltr" style=3D"line-height:1=
..15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-fa=
mily:Arial;color:#000000;background-color:transparent;font-weight:normal;fo=
nt-style:normal;font-variant:normal;text-decoration:none;vertical-align:bas=
eline">  =
; fib3=3Dnew int(*fib1+*fib2); //being constructed only now<br></span=
></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:=
0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgrou=
nd-color:transparent;font-weight:normal;font-style:normal;font-variant:norm=
al;text-decoration:none;vertical-align:baseline"> &=
nbsp; *fib1=3D*fib2;</span></p>=
<p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt">=
<span style=3D"font-size:15px;font-family:Arial;color:#000000;background-co=
lor:transparent;font-weight:normal;font-style:normal;font-variant:normal;te=
xt-decoration:none;vertical-align:baseline"> =
*fib2=3D*fib3;</span></p><p di=
r=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span=
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:t=
ransparent;font-weight:normal;font-style:normal;font-variant:normal;text-de=
coration:none;vertical-align:baseline"> &nbs=
p; ret_value=3Dnew int(*fib3);</span><=
/p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0p=
t"><span style=3D"font-size:15px;font-family:Arial;color:#000000;background=
-color:transparent;font-weight:normal;font-style:normal;font-variant:normal=
;text-decoration:none;vertical-align:baseline"> &nb=
sp; pos=3Dp2;</span></p><p dir=
=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span =
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:tr=
ansparent;font-weight:normal;font-style:normal;font-variant:normal;text-dec=
oration:none;vertical-align:baseline">  =
; return;</span></p><p dir=3D"ltr" sty=
le=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"fon=
t-size:15px;font-family:Arial;color:#000000;background-color:transparent;fo=
nt-weight:normal;font-style:normal;font-variant:normal;text-decoration:none=
;vertical-align:baseline"> label2:</sp=
an></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-botto=
m:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgr=
ound-color:transparent;font-weight:normal;font-style:normal;font-variant:no=
rmal;text-decoration:none;vertical-align:baseline">  =
; b=3Dnew A(n);</span></p=
><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"=
><span style=3D"font-size:15px;font-family:Arial;color:#000000;background-c=
olor:transparent;font-weight:normal;font-style:normal;font-variant:normal;t=
ext-decoration:none;vertical-align:baseline">  =
; ret_value=3Dnew int((*even)+=
=3D2);</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;ma=
rgin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000=
000;background-color:transparent;font-weight:normal;font-style:normal;font-=
variant:normal;text-decoration:none;vertical-align:baseline"> &=
nbsp; pos=3Dp3;</sp=
an></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-botto=
m:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgr=
ound-color:transparent;font-weight:normal;font-style:normal;font-variant:no=
rmal;text-decoration:none;vertical-align:baseline">  =
; return;</span></p><p di=
r=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span=
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:t=
ransparent;font-weight:normal;font-style:normal;font-variant:normal;text-de=
coration:none;vertical-align:baseline"> &nbs=
p;label3:</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt=
;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#=
000000;background-color:transparent;font-weight:normal;font-style:normal;fo=
nt-variant:normal;text-decoration:none;vertical-align:baseline">//automatic=
variables going out of scope, and s</span><span style=3D"font-size:15px;fo=
nt-family:Arial;color:#000000;background-color:transparent;font-weight:norm=
al;font-style:normal;font-variant:normal;text-decoration:none;vertical-alig=
n:baseline"><span style=3D"font-size:15px;font-family:Arial;color:#000000;b=
ackground-color:transparent;font-weight:normal;font-style:normal;font-varia=
nt:normal;text-decoration:none;vertical-align:baseline">h</span>ould be des=
tructed<br></span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0=
pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color=
:#000000;background-color:transparent;font-weight:normal;font-style:normal;=
font-variant:normal;text-decoration:none;vertical-align:baseline"> &n=
bsp; delete b=
;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-=
bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;b=
ackground-color:transparent;font-weight:normal;font-style:normal;font-varia=
nt:normal;text-decoration:none;vertical-align:baseline"> =
delete fib3;</span=
></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:=
0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgrou=
nd-color:transparent;font-weight:normal;font-style:normal;font-variant:norm=
al;text-decoration:none;vertical-align:baseline"> &=
nbsp; }</span></p><p dir=3D"ltr" style=3D"line-hei=
ght:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;fo=
nt-family:Arial;color:#000000;background-color:transparent;font-weight:norm=
al;font-style:normal;font-variant:normal;text-decoration:none;vertical-alig=
n:baseline"> delete=
even;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;ma=
rgin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000=
000;background-color:transparent;font-weight:normal;font-style:normal;font-=
variant:normal;text-decoration:none;vertical-align:baseline"> &=
nbsp; delete fib2;</span></p><p dir=3D=
"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span sty=
le=3D"font-size:15px;font-family:Arial;color:#000000;background-color:trans=
parent;font-weight:normal;font-style:normal;font-variant:normal;text-decora=
tion:none;vertical-align:baseline"> &n=
bsp; delete fib1;</span></p><p dir=3D"ltr" style=3D"line-height=
:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-=
family:Arial;color:#000000;background-color:transparent;font-weight:normal;=
font-style:normal;font-variant:normal;text-decoration:none;vertical-align:b=
aseline"> delete a;=
</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-b=
ottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;ba=
ckground-color:transparent;font-weight:normal;font-style:normal;font-varian=
t:normal;text-decoration:none;vertical-align:baseline"> &=
nbsp; pos=3Dp4;</span></p><p dir=3D"ltr" sty=
le=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"fon=
t-size:15px;font-family:Arial;color:#000000;background-color:transparent;fo=
nt-weight:normal;font-style:normal;font-variant:normal;text-decoration:none=
;vertical-align:baseline"> }</span></p=
><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"=
><span style=3D"font-size:15px;font-family:Arial;color:#000000;background-c=
olor:transparent;font-weight:normal;font-style:normal;font-variant:normal;t=
ext-decoration:none;vertical-align:baseline">  =
; iterator(int n) : n(n),pos(p0) {</span></p><p dir=3D"ltr" style=3D"=
line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size=
:15px;font-family:Arial;color:#000000;background-color:transparent;font-wei=
ght:normal;font-style:normal;font-variant:normal;text-decoration:none;verti=
cal-align:baseline"> &nbs=
p;next(); //get t</span><span style=3D"font-size:15px;font-family:Arial;col=
or:#000000;background-color:transparent;font-weight:normal;font-style:norma=
l;font-variant:normal;text-decoration:none;vertical-align:baseline">he firs=
t value<br></span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0=
pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color=
:#000000;background-color:transparent;font-weight:normal;font-style:normal;=
font-variant:normal;text-decoration:none;vertical-align:baseline"> &n=
bsp; }</span></p><p dir=3D"ltr" style=3D"line-heigh=
t:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font=
-family:Arial;color:#000000;background-color:transparent;font-weight:normal=
;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:=
baseline"> iterator() : pos(p4) {}</sp=
an></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-botto=
m:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgr=
ound-color:transparent;font-weight:normal;font-style:normal;font-variant:no=
rmal;text-decoration:none;vertical-align:baseline"> publi=
c:</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin=
-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;=
background-color:transparent;font-weight:normal;font-style:normal;font-vari=
ant:normal;text-decoration:none;vertical-align:baseline">  =
; iterator &operator++() {</span></p><p dir=3D"ltr" s=
tyle=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"f=
ont-size:15px;font-family:Arial;color:#000000;background-color:transparent;=
font-weight:normal;font-style:normal;font-variant:normal;text-decoration:no=
ne;vertical-align:baseline"> &nb=
sp; delete ret_value;</span></p><p dir=3D"ltr" style=3D"line-height:1=
..15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-fa=
mily:Arial;color:#000000;background-color:transparent;font-weight:normal;fo=
nt-style:normal;font-variant:normal;text-decoration:none;vertical-align:bas=
eline"> next();</sp=
an></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-botto=
m:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgr=
ound-color:transparent;font-weight:normal;font-style:normal;font-variant:no=
rmal;text-decoration:none;vertical-align:baseline">  =
; return *this;</span></p><p dir=3D"ltr" sty=
le=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"fon=
t-size:15px;font-family:Arial;color:#000000;background-color:transparent;fo=
nt-weight:normal;font-style:normal;font-variant:normal;text-decoration:none=
;vertical-align:baseline"> }</span></p=
><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"=
><span style=3D"font-size:15px;font-family:Arial;color:#000000;background-c=
olor:transparent;font-weight:normal;font-style:normal;font-variant:normal;t=
ext-decoration:none;vertical-align:baseline">  =
; int &operator*() {</span></p><p dir=3D"ltr" style=3D"line-heigh=
t:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font=
-family:Arial;color:#000000;background-color:transparent;font-weight:normal=
;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:=
baseline"> return *=
ret_value;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0p=
t;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:=
#000000;background-color:transparent;font-weight:normal;font-style:normal;f=
ont-variant:normal;text-decoration:none;vertical-align:baseline"> &nb=
sp; }</span></p><p dir=3D"ltr" style=3D"line-height=
:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-=
family:Arial;color:#000000;background-color:transparent;font-weight:normal;=
font-style:normal;font-variant:normal;text-decoration:none;vertical-align:b=
aseline"> iterator(const iterator &=
;it) : n(it.n),pos(it.pos) {</span></p><p dir=3D"ltr" style=3D"line-height:=
1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-f=
amily:Arial;color:#000000;background-color:transparent;font-weight:normal;f=
ont-style:normal;font-variant:normal;text-decoration:none;vertical-align:ba=
seline">//copy only living members<br></span></p><p dir=3D"ltr" style=3D"li=
ne-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:1=
5px;font-family:Arial;color:#000000;background-color:transparent;font-weigh=
t:normal;font-style:normal;font-variant:normal;text-decoration:none;vertica=
l-align:baseline"> =
if (pos>p0 && pos<p4) {</span></p><p dir=3D"ltr" style=3D"lin=
e-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15=
px;font-family:Arial;color:#000000;background-color:transparent;font-weight=
:normal;font-style:normal;font-variant:normal;text-decoration:none;vertical=
-align:baseline"> &=
nbsp; ret_value=3Dnew int(*it.ret_value);</span></p><p dir=3D"l=
tr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline"> &nbs=
p; a=3Dnew A(*it.a);</span></p><p dir=3D"ltr=
" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline"> &nbs=
p; fib1=3Dnew int(*it.fib1);</span></p><p di=
r=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span=
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:t=
ransparent;font-weight:normal;font-style:normal;font-variant:normal;text-de=
coration:none;vertical-align:baseline"> &nbs=
p; fib2=3Dnew int(*it.fib2);</span></p=
><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"=
><span style=3D"font-size:15px;font-family:Arial;color:#000000;background-c=
olor:transparent;font-weight:normal;font-style:normal;font-variant:normal;t=
ext-decoration:none;vertical-align:baseline">  =
; even=3Dnew int(*it.even);</sp=
an></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-botto=
m:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgr=
ound-color:transparent;font-weight:normal;font-style:normal;font-variant:no=
rmal;text-decoration:none;vertical-align:baseline">  =
; }</span></p><p dir=3D"ltr" style=3D"line-h=
eight:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;=
font-family:Arial;color:#000000;background-color:transparent;font-weight:no=
rmal;font-style:normal;font-variant:normal;text-decoration:none;vertical-al=
ign:baseline"> if (=
pos>p1 && pos<p4) fib3=3Dnew int(*it.fib3);</span></p><p dir=
=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span =
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:tr=
ansparent;font-weight:normal;font-style:normal;font-variant:normal;text-dec=
oration:none;vertical-align:baseline">  =
; if (pos>p2 && pos<p4) b=3Dnew A(*it.b);</=
span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bot=
tom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;back=
ground-color:transparent;font-weight:normal;font-style:normal;font-variant:=
normal;text-decoration:none;vertical-align:baseline"> &nb=
sp; }</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin=
-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial=
;color:#000000;background-color:transparent;font-weight:normal;font-style:n=
ormal;font-variant:normal;text-decoration:none;vertical-align:baseline"> &n=
bsp; iterator(iterator &&it) : n(std:=
:move(it.n)),pos(it.pos) {</span></p><p dir=3D"ltr" style=3D"line-height:1.=
15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-fam=
ily:Arial;color:#000000;background-color:transparent;font-weight:normal;fon=
t-style:normal;font-variant:normal;text-decoration:none;vertical-align:base=
line"> if (pos>p=
0 && pos<p4) {</span></p><p dir=3D"ltr" style=3D"line-height:1.1=
5;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-fami=
ly:Arial;color:#000000;background-color:transparent;font-weight:normal;font=
-style:normal;font-variant:normal;text-decoration:none;vertical-align:basel=
ine"> =
ret_value=3Dnew int(std::move(*it.ret_value));</span></p><p dir=3D"lt=
r" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline"> &nbs=
p; a=3Dnew A(std::move(*it.a));</span></p><p=
dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><s=
pan style=3D"font-size:15px;font-family:Arial;color:#000000;background-colo=
r:transparent;font-weight:normal;font-style:normal;font-variant:normal;text=
-decoration:none;vertical-align:baseline"> &=
nbsp; fib1=3Dnew int(std::move(*it.fib=
1));</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;marg=
in-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#00000=
0;background-color:transparent;font-weight:normal;font-style:normal;font-va=
riant:normal;text-decoration:none;vertical-align:baseline"> &nb=
sp; fib2=3Dnew int(=
std::move(*it.fib2));</span></p><p dir=3D"ltr" style=3D"line-height:1.15;ma=
rgin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:A=
rial;color:#000000;background-color:transparent;font-weight:normal;font-sty=
le:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"=
> &nbs=
p;even=3Dnew int(std::move(*it.even));</span></p><p dir=3D"ltr" style=3D"li=
ne-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:1=
5px;font-family:Arial;color:#000000;background-color:transparent;font-weigh=
t:normal;font-style:normal;font-variant:normal;text-decoration:none;vertica=
l-align:baseline"> =
}</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-=
bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;b=
ackground-color:transparent;font-weight:normal;font-style:normal;font-varia=
nt:normal;text-decoration:none;vertical-align:baseline"> =
if (pos>p1 && pos<p4) f=
ib3=3Dnew int(std::move(*it.fib3));</span></p><p dir=3D"ltr" style=3D"line-=
height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px=
;font-family:Arial;color:#000000;background-color:transparent;font-weight:n=
ormal;font-style:normal;font-variant:normal;text-decoration:none;vertical-a=
lign:baseline"> if =
(pos>p2 && pos<p4) b=3Dnew A(std::move(*it.b));</span></p><p =
dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><sp=
an style=3D"font-size:15px;font-family:Arial;color:#000000;background-color=
:transparent;font-weight:normal;font-style:normal;font-variant:normal;text-=
decoration:none;vertical-align:baseline"> &n=
bsp;}</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;mar=
gin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#0000=
00;background-color:transparent;font-weight:normal;font-style:normal;font-v=
ariant:normal;text-decoration:none;vertical-align:baseline"> &n=
bsp; ~iterator() {</span></p><p dir=3D"ltr" style=3D"line=
-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15p=
x;font-family:Arial;color:#000000;background-color:transparent;font-weight:=
normal;font-style:normal;font-variant:normal;text-decoration:none;vertical-=
align:baseline"> if=
(pos>p2 && pos<p4) delete b;</span></p><p dir=3D"ltr" style=
=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-=
size:15px;font-family:Arial;color:#000000;background-color:transparent;font=
-weight:normal;font-style:normal;font-variant:normal;text-decoration:none;v=
ertical-align:baseline"> =
if (pos>p1 && pos<p4) delete fib3;</span></p><p dir=3D"=
ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span styl=
e=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transp=
arent;font-weight:normal;font-style:normal;font-variant:normal;text-decorat=
ion:none;vertical-align:baseline"> &nb=
sp; if (pos>p0 && pos<p4) {</span></p><p dir=3D"l=
tr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline"> &nbs=
p; delete even;</span></p><p dir=3D"ltr" sty=
le=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"fon=
t-size:15px;font-family:Arial;color:#000000;background-color:transparent;fo=
nt-weight:normal;font-style:normal;font-variant:normal;text-decoration:none=
;vertical-align:baseline">  =
; delete fib2;</span></p><p dir=3D"ltr" style=3D"l=
ine-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:=
15px;font-family:Arial;color:#000000;background-color:transparent;font-weig=
ht:normal;font-style:normal;font-variant:normal;text-decoration:none;vertic=
al-align:baseline">  =
; delete fib1;</span></p><p dir=3D"ltr" style=3D"line-hei=
ght:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;fo=
nt-family:Arial;color:#000000;background-color:transparent;font-weight:norm=
al;font-style:normal;font-variant:normal;text-decoration:none;vertical-alig=
n:baseline"> =
delete a;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;m=
argin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:=
Arial;color:#000000;background-color:transparent;font-weight:normal;font-st=
yle:normal;font-variant:normal;text-decoration:none;vertical-align:baseline=
"> &nb=
sp;delete ret_value;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;mar=
gin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Ar=
ial;color:#000000;background-color:transparent;font-weight:normal;font-styl=
e:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">=
}</span></p><p dir=
=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span =
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:tr=
ansparent;font-weight:normal;font-style:normal;font-variant:normal;text-dec=
oration:none;vertical-align:baseline">  =
;}</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin=
-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;=
background-color:transparent;font-weight:normal;font-style:normal;font-vari=
ant:normal;text-decoration:none;vertical-align:baseline">  =
; bool operator!=3D(const iterator &it) {</span></p><=
p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><=
span style=3D"font-size:15px;font-family:Arial;color:#000000;background-col=
or:transparent;font-weight:normal;font-style:normal;font-variant:normal;tex=
t-decoration:none;vertical-align:baseline"> =
return pos!=3Dit.pos;</span></p><p dir=3D"ltr" sty=
le=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"fon=
t-size:15px;font-family:Arial;color:#000000;background-color:transparent;fo=
nt-weight:normal;font-style:normal;font-variant:normal;text-decoration:none=
;vertical-align:baseline"> }</span></p=
><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"=
><span style=3D"font-size:15px;font-family:Arial;color:#000000;background-c=
olor:transparent;font-weight:normal;font-style:normal;font-variant:normal;t=
ext-decoration:none;vertical-align:baseline">  =
; operator bool() {</span></p><p dir=3D"ltr" style=3D"line-height:1.1=
5;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-fami=
ly:Arial;color:#000000;background-color:transparent;font-weight:normal;font=
-style:normal;font-variant:normal;text-decoration:none;vertical-align:basel=
ine"> return pos<=
;p4; //still </span><span style=3D"font-size:15px;font-family:Arial;color:#=
000000;background-color:transparent;font-weight:normal;font-style:normal;fo=
nt-variant:normal;text-decoration:none;vertical-align:baseline">hasn't ende=
d<br></span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;mar=
gin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#0000=
00;background-color:transparent;font-weight:normal;font-style:normal;font-v=
ariant:normal;text-decoration:none;vertical-align:baseline"> &n=
bsp; }</span></p><p dir=3D"ltr" style=3D"line-height:1.15=
;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-famil=
y:Arial;color:#000000;background-color:transparent;font-weight:normal;font-=
style:normal;font-variant:normal;text-decoration:none;vertical-align:baseli=
ne"> iterator &operator=3D(const i=
terator&) =3D delete;</span></p><p dir=3D"ltr" style=3D"line-height:1.1=
5;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-fami=
ly:Arial;color:#000000;background-color:transparent;font-weight:normal;font=
-style:normal;font-variant:normal;text-decoration:none;vertical-align:basel=
ine"> friend fib_even;</span></p><p di=
r=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span=
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:t=
ransparent;font-weight:normal;font-style:normal;font-variant:normal;text-de=
coration:none;vertical-align:baseline"> };</span></p><p d=
ir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><spa=
n style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:=
transparent;font-weight:normal;font-style:normal;font-variant:normal;text-d=
ecoration:none;vertical-align:baseline"> int n;</span></p=
><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"=
><span style=3D"font-size:15px;font-family:Arial;color:#000000;background-c=
olor:transparent;font-weight:normal;font-style:normal;font-variant:normal;t=
ext-decoration:none;vertical-align:baseline">public:</span></p><p dir=3D"lt=
r" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline"> fib_even(int n) : n(n) =
{}</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin=
-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;=
background-color:transparent;font-weight:normal;font-style:normal;font-vari=
ant:normal;text-decoration:none;vertical-align:baseline">  =
;iterator begin() {</span></p><p dir=3D"ltr" style=3D"line-height:1.15;marg=
in-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Ari=
al;color:#000000;background-color:transparent;font-weight:normal;font-style=
:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"> =
return iterator(n);</span></p><p dir=
=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span =
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:tr=
ansparent;font-weight:normal;font-style:normal;font-variant:normal;text-dec=
oration:none;vertical-align:baseline"> }</span></p><p dir=
=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span =
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:tr=
ansparent;font-weight:normal;font-style:normal;font-variant:normal;text-dec=
oration:none;vertical-align:baseline"> iterator end() {</=
span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bot=
tom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;back=
ground-color:transparent;font-weight:normal;font-style:normal;font-variant:=
normal;text-decoration:none;vertical-align:baseline"> &nb=
sp; return iterator();</span></p><p dir=3D"ltr" style=3D"line-h=
eight:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;=
font-family:Arial;color:#000000;background-color:transparent;font-weight:no=
rmal;font-style:normal;font-variant:normal;text-decoration:none;vertical-al=
ign:baseline"> }</span></p><p dir=3D"ltr" style=3D"line-h=
eight:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;=
font-family:Arial;color:#000000;background-color:transparent;font-weight:no=
rmal;font-style:normal;font-variant:normal;text-decoration:none;vertical-al=
ign:baseline">};</span></p><br><span style=3D"font-size:15px;font-family:Ar=
ial;color:#000000;background-color:transparent;font-weight:normal;font-styl=
e:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">=
</span><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-botto=
m:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgr=
ound-color:transparent;font-weight:normal;font-style:normal;font-variant:no=
rmal;text-decoration:none;vertical-align:baseline">So, what do you think?</=
span></p></blockquote>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
<br />
<br />
------=_Part_87_21569202.1372323233185--
.
Author: asaelr@gmail.com
Date: Thu, 27 Jun 2013 07:34:39 -0700 (PDT)
Raw View
------=_Part_482_15419926.1372343679497
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
1) *begin* and *end* are the common way to iterate over something. I'm=20
agree that sometimes we just want to have *auto coro(args);coro();
2) You're rig*ht. I had forgotten that class template arguments are not=20
being deducted - even when we just are calling the constructor
If I understood you correctly, you mean to transfrom *int : fib(int n)=20
{/*blablabla/*}* to *fib_class fib(int n) {return fib_class(n);}* , when *
fib_class* is some unnamed data structure. This seems to solve the=20
deduction problem. If we allow *fib_class::operator()*, it means that the=
=20
actual calling is represented by *fib_class*, and not by *fib_class:iterato=
r
*. That's a good idea, but it should deal with:
auto coro=3Dfib(10);
auto iter=3Dfib.begin();
int a=3D*iter; //should be 1
int b=3Dcoro(); //should be 2
++iter; //what does this mean? what is the value of *iter now?
I think that since a coroutine have only one currently return value, an=20
existing iterator should be invalidated when the corouting is being=20
incremented by other way (using another iterator, or *operator()* ).
In this concept, I suggest that an iterator object will contain only=20
reference to the coroutine object, and the position data.
(This also saves the parameters copy in *begin*)
Thanks for the feedback. Clearly I may think more about the concept. (My=20
main goals were to discuss some technical details which weren't clear in=20
https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/PPZJVTDd=
DVQ=20
, and to suggest a new (and - according to my taste - nice) syntax.
=D7=91=D7=AA=D7=90=D7=A8=D7=99=D7=9A =D7=99=D7=95=D7=9D =D7=97=D7=9E=D7=99=
=D7=A9=D7=99, 27 =D7=91=D7=99=D7=95=D7=A0=D7=99 2013 11:53:53 UTC+3, =D7=9E=
=D7=90=D7=AA Xeo:
>
> While I really want to get my hands on native coroutines, I don't think=
=20
> your approach works very well.
>
> 1) Who says we always want to use coroutines as `for(auto r :=20
> coro(args))`? I don't think that's necessarily the main form of use
> 2) How would the transformation to a class work for template argument=20
> deduction?
>
> I think a better course would be to transform the return type of such a=
=20
> function, as would be done with async/await-style functions.
> The returned type would then simply have an `operator()` and if you wante=
d=20
> a range from that, it could be quite easily done with a general=20
> function-adaptor.
>
> On Thursday, June 27, 2013 3:40:58 AM UTC+2, asa...@gmail.com wrote:
>>
>> Recently, I=E2=80=99ve thought a lot about coroutines, and how they shou=
ld behave=20
>> if became a part of c++.
>>
>> I found two (main) proposals:
>>
>> a.=20
>> https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/3g6ZI=
WedGJ8
>>
>> It has the advantage of not requiring to change the syntax, but in force=
=20
>> a new model of stack-based calls. It does so in purpose to let nested=20
>> functions to yield value, which I think is not really necessary. (If we =
let=20
>> nested functions return value on behalf of their callee, we should start=
=20
>> this in regular functions). Also, Its syntax is somehow complex.
>>
>> b.=20
>> https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/PPZJV=
TDdDVQ
>>
>> It is easy to use and doesn=E2=80=99t require a new stack, and I think t=
hat this=20
>> is the right direction. However, it ignores some technical details=20
>> (lifetime of locals, etc). Also, adding a keyword may break too many=20
>> working code, and my personal opinion is that it is ugly. Sentences like=
=20
>> =E2=80=9Cvoid numbers() yields int=E2=80=9D reminds me too many things I=
hate in Java. The=20
>> alternative syntax (described at the end of this proposal) is not so ugl=
y,=20
>> but still complex.
>>
>> There is even a nice implementation of coroutines (using macros):=20
>> http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
>>
>> but it has 2 major disadvantages: while using it, we can=E2=80=99t yield=
a value=20
>> from within a switch statement, and, much more important, we have to def=
ine=20
>> all the local variables at the top of the function - back to C90 days! (=
and=20
>> with constructors this is much worst.)
>>
>> Another thing that was very little talk about, is for-range loops native=
=20
>> support. Let=E2=80=99s say we have a Fibonacci number generator (a very =
common=20
>> example):
>>
>> (Using Denis Bredelet=E2=80=99s proposal syntax)
>>
>> void fib(int n) yields int {
>>
>> int a=3D0,b=3D1;
>>
>> while(n--) {
>>
>> int c=3Da+b;
>>
>> a=3Db;
>>
>> b=3Dc;
>>
>> yield c;
>>
>> }
>>
>> }
>>
>> We want the possibility to write for (int i : fib(10))=20
>> std::cout<<i<<=E2=80=99\n=E2=80=99; to print the first 10 Fibonacci numb=
ers.
>>
>> So what am I suggest?
>>
>> First, to the syntax. Since we want it to work natively with for-range=
=20
>> loops, and since the language concept is =E2=80=9Cdeclare it the way yo=
u will use=20
>> it=E2=80=9D, I would suggest using colon in the function signature. The =
nicest idea=20
>> I managed to think so far is int : fib(int n)
>>
>> Also, there is no reason to add the keyword yield, when we can stick to=
=20
>> good old return.
>>
>> Now, to the real stuff: What does fib(10) mean? What=E2=80=99s the type =
of=20
>> fib(10).begin()?
>>
>> I suggest this meaning: fib will be (auto-generated) class, and an objec=
t=20
>> of it will represent calling the =E2=80=9Cfunction=E2=80=9D with specifi=
c parameters. The=20
>> member function begin (and end) will return some sort of iterator, which=
=20
>> will represent the actual call.
>>
>> Some details: the fib class should have some members, to contain the=20
>> parameters it called with, but the real fun is in the iterator class: it=
=20
>> will have (in addition to the parameters), as (not exactly, I will expl=
ain=20
>> below) members, all the local variables of the =E2=80=9Cfunction=E2=80=
=9D (including the=20
>> return value), and also the information about where it stopped last time=
=20
>> (and should resume from) - let=E2=80=99s call it, from now on, =E2=80=9C=
position data=E2=80=9D.
>>
>> To be more precise: an iterator should contain the memory for the local=
=20
>> variables (like every member variable), but their lifetime will be as if=
=20
>> they were local variables of the =E2=80=9Cfunction=E2=80=9D. I mean - th=
ey will been=20
>> constructed only when the =E2=80=9Cfunction=E2=80=9D will decide so, and=
not automatically=20
>> when the iterator is been constructed.
>>
>> When the =E2=80=9Cfunction=E2=80=9D ends (either by falling through the =
ending brace, not=20
>> catching exception, or simply saying return; without a value), the=20
>> position data should contain this information, and (like every function)=
,=20
>> every local variable should be destructed.
>>
>> Knowing the position data let us easily determine which variables are=20
>> alive, and so I think that the following member functions can be=20
>> automatically created:
>>
>> copy constructor - should copy the position data, the parameters, and=20
>> every living local variable
>>
>> move constructor - the same, but move instead of copy
>>
>> destructor - destroy the parameters, and every living local variable.
>>
>> (Of course, if some local variable is noncopyable, so is the iterator)
>>
>> I think that it should not be assignable - If one iterator have a live=
=20
>> object, and another one have not, it=E2=80=99s a real mess.
>>
>> Some example:
>>
>> Suppose that we want to yield the number 0, and then, the first n=20
>> Fibonacci numbers and the first n even number, alternately. To add more=
=20
>> interest (and to demonstrate more rules), I want to create and destroy s=
ome=20
>> objects (assume A is a copyable, moveable, and int-constructive class),=
=20
>> so I=E2=80=99ve written the following code:
>>
>> int : fib_even(int n) {
>>
>> A a(7);
>>
>> int fib1=3D0,fib2=3D1,even=3D0;
>>
>> return 0;
>>
>> while(n--) {
>>
>> int fib3=3Dfib1+fib2;
>>
>> fib1=3Dfib2;
>>
>> fib2=3Dfib3;
>>
>> return fib3;
>>
>> A b=3Dn;
>>
>> return even+=3D2;
>>
>> }
>>
>> }
>>
>> A compiler may expand it to something like:
>>
>> (Note: I=E2=80=99m using dynamic memory allocation, but It=E2=80=99s not=
really how it=20
>> should be implemented - I just don=E2=80=99t want some constructors and =
destructors=20
>> to been invoked automatically)
>>
>> class fib_even {
>>
>> class iterator {
>>
>> int n;
>>
>> int *fib1,*fib2,*fib3,*even;
>>
>> A *a,*b;
>>
>> int *ret_value;
>>
>> enum {p0,p1,p2,p3,p4} pos; //resuming points
>>
>> void next() {
>>
>> switch (pos) {
>>
>> case p0: break;
>>
>> case p1: goto label1;
>>
>> case p2: goto label2;
>>
>> case p3: goto label3;
>>
>> case p4: return;
>>
>> }
>>
>> //construct automatic variables of the function
>>
>> a=3Dnew A(7);
>>
>> fib1=3Dnew int(0);
>>
>> fib2=3Dnew int(1);
>>
>> even=3Dnew int(0);
>>
>> //the return process - create the value, save the resuming point, and=20
>> return
>>
>> ret_value=3Dnew int(0);
>>
>> pos=3Dp1;
>>
>> return;
>>
>> label1:
>>
>> while(n--) {
>>
>> fib3=3Dnew int(*fib1+*fib2); //being constructed only now
>>
>> *fib1=3D*fib2;
>>
>> *fib2=3D*fib3;
>>
>> ret_value=3Dnew int(*fib3);
>>
>> pos=3Dp2;
>>
>> return;
>>
>> label2:
>>
>> b=3Dnew A(n);
>>
>> ret_value=3Dnew int((*even)+=3D2);
>>
>> pos=3Dp3;
>>
>> return;
>>
>> label3:
>>
>> //automatic variables going out of scope, and should be destructed
>>
>> delete b;
>>
>> delete fib3;
>>
>> }
>>
>> delete even;
>>
>> delete fib2;
>>
>> delete fib1;
>>
>> delete a;
>>
>> pos=3Dp4;
>>
>> }
>>
>> iterator(int n) : n(n),pos(p0) {
>>
>> next(); //get the first value
>>
>> }
>>
>> iterator() : pos(p4) {}
>>
>> public:
>>
>> iterator &operator++() {
>>
>> delete ret_value;
>>
>> next();
>>
>> return *this;
>>
>> }
>>
>> int &operator*() {
>>
>> return *ret_value;
>>
>> }
>>
>> iterator(const iterator &it) : n(it.n),pos(it.pos) {
>>
>> //copy only living members
>>
>> if (pos>p0 && pos<p4) {
>>
>> ret_value=3Dnew int(*it.ret_value);
>>
>> a=3Dnew A(*it.a);
>>
>> fib1=3Dnew int(*it.fib1);
>>
>> fib2=3Dnew int(*it.fib2);
>>
>> even=3Dnew int(*it.even);
>>
>> }
>>
>> if (pos>p1 && pos<p4) fib3=3Dnew int(*it.fib3);
>>
>> if (pos>p2 && pos<p4) b=3Dnew A(*it.b);
>>
>> }
>>
>> iterator(iterator &&it) : n(std::move(it.n)),pos(it.pos) {
>>
>> if (pos>p0 && pos<p4) {
>>
>> ret_value=3Dnew int(std::move(*it.ret_value));
>>
>> a=3Dnew A(std::move(*it.a));
>>
>> fib1=3Dnew int(std::move(*it.fib1));
>>
>> fib2=3Dnew int(std::move(*it.fib2));
>>
>> even=3Dnew int(std::move(*it.even));
>>
>> }
>>
>> if (pos>p1 && pos<p4) fib3=3Dnew int(std::move(*it.fib3));
>>
>> if (pos>p2 && pos<p4) b=3Dnew A(std::move(*it.b));
>>
>> }
>>
>> ~iterator() {
>>
>> if (pos>p2 && pos<p4) delete b;
>>
>> if (pos>p1 && pos<p4) delete fib3;
>>
>> if (pos>p0 && pos<p4) {
>>
>> delete even;
>>
>> delete fib2;
>>
>> delete fib1;
>>
>> delete a;
>>
>> delete ret_value;
>>
>> }
>>
>> }
>>
>> bool operator!=3D(const iterator &it) {
>>
>> return pos!=3Dit.pos;
>>
>> }
>>
>> operator bool() {
>>
>> return pos<p4; //still hasn't ended
>>
>> }
>>
>> iterator &operator=3D(const iterator&) =3D delete;
>>
>> friend fib_even;
>>
>> };
>>
>> int n;
>>
>> public:
>>
>> fib_even(int n) : n(n) {}
>>
>> iterator begin() {
>>
>> return iterator(n);
>>
>> }
>>
>> iterator end() {
>>
>> return iterator();
>>
>> }
>>
>> };
>>
>> So, what do you think?
>>
>
--=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_482_15419926.1372343679497
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
1) <i>begin</i> and <i>end</i> are the common way to iterate over something=
.. I'm agree that sometimes we just want to have <i>auto coro(args);coro();<=
br>2) You're rig</i>ht. I had forgotten that class template arguments are n=
ot being deducted - even when we just are calling the constructor<br><br>If=
I understood you correctly, you mean to transfrom <i>int : fib(int n) {/*b=
lablabla/*}</i> to <i>fib_class fib(int n) {return fib_class(n);}</i> , whe=
n <i>fib_class</i> is some unnamed data structure. This seems to solve the =
deduction problem. If we allow <i>fib_class::operator()</i>, it means that =
the actual calling is represented by <i>fib_class</i>, and not by <i>fib_cl=
ass:iterator</i>. That's a good idea, but it should deal with:<br>auto coro=
=3Dfib(10);<br>auto iter=3Dfib.begin();<br>int a=3D*iter; //should be 1<br>=
int b=3Dcoro(); //should be 2<br>++iter; //what does this mean? what is the=
value of *iter now?<br>I think that since a coroutine have only one curren=
tly return value, an existing iterator should be invalidated when the corou=
ting is being incremented by other way (using another iterator, or <i>opera=
tor()</i> ).<br>In this concept, I suggest that an iterator object will con=
tain only reference to the coroutine object, and the position data.<br>(Thi=
s also saves the parameters copy in <i>begin</i>)<br><br>Thanks for the fee=
dback. Clearly I may think more about the concept. (My main goals were to d=
iscuss some technical details which weren't clear in https://groups.google.=
com/a/isocpp.org/forum/#!topic/std-proposals/PPZJVTDdDVQ , and to suggest a=
new (and - according to my taste - nice) syntax.<br><br><br>=D7=91=D7=AA=
=D7=90=D7=A8=D7=99=D7=9A =D7=99=D7=95=D7=9D =D7=97=D7=9E=D7=99=D7=A9=D7=99,=
27 =D7=91=D7=99=D7=95=D7=A0=D7=99 2013 11:53:53 UTC+3, =D7=9E=D7=90=D7=AA =
Xeo:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex=
;border-left: 1px #ccc solid;padding-left: 1ex;">While I really want to get=
my hands on native coroutines, I don't think your approach works very well=
..<br><br>1) Who says we always want to use coroutines as `for(auto r : coro=
(args))`? I don't think that's necessarily the main form of use<br>2) How w=
ould the transformation to a class work for template argument deduction?<br=
><br>I think a better course would be to transform the return type of such =
a function, as would be done with async/await-style functions.<br>The retur=
ned type would then simply have an `operator()` and if you wanted a range f=
rom that, it could be quite easily done with a general function-adaptor.<br=
><br>On Thursday, June 27, 2013 3:40:58 AM UTC+2, <a>asa...@gmail.com</a> w=
rote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;=
border-left:1px #ccc solid;padding-left:1ex"><p dir=3D"ltr" style=3D"line-h=
eight:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;=
font-family:Arial;color:#000000;background-color:transparent;font-weight:no=
rmal;font-style:normal;font-variant:normal;text-decoration:none;vertical-al=
ign:baseline">Recently, I=E2=80=99ve thought a lot about coroutines, and ho=
w they should behave if became a part of c++.</span></p><p dir=3D"ltr" styl=
e=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font=
-size:15px;font-family:Arial;color:#000000;background-color:transparent;fon=
t-weight:normal;font-style:normal;font-variant:normal;text-decoration:none;=
vertical-align:baseline">I found two (main) proposals:</span></p><p dir=3D"=
ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span styl=
e=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transp=
arent;font-weight:normal;font-style:normal;font-variant:normal;text-decorat=
ion:none;vertical-align:baseline">a. </span><a href=3D"https://groups.googl=
e.com/a/isocpp.org/forum/#%21topic/std-proposals/3g6ZIWedGJ8" style=3D"text=
-decoration:none" target=3D"_blank"><span style=3D"font-size:15px;font-fami=
ly:Arial;color:#1155cc;background-color:transparent;font-weight:normal;font=
-style:normal;font-variant:normal;text-decoration:underline;vertical-align:=
baseline">https://groups.google.com/a/<wbr>isocpp.org/forum/#!topic/std-<wb=
r>proposals/3g6ZIWedGJ8</span></a><span style=3D"font-size:15px;font-family=
:Arial;color:#000000;background-color:transparent;font-weight:normal;font-s=
tyle:normal;font-variant:normal;text-decoration:none;vertical-align:baselin=
e"></span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margi=
n-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000=
;background-color:transparent;font-weight:normal;font-style:normal;font-var=
iant:normal;text-decoration:none;vertical-align:baseline">It
has the advantage of not requiring to change the syntax, but in force a
new model of stack-based calls. It does so in purpose to let nested=20
functions to yield value, which I think is not really necessary. (If we=20
let nested functions return value on behalf of their callee, we should=20
start this in regular functions). Also, Its syntax is somehow complex.</spa=
n></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom=
:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgro=
und-color:transparent;font-weight:normal;font-style:normal;font-variant:nor=
mal;text-decoration:none;vertical-align:baseline">b. </span><a href=3D"http=
s://groups.google.com/a/isocpp.org/forum/#%21topic/std-proposals/PPZJVTDdDV=
Q" style=3D"text-decoration:none" target=3D"_blank"><span style=3D"font-siz=
e:15px;font-family:Arial;color:#1155cc;background-color:transparent;font-we=
ight:normal;font-style:normal;font-variant:normal;text-decoration:underline=
;vertical-align:baseline">https://groups.google.com/a/<wbr>isocpp.org/forum=
/#!topic/std-<wbr>proposals/PPZJVTDdDVQ</span></a><span style=3D"font-size:=
15px;font-family:Arial;color:#000000;background-color:transparent;font-weig=
ht:normal;font-style:normal;font-variant:normal;text-decoration:none;vertic=
al-align:baseline"></span></p><p dir=3D"ltr" style=3D"line-height:1.15;marg=
in-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Ari=
al;color:#000000;background-color:transparent;font-weight:normal;font-style=
:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">I=
t
is easy to use and doesn=E2=80=99t require a new stack, and I think that t=
his=20
is the right direction. However, it ignores some technical details=20
(lifetime of locals, etc). Also, adding a keyword may break too many=20
working code, and my personal opinion is that it is ugly. Sentences like
=E2=80=9Cvoid numbers() yields int=E2=80=9D reminds me too many things I h=
ate in Java.=20
The alternative syntax (described at the end of this proposal) is not so
ugly, but still complex.</span></p><p dir=3D"ltr" style=3D"line-height:1.1=
5;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-fami=
ly:Arial;color:#000000;background-color:transparent;font-weight:normal;font=
-style:normal;font-variant:normal;text-decoration:none;vertical-align:basel=
ine">There is even a nice implementation of coroutines (using macros): </sp=
an><a href=3D"http://www.chiark.greenend.org.uk/%7Esgtatham/coroutines.html=
" style=3D"text-decoration:none" target=3D"_blank"><span style=3D"font-size=
:15px;font-family:Arial;color:#1155cc;background-color:transparent;font-wei=
ght:normal;font-style:normal;font-variant:normal;text-decoration:underline;=
vertical-align:baseline">http://www.chiark.greenend.<wbr>org.uk/~sgtatham/c=
oroutines.<wbr>html</span></a><span style=3D"font-size:15px;font-family:Ari=
al;color:#000000;background-color:transparent;font-weight:normal;font-style=
:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"><=
/span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bo=
ttom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;bac=
kground-color:transparent;font-weight:normal;font-style:normal;font-variant=
:normal;text-decoration:none;vertical-align:baseline">but
it has 2 major disadvantages: while using it, we can=E2=80=99t yield a val=
ue=20
from within a switch statement, and, much more important, we have to=20
define all the local variables at the top of the function - back to C90=20
days! (and with constructors this is much worst.)</span></p><br><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline"></span><p dir=3D"ltr" style=3D"line-height=
:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-=
family:Arial;color:#000000;background-color:transparent;font-weight:normal;=
font-style:normal;font-variant:normal;text-decoration:none;vertical-align:b=
aseline">Another
thing that was very little talk about, is for-range loops native=20
support. Let=E2=80=99s say we have a Fibonacci number generator (a very com=
mon=20
example):</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt=
;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#=
000000;background-color:transparent;font-weight:normal;font-style:normal;fo=
nt-variant:normal;text-decoration:none;vertical-align:baseline">(Using Deni=
s Bredelet=E2=80=99s proposal syntax)</span></p><p dir=3D"ltr" style=3D"lin=
e-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15=
px;font-family:Arial;color:#000000;background-color:transparent;font-weight=
:normal;font-style:normal;font-variant:normal;text-decoration:none;vertical=
-align:baseline">void fib(int n) yields int {</span></p><p dir=3D"ltr" styl=
e=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font=
-size:15px;font-family:Arial;color:#000000;background-color:transparent;fon=
t-weight:normal;font-style:normal;font-variant:normal;text-decoration:none;=
vertical-align:baseline"> int a=3D0,b=3D1;</span></p><p dir=3D"ltr" s=
tyle=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"f=
ont-size:15px;font-family:Arial;color:#000000;background-color:transparent;=
font-weight:normal;font-style:normal;font-variant:normal;text-decoration:no=
ne;vertical-align:baseline"> while(n--) {</span></p><p dir=3D"ltr" st=
yle=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"fo=
nt-size:15px;font-family:Arial;color:#000000;background-color:transparent;f=
ont-weight:normal;font-style:normal;font-variant:normal;text-decoration:non=
e;vertical-align:baseline"> int c=3Da+b;</span></p><p dir=
=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span =
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:tr=
ansparent;font-weight:normal;font-style:normal;font-variant:normal;text-dec=
oration:none;vertical-align:baseline"> a=3Db;</span></p><=
p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><=
span style=3D"font-size:15px;font-family:Arial;color:#000000;background-col=
or:transparent;font-weight:normal;font-style:normal;font-variant:normal;tex=
t-decoration:none;vertical-align:baseline"> b=3Dc;</span>=
</p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0=
pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgroun=
d-color:transparent;font-weight:normal;font-style:normal;font-variant:norma=
l;text-decoration:none;vertical-align:baseline"> yield c;=
</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-b=
ottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;ba=
ckground-color:transparent;font-weight:normal;font-style:normal;font-varian=
t:normal;text-decoration:none;vertical-align:baseline"> }</span></p><=
p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><=
span style=3D"font-size:15px;font-family:Arial;color:#000000;background-col=
or:transparent;font-weight:normal;font-style:normal;font-variant:normal;tex=
t-decoration:none;vertical-align:baseline">}</span></p><p dir=3D"ltr" style=
=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-=
size:15px;font-family:Arial;color:#000000;background-color:transparent;font=
-weight:normal;font-style:normal;font-variant:normal;text-decoration:none;v=
ertical-align:baseline">We want the possibility to write </span><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:italic;font-variant:normal;text-decorati=
on:none;vertical-align:baseline">for (int i : fib(10)) std::cout<<i&l=
t;<=E2=80=99\n=E2=80=99;</span><span style=3D"font-size:15px;font-family=
:Arial;color:#000000;background-color:transparent;font-weight:normal;font-s=
tyle:normal;font-variant:normal;text-decoration:none;vertical-align:baselin=
e"> to print the first 10 Fibonacci numbers.</span></p><br><span style=3D"f=
ont-size:15px;font-family:Arial;color:#000000;background-color:transparent;=
font-weight:normal;font-style:normal;font-variant:normal;text-decoration:no=
ne;vertical-align:baseline"></span><p dir=3D"ltr" style=3D"line-height:1.15=
;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-famil=
y:Arial;color:#000000;background-color:transparent;font-weight:normal;font-=
style:normal;font-variant:normal;text-decoration:none;vertical-align:baseli=
ne">So what am I suggest?</span></p><p dir=3D"ltr" style=3D"line-height:1.1=
5;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-fami=
ly:Arial;color:#000000;background-color:transparent;font-weight:normal;font=
-style:normal;font-variant:normal;text-decoration:none;vertical-align:basel=
ine">First,
to the syntax. Since we want it to work natively with for-range loops,=20
and since the language concept is =E2=80=9Cdeclare it the way you wil=
l use it=E2=80=9D,
I would suggest using colon in the function signature. The nicest idea I
managed to think so far is </span><span style=3D"font-size:15px;font-famil=
y:Arial;color:#000000;background-color:transparent;font-weight:normal;font-=
style:italic;font-variant:normal;text-decoration:none;vertical-align:baseli=
ne">int : fib(int n)</span></p><p dir=3D"ltr" style=3D"line-height:1.15;mar=
gin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Ar=
ial;color:#000000;background-color:transparent;font-weight:normal;font-styl=
e:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">=
Also, there is no reason to add the keyword </span><span style=3D"font-size=
:15px;font-family:Arial;color:#000000;background-color:transparent;font-wei=
ght:normal;font-style:italic;font-variant:normal;text-decoration:none;verti=
cal-align:baseline">yield</span><span style=3D"font-size:15px;font-family:A=
rial;color:#000000;background-color:transparent;font-weight:normal;font-sty=
le:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"=
>, when we can stick to good old </span><span style=3D"font-size:15px;font-=
family:Arial;color:#000000;background-color:transparent;font-weight:normal;=
font-style:italic;font-variant:normal;text-decoration:none;vertical-align:b=
aseline">return</span><span style=3D"font-size:15px;font-family:Arial;color=
:#000000;background-color:transparent;font-weight:normal;font-style:normal;=
font-variant:normal;text-decoration:none;vertical-align:baseline">.</span><=
/p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0p=
t"><span style=3D"font-size:15px;font-family:Arial;color:#000000;background=
-color:transparent;font-weight:normal;font-style:normal;font-variant:normal=
;text-decoration:none;vertical-align:baseline">Now, to the real stuff: What=
does </span><span style=3D"font-size:15px;font-family:Arial;color:#000000;=
background-color:transparent;font-weight:normal;font-style:italic;font-vari=
ant:normal;text-decoration:none;vertical-align:baseline">fib(10)</span><spa=
n style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:=
transparent;font-weight:normal;font-style:normal;font-variant:normal;text-d=
ecoration:none;vertical-align:baseline"> mean? What=E2=80=99s the type of <=
/span><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgro=
und-color:transparent;font-weight:normal;font-style:italic;font-variant:nor=
mal;text-decoration:none;vertical-align:baseline">fib(10).begin()</span><sp=
an style=3D"font-size:15px;font-family:Arial;color:#000000;background-color=
:transparent;font-weight:normal;font-style:normal;font-variant:normal;text-=
decoration:none;vertical-align:baseline">?</span></p><p dir=3D"ltr" style=
=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-=
size:15px;font-family:Arial;color:#000000;background-color:transparent;font=
-weight:normal;font-style:normal;font-variant:normal;text-decoration:none;v=
ertical-align:baseline">I
suggest this meaning: fib will be (auto-generated) class, and an object
of it will represent calling the =E2=80=9Cfunction=E2=80=9D with specific =
parameters.=20
The member function </span><span style=3D"font-size:15px;font-family:Arial;=
color:#000000;background-color:transparent;font-weight:normal;font-style:it=
alic;font-variant:normal;text-decoration:none;vertical-align:baseline">begi=
n</span><span style=3D"font-size:15px;font-family:Arial;color:#000000;backg=
round-color:transparent;font-weight:normal;font-style:normal;font-variant:n=
ormal;text-decoration:none;vertical-align:baseline"> (and </span><span styl=
e=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transp=
arent;font-weight:normal;font-style:italic;font-variant:normal;text-decorat=
ion:none;vertical-align:baseline">end</span><span style=3D"font-size:15px;f=
ont-family:Arial;color:#000000;background-color:transparent;font-weight:nor=
mal;font-style:normal;font-variant:normal;text-decoration:none;vertical-ali=
gn:baseline">) will return some sort of iterator, which will represent the =
actual call.</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:=
0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;colo=
r:#000000;background-color:transparent;font-weight:normal;font-style:normal=
;font-variant:normal;text-decoration:none;vertical-align:baseline">Some det=
ails: the </span><span style=3D"font-size:15px;font-family:Arial;color:#000=
000;background-color:transparent;font-weight:normal;font-style:italic;font-=
variant:normal;text-decoration:none;vertical-align:baseline">fib</span><spa=
n style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:=
transparent;font-weight:normal;font-style:normal;font-variant:normal;text-d=
ecoration:none;vertical-align:baseline"> class should have some members, to=
contain the parameters it called with, but the real fun is in the </span><=
span style=3D"font-size:15px;font-family:Arial;color:#000000;background-col=
or:transparent;font-weight:normal;font-style:italic;font-variant:normal;tex=
t-decoration:none;vertical-align:baseline">iterator</span><span style=3D"fo=
nt-size:15px;font-family:Arial;color:#000000;background-color:transparent;f=
ont-weight:normal;font-style:normal;font-variant:normal;text-decoration:non=
e;vertical-align:baseline">
class: it will have (in addition to the parameters), as (not exactly=
, I
will explain below) members, all the local variables of the =E2=80=9Cfunct=
ion=E2=80=9D=20
(including the return value), and also the information about where it=20
stopped last time (and should resume from) - let=E2=80=99s call it, from no=
w on,
=E2=80=9Cposition data=E2=80=9D.</span></p><p dir=3D"ltr" style=3D"line-he=
ight:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;f=
ont-family:Arial;color:#000000;background-color:transparent;font-weight:nor=
mal;font-style:normal;font-variant:normal;text-decoration:none;vertical-ali=
gn:baseline">To be more precise: an </span><span style=3D"font-size:15px;fo=
nt-family:Arial;color:#000000;background-color:transparent;font-weight:norm=
al;font-style:italic;font-variant:normal;text-decoration:none;vertical-alig=
n:baseline">iterator</span><span style=3D"font-size:15px;font-family:Arial;=
color:#000000;background-color:transparent;font-weight:normal;font-style:no=
rmal;font-variant:normal;text-decoration:none;vertical-align:baseline">
should contain the memory for the local variables (like every member=20
variable), but their lifetime will be as if they were local variables of
the =E2=80=9Cfunction=E2=80=9D. I mean - they will been constructed only w=
hen the=20
=E2=80=9Cfunction=E2=80=9D will decide so, and not automatically when the <=
/span><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgro=
und-color:transparent;font-weight:normal;font-style:italic;font-variant:nor=
mal;text-decoration:none;vertical-align:baseline">iterator</span><span styl=
e=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transp=
arent;font-weight:normal;font-style:normal;font-variant:normal;text-decorat=
ion:none;vertical-align:baseline"> is been constructed.</span></p><p dir=3D=
"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span sty=
le=3D"font-size:15px;font-family:Arial;color:#000000;background-color:trans=
parent;font-weight:normal;font-style:normal;font-variant:normal;text-decora=
tion:none;vertical-align:baseline">When the =E2=80=9Cfunction=E2=80=9D ends=
(either by falling through the ending brace, not catching exception, or si=
mply saying </span><span style=3D"font-size:15px;font-family:Arial;color:#0=
00000;background-color:transparent;font-weight:normal;font-style:italic;fon=
t-variant:normal;text-decoration:none;vertical-align:baseline">return;</spa=
n><span style=3D"font-size:15px;font-family:Arial;color:#000000;background-=
color:transparent;font-weight:normal;font-style:normal;font-variant:normal;=
text-decoration:none;vertical-align:baseline">
without a value), the position data should contain this information,=20
and (like every function), every local variable should be destructed.</span=
></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:=
0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgrou=
nd-color:transparent;font-weight:normal;font-style:normal;font-variant:norm=
al;text-decoration:none;vertical-align:baseline">Knowing
the position data let us easily determine which variables are alive,=20
and so I think that the following member functions can be automatically=20
created:</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;=
margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#0=
00000;background-color:transparent;font-weight:normal;font-style:normal;fon=
t-variant:normal;text-decoration:none;vertical-align:baseline">copy constru=
ctor - should copy the position data, the parameters, and every living loca=
l variable</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0p=
t;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:=
#000000;background-color:transparent;font-weight:normal;font-style:normal;f=
ont-variant:normal;text-decoration:none;vertical-align:baseline">move const=
ructor - the same, but move instead of copy</span></p><p dir=3D"ltr" style=
=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-=
size:15px;font-family:Arial;color:#000000;background-color:transparent;font=
-weight:normal;font-style:normal;font-variant:normal;text-decoration:none;v=
ertical-align:baseline">destructor - destroy the parameters, and every livi=
ng local variable.</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margi=
n-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Aria=
l;color:#000000;background-color:transparent;font-weight:normal;font-style:=
normal;font-variant:normal;text-decoration:none;vertical-align:baseline">(O=
f course, if some local variable is noncopyable, so is the iterator)</span>=
</p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0=
pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgroun=
d-color:transparent;font-weight:normal;font-style:normal;font-variant:norma=
l;text-decoration:none;vertical-align:baseline">I think that it should not =
be assignable - If one iterator have a live object, and another one have no=
t, it=E2=80=99s a real mess.</span></p><br><span style=3D"font-size:15px;fo=
nt-family:Arial;color:#000000;background-color:transparent;font-weight:norm=
al;font-style:normal;font-variant:normal;text-decoration:none;vertical-alig=
n:baseline"></span><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;=
margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#0=
00000;background-color:transparent;font-weight:normal;font-style:normal;fon=
t-variant:normal;text-decoration:none;vertical-align:baseline">Some example=
:</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-=
bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;b=
ackground-color:transparent;font-weight:normal;font-style:normal;font-varia=
nt:normal;text-decoration:none;vertical-align:baseline">Suppose
that we want to yield the number 0, and then, the first n Fibonacci=20
numbers and the first n even number, alternately. To add more interest=20
(and to demonstrate more rules), I want to create and destroy some=20
objects (assume </span><span style=3D"font-size:15px;font-family:Arial;colo=
r:#000000;background-color:transparent;font-weight:normal;font-style:italic=
;font-variant:normal;text-decoration:none;vertical-align:baseline">A</span>=
<span style=3D"font-size:15px;font-family:Arial;color:#000000;background-co=
lor:transparent;font-weight:normal;font-style:normal;font-variant:normal;te=
xt-decoration:none;vertical-align:baseline"> is a copyable, moveable, and i=
nt-constructive class), so I=E2=80=99ve written the following code:</span><=
/p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0p=
t"><span style=3D"font-size:15px;font-family:Arial;color:#000000;background=
-color:transparent;font-weight:normal;font-style:normal;font-variant:normal=
;text-decoration:none;vertical-align:baseline">int : fib_even(int n) {</spa=
n></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom=
:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgro=
und-color:transparent;font-weight:normal;font-style:normal;font-variant:nor=
mal;text-decoration:none;vertical-align:baseline"> A a(7)=
;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-=
bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;b=
ackground-color:transparent;font-weight:normal;font-style:normal;font-varia=
nt:normal;text-decoration:none;vertical-align:baseline"> =
int fib1=3D0,fib2=3D1,even=3D0;</span></p><p dir=3D"ltr" style=3D"line-heig=
ht:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;fon=
t-family:Arial;color:#000000;background-color:transparent;font-weight:norma=
l;font-style:normal;font-variant:normal;text-decoration:none;vertical-align=
:baseline"> return 0;</span></p><p dir=3D"ltr" style=3D"l=
ine-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:=
15px;font-family:Arial;color:#000000;background-color:transparent;font-weig=
ht:normal;font-style:normal;font-variant:normal;text-decoration:none;vertic=
al-align:baseline"> while(n--) {</span></p><p dir=3D"ltr"=
style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D=
"font-size:15px;font-family:Arial;color:#000000;background-color:transparen=
t;font-weight:normal;font-style:normal;font-variant:normal;text-decoration:=
none;vertical-align:baseline"> int fib=
3=3Dfib1+fib2;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-to=
p:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;co=
lor:#000000;background-color:transparent;font-weight:normal;font-style:norm=
al;font-variant:normal;text-decoration:none;vertical-align:baseline">  =
; fib1=3Dfib2;</span></p><p dir=3D"ltr" style=
=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-=
size:15px;font-family:Arial;color:#000000;background-color:transparent;font=
-weight:normal;font-style:normal;font-variant:normal;text-decoration:none;v=
ertical-align:baseline"> fib2=3Dfib3;<=
/span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bo=
ttom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;bac=
kground-color:transparent;font-weight:normal;font-style:normal;font-variant=
:normal;text-decoration:none;vertical-align:baseline"> &n=
bsp; return fib3;</span></p><p dir=3D"ltr" style=3D"line-height=
:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-=
family:Arial;color:#000000;background-color:transparent;font-weight:normal;=
font-style:normal;font-variant:normal;text-decoration:none;vertical-align:b=
aseline"> A b=3Dn;</span></p><p dir=3D=
"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span sty=
le=3D"font-size:15px;font-family:Arial;color:#000000;background-color:trans=
parent;font-weight:normal;font-style:normal;font-variant:normal;text-decora=
tion:none;vertical-align:baseline"> re=
turn even+=3D2;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-t=
op:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;c=
olor:#000000;background-color:transparent;font-weight:normal;font-style:nor=
mal;font-variant:normal;text-decoration:none;vertical-align:baseline"> &nbs=
p; }</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-t=
op:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;c=
olor:#000000;background-color:transparent;font-weight:normal;font-style:nor=
mal;font-variant:normal;text-decoration:none;vertical-align:baseline">}</sp=
an></p><br><span style=3D"font-size:15px;font-family:Arial;color:#000000;ba=
ckground-color:transparent;font-weight:normal;font-style:normal;font-varian=
t:normal;text-decoration:none;vertical-align:baseline"></span><p dir=3D"ltr=
" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline">A compiler may expand it to something like=
:</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-=
bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;b=
ackground-color:transparent;font-weight:normal;font-style:normal;font-varia=
nt:normal;text-decoration:none;vertical-align:baseline">(Note:
I=E2=80=99m using dynamic memory allocation, but It=E2=80=99s not really h=
ow it should=20
be implemented - I just don=E2=80=99t want some constructors and destructor=
s to=20
been invoked automatically)</span></p><br><span style=3D"font-size:15px;fon=
t-family:Arial;color:#000000;background-color:transparent;font-weight:norma=
l;font-style:normal;font-variant:normal;text-decoration:none;vertical-align=
:baseline"></span><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;m=
argin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#00=
0000;background-color:transparent;font-weight:normal;font-style:normal;font=
-variant:normal;text-decoration:none;vertical-align:baseline">class fib_eve=
n {</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margi=
n-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000=
;background-color:transparent;font-weight:normal;font-style:normal;font-var=
iant:normal;text-decoration:none;vertical-align:baseline"> &nbs=
p;class iterator {</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margi=
n-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Aria=
l;color:#000000;background-color:transparent;font-weight:normal;font-style:=
normal;font-variant:normal;text-decoration:none;vertical-align:baseline"> &=
nbsp; int n;</span></p><p dir=3D"ltr" style=
=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-=
size:15px;font-family:Arial;color:#000000;background-color:transparent;font=
-weight:normal;font-style:normal;font-variant:normal;text-decoration:none;v=
ertical-align:baseline"> int *fib1,*fi=
b2,*fib3,*even;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-t=
op:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;c=
olor:#000000;background-color:transparent;font-weight:normal;font-style:nor=
mal;font-variant:normal;text-decoration:none;vertical-align:baseline"> &nbs=
p; A *a,*b;</span></p><p dir=3D"ltr" style=3D=
"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-siz=
e:15px;font-family:Arial;color:#000000;background-color:transparent;font-we=
ight:normal;font-style:normal;font-variant:normal;text-decoration:none;vert=
ical-align:baseline"> int *ret_value;<=
/span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bo=
ttom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;bac=
kground-color:transparent;font-weight:normal;font-style:normal;font-variant=
:normal;text-decoration:none;vertical-align:baseline"> &n=
bsp; enum {p0,p1,p2,p3,p4} pos; //resuming points<br></span></p=
><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"=
><span style=3D"font-size:15px;font-family:Arial;color:#000000;background-c=
olor:transparent;font-weight:normal;font-style:normal;font-variant:normal;t=
ext-decoration:none;vertical-align:baseline">  =
; void next() {</span></p><p dir=3D"ltr" style=3D"line-height:1.15;ma=
rgin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:A=
rial;color:#000000;background-color:transparent;font-weight:normal;font-sty=
le:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"=
> switch (pos) {</s=
pan></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bott=
om:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backg=
round-color:transparent;font-weight:normal;font-style:normal;font-variant:n=
ormal;text-decoration:none;vertical-align:baseline"> &nbs=
p; case p0: break;</span>=
</p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0=
pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgroun=
d-color:transparent;font-weight:normal;font-style:normal;font-variant:norma=
l;text-decoration:none;vertical-align:baseline"> &n=
bsp; case p1: goto label1;</spa=
n></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom=
:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgro=
und-color:transparent;font-weight:normal;font-style:normal;font-variant:nor=
mal;text-decoration:none;vertical-align:baseline"> =
case p2: goto label2;</s=
pan></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bott=
om:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backg=
round-color:transparent;font-weight:normal;font-style:normal;font-variant:n=
ormal;text-decoration:none;vertical-align:baseline"> &nbs=
p; case p3: goto label3;<=
/span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bo=
ttom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;bac=
kground-color:transparent;font-weight:normal;font-style:normal;font-variant=
:normal;text-decoration:none;vertical-align:baseline"> &n=
bsp; case p4: return;</sp=
an></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-botto=
m:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgr=
ound-color:transparent;font-weight:normal;font-style:normal;font-variant:no=
rmal;text-decoration:none;vertical-align:baseline">  =
; }</span></p><p dir=3D"ltr" style=3D"line-h=
eight:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;=
font-family:Arial;color:#000000;background-color:transparent;font-weight:no=
rmal;font-style:normal;font-variant:normal;text-decoration:none;vertical-al=
ign:baseline">//construct automatic variables of t</span><span style=3D"fon=
t-size:15px;font-family:Arial;color:#000000;background-color:transparent;fo=
nt-weight:normal;font-style:normal;font-variant:normal;text-decoration:none=
;vertical-align:baseline">he function<br></span></p><p dir=3D"ltr" style=3D=
"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-siz=
e:15px;font-family:Arial;color:#000000;background-color:transparent;font-we=
ight:normal;font-style:normal;font-variant:normal;text-decoration:none;vert=
ical-align:baseline"> &nb=
sp;a=3Dnew A(7);</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-=
top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;=
color:#000000;background-color:transparent;font-weight:normal;font-style:no=
rmal;font-variant:normal;text-decoration:none;vertical-align:baseline"> &nb=
sp; fib1=3Dnew int(0);</sp=
an></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-botto=
m:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgr=
ound-color:transparent;font-weight:normal;font-style:normal;font-variant:no=
rmal;text-decoration:none;vertical-align:baseline">  =
; fib2=3Dnew int(1);</span></p><p dir=3D"ltr=
" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline"> &nbs=
p; even=3Dnew int(0);</span></p><p dir=3D"ltr" style=3D"line-he=
ight:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;f=
ont-family:Arial;color:#000000;background-color:transparent;font-weight:nor=
mal;font-style:normal;font-variant:normal;text-decoration:none;vertical-ali=
gn:baseline">//t</span><span style=3D"font-size:15px;font-family:Arial;colo=
r:#000000;background-color:transparent;font-weight:normal;font-style:normal=
;font-variant:normal;text-decoration:none;vertical-align:baseline">he retur=
n process - create t</span><span style=3D"font-size:15px;font-family:Arial;=
color:#000000;background-color:transparent;font-weight:normal;font-style:no=
rmal;font-variant:normal;text-decoration:none;vertical-align:baseline">he v=
alue, save t</span><span style=3D"font-size:15px;font-family:Arial;color:#0=
00000;background-color:transparent;font-weight:normal;font-style:normal;fon=
t-variant:normal;text-decoration:none;vertical-align:baseline">he resuming =
point, and return<br></span></p><p dir=3D"ltr" style=3D"line-height:1.15;ma=
rgin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:A=
rial;color:#000000;background-color:transparent;font-weight:normal;font-sty=
le:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"=
> ret_value=3Dnew i=
nt(0);</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;ma=
rgin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000=
000;background-color:transparent;font-weight:normal;font-style:normal;font-=
variant:normal;text-decoration:none;vertical-align:baseline"> &=
nbsp; pos=3Dp1;</span></p><p dir=3D"lt=
r" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline"> &nbs=
p; return;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;m=
argin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:=
Arial;color:#000000;background-color:transparent;font-weight:normal;font-st=
yle:normal;font-variant:normal;text-decoration:none;vertical-align:baseline=
"> label1:<br></span></p><p dir=3D"ltr=
" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline"> &nbs=
p; while(n--) {</span></p><p dir=3D"ltr" style=3D"line-height:1=
..15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-fa=
mily:Arial;color:#000000;background-color:transparent;font-weight:normal;fo=
nt-style:normal;font-variant:normal;text-decoration:none;vertical-align:bas=
eline">  =
; fib3=3Dnew int(*fib1+*fib2); //being constructed only now<br></span=
></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:=
0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgrou=
nd-color:transparent;font-weight:normal;font-style:normal;font-variant:norm=
al;text-decoration:none;vertical-align:baseline"> &=
nbsp; *fib1=3D*fib2;</span></p>=
<p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt">=
<span style=3D"font-size:15px;font-family:Arial;color:#000000;background-co=
lor:transparent;font-weight:normal;font-style:normal;font-variant:normal;te=
xt-decoration:none;vertical-align:baseline"> =
*fib2=3D*fib3;</span></p><p di=
r=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span=
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:t=
ransparent;font-weight:normal;font-style:normal;font-variant:normal;text-de=
coration:none;vertical-align:baseline"> &nbs=
p; ret_value=3Dnew int(*fib3);</span><=
/p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0p=
t"><span style=3D"font-size:15px;font-family:Arial;color:#000000;background=
-color:transparent;font-weight:normal;font-style:normal;font-variant:normal=
;text-decoration:none;vertical-align:baseline"> &nb=
sp; pos=3Dp2;</span></p><p dir=
=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span =
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:tr=
ansparent;font-weight:normal;font-style:normal;font-variant:normal;text-dec=
oration:none;vertical-align:baseline">  =
; return;</span></p><p dir=3D"ltr" sty=
le=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"fon=
t-size:15px;font-family:Arial;color:#000000;background-color:transparent;fo=
nt-weight:normal;font-style:normal;font-variant:normal;text-decoration:none=
;vertical-align:baseline"> label2:</sp=
an></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-botto=
m:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgr=
ound-color:transparent;font-weight:normal;font-style:normal;font-variant:no=
rmal;text-decoration:none;vertical-align:baseline">  =
; b=3Dnew A(n);</span></p=
><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"=
><span style=3D"font-size:15px;font-family:Arial;color:#000000;background-c=
olor:transparent;font-weight:normal;font-style:normal;font-variant:normal;t=
ext-decoration:none;vertical-align:baseline">  =
; ret_value=3Dnew int((*even)+=
=3D2);</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;ma=
rgin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000=
000;background-color:transparent;font-weight:normal;font-style:normal;font-=
variant:normal;text-decoration:none;vertical-align:baseline"> &=
nbsp; pos=3Dp3;</sp=
an></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-botto=
m:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgr=
ound-color:transparent;font-weight:normal;font-style:normal;font-variant:no=
rmal;text-decoration:none;vertical-align:baseline">  =
; return;</span></p><p di=
r=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span=
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:t=
ransparent;font-weight:normal;font-style:normal;font-variant:normal;text-de=
coration:none;vertical-align:baseline"> &nbs=
p;label3:</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt=
;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#=
000000;background-color:transparent;font-weight:normal;font-style:normal;fo=
nt-variant:normal;text-decoration:none;vertical-align:baseline">//automatic=
variables going out of scope, and s</span><span style=3D"font-size:15px;fo=
nt-family:Arial;color:#000000;background-color:transparent;font-weight:norm=
al;font-style:normal;font-variant:normal;text-decoration:none;vertical-alig=
n:baseline"><span style=3D"font-size:15px;font-family:Arial;color:#000000;b=
ackground-color:transparent;font-weight:normal;font-style:normal;font-varia=
nt:normal;text-decoration:none;vertical-align:baseline">h</span>ould be des=
tructed<br></span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0=
pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color=
:#000000;background-color:transparent;font-weight:normal;font-style:normal;=
font-variant:normal;text-decoration:none;vertical-align:baseline"> &n=
bsp; delete b=
;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-=
bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;b=
ackground-color:transparent;font-weight:normal;font-style:normal;font-varia=
nt:normal;text-decoration:none;vertical-align:baseline"> =
delete fib3;</span=
></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:=
0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgrou=
nd-color:transparent;font-weight:normal;font-style:normal;font-variant:norm=
al;text-decoration:none;vertical-align:baseline"> &=
nbsp; }</span></p><p dir=3D"ltr" style=3D"line-hei=
ght:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;fo=
nt-family:Arial;color:#000000;background-color:transparent;font-weight:norm=
al;font-style:normal;font-variant:normal;text-decoration:none;vertical-alig=
n:baseline"> delete=
even;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;ma=
rgin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000=
000;background-color:transparent;font-weight:normal;font-style:normal;font-=
variant:normal;text-decoration:none;vertical-align:baseline"> &=
nbsp; delete fib2;</span></p><p dir=3D=
"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span sty=
le=3D"font-size:15px;font-family:Arial;color:#000000;background-color:trans=
parent;font-weight:normal;font-style:normal;font-variant:normal;text-decora=
tion:none;vertical-align:baseline"> &n=
bsp; delete fib1;</span></p><p dir=3D"ltr" style=3D"line-height=
:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-=
family:Arial;color:#000000;background-color:transparent;font-weight:normal;=
font-style:normal;font-variant:normal;text-decoration:none;vertical-align:b=
aseline"> delete a;=
</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-b=
ottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;ba=
ckground-color:transparent;font-weight:normal;font-style:normal;font-varian=
t:normal;text-decoration:none;vertical-align:baseline"> &=
nbsp; pos=3Dp4;</span></p><p dir=3D"ltr" sty=
le=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"fon=
t-size:15px;font-family:Arial;color:#000000;background-color:transparent;fo=
nt-weight:normal;font-style:normal;font-variant:normal;text-decoration:none=
;vertical-align:baseline"> }</span></p=
><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"=
><span style=3D"font-size:15px;font-family:Arial;color:#000000;background-c=
olor:transparent;font-weight:normal;font-style:normal;font-variant:normal;t=
ext-decoration:none;vertical-align:baseline">  =
; iterator(int n) : n(n),pos(p0) {</span></p><p dir=3D"ltr" style=3D"=
line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size=
:15px;font-family:Arial;color:#000000;background-color:transparent;font-wei=
ght:normal;font-style:normal;font-variant:normal;text-decoration:none;verti=
cal-align:baseline"> &nbs=
p;next(); //get t</span><span style=3D"font-size:15px;font-family:Arial;col=
or:#000000;background-color:transparent;font-weight:normal;font-style:norma=
l;font-variant:normal;text-decoration:none;vertical-align:baseline">he firs=
t value<br></span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0=
pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color=
:#000000;background-color:transparent;font-weight:normal;font-style:normal;=
font-variant:normal;text-decoration:none;vertical-align:baseline"> &n=
bsp; }</span></p><p dir=3D"ltr" style=3D"line-heigh=
t:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font=
-family:Arial;color:#000000;background-color:transparent;font-weight:normal=
;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:=
baseline"> iterator() : pos(p4) {}</sp=
an></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-botto=
m:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgr=
ound-color:transparent;font-weight:normal;font-style:normal;font-variant:no=
rmal;text-decoration:none;vertical-align:baseline"> publi=
c:</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin=
-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;=
background-color:transparent;font-weight:normal;font-style:normal;font-vari=
ant:normal;text-decoration:none;vertical-align:baseline">  =
; iterator &operator++() {</span></p><p dir=3D"ltr" s=
tyle=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"f=
ont-size:15px;font-family:Arial;color:#000000;background-color:transparent;=
font-weight:normal;font-style:normal;font-variant:normal;text-decoration:no=
ne;vertical-align:baseline"> &nb=
sp; delete ret_value;</span></p><p dir=3D"ltr" style=3D"line-height:1=
..15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-fa=
mily:Arial;color:#000000;background-color:transparent;font-weight:normal;fo=
nt-style:normal;font-variant:normal;text-decoration:none;vertical-align:bas=
eline"> next();</sp=
an></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-botto=
m:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgr=
ound-color:transparent;font-weight:normal;font-style:normal;font-variant:no=
rmal;text-decoration:none;vertical-align:baseline">  =
; return *this;</span></p><p dir=3D"ltr" sty=
le=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"fon=
t-size:15px;font-family:Arial;color:#000000;background-color:transparent;fo=
nt-weight:normal;font-style:normal;font-variant:normal;text-decoration:none=
;vertical-align:baseline"> }</span></p=
><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"=
><span style=3D"font-size:15px;font-family:Arial;color:#000000;background-c=
olor:transparent;font-weight:normal;font-style:normal;font-variant:normal;t=
ext-decoration:none;vertical-align:baseline">  =
; int &operator*() {</span></p><p dir=3D"ltr" style=3D"line-heigh=
t:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font=
-family:Arial;color:#000000;background-color:transparent;font-weight:normal=
;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:=
baseline"> return *=
ret_value;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0p=
t;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:=
#000000;background-color:transparent;font-weight:normal;font-style:normal;f=
ont-variant:normal;text-decoration:none;vertical-align:baseline"> &nb=
sp; }</span></p><p dir=3D"ltr" style=3D"line-height=
:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-=
family:Arial;color:#000000;background-color:transparent;font-weight:normal;=
font-style:normal;font-variant:normal;text-decoration:none;vertical-align:b=
aseline"> iterator(const iterator &=
;it) : n(it.n),pos(it.pos) {</span></p><p dir=3D"ltr" style=3D"line-height:=
1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-f=
amily:Arial;color:#000000;background-color:transparent;font-weight:normal;f=
ont-style:normal;font-variant:normal;text-decoration:none;vertical-align:ba=
seline">//copy only living members<br></span></p><p dir=3D"ltr" style=3D"li=
ne-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:1=
5px;font-family:Arial;color:#000000;background-color:transparent;font-weigh=
t:normal;font-style:normal;font-variant:normal;text-decoration:none;vertica=
l-align:baseline"> =
if (pos>p0 && pos<p4) {</span></p><p dir=3D"ltr" style=3D"lin=
e-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15=
px;font-family:Arial;color:#000000;background-color:transparent;font-weight=
:normal;font-style:normal;font-variant:normal;text-decoration:none;vertical=
-align:baseline"> &=
nbsp; ret_value=3Dnew int(*it.ret_value);</span></p><p dir=3D"l=
tr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline"> &nbs=
p; a=3Dnew A(*it.a);</span></p><p dir=3D"ltr=
" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline"> &nbs=
p; fib1=3Dnew int(*it.fib1);</span></p><p di=
r=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span=
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:t=
ransparent;font-weight:normal;font-style:normal;font-variant:normal;text-de=
coration:none;vertical-align:baseline"> &nbs=
p; fib2=3Dnew int(*it.fib2);</span></p=
><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"=
><span style=3D"font-size:15px;font-family:Arial;color:#000000;background-c=
olor:transparent;font-weight:normal;font-style:normal;font-variant:normal;t=
ext-decoration:none;vertical-align:baseline">  =
; even=3Dnew int(*it.even);</sp=
an></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-botto=
m:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgr=
ound-color:transparent;font-weight:normal;font-style:normal;font-variant:no=
rmal;text-decoration:none;vertical-align:baseline">  =
; }</span></p><p dir=3D"ltr" style=3D"line-h=
eight:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;=
font-family:Arial;color:#000000;background-color:transparent;font-weight:no=
rmal;font-style:normal;font-variant:normal;text-decoration:none;vertical-al=
ign:baseline"> if (=
pos>p1 && pos<p4) fib3=3Dnew int(*it.fib3);</span></p><p dir=
=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span =
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:tr=
ansparent;font-weight:normal;font-style:normal;font-variant:normal;text-dec=
oration:none;vertical-align:baseline">  =
; if (pos>p2 && pos<p4) b=3Dnew A(*it.b);</=
span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bot=
tom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;back=
ground-color:transparent;font-weight:normal;font-style:normal;font-variant:=
normal;text-decoration:none;vertical-align:baseline"> &nb=
sp; }</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin=
-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial=
;color:#000000;background-color:transparent;font-weight:normal;font-style:n=
ormal;font-variant:normal;text-decoration:none;vertical-align:baseline"> &n=
bsp; iterator(iterator &&it) : n(std:=
:move(it.n)),pos(it.pos) {</span></p><p dir=3D"ltr" style=3D"line-height:1.=
15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-fam=
ily:Arial;color:#000000;background-color:transparent;font-weight:normal;fon=
t-style:normal;font-variant:normal;text-decoration:none;vertical-align:base=
line"> if (pos>p=
0 && pos<p4) {</span></p><p dir=3D"ltr" style=3D"line-height:1.1=
5;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-fami=
ly:Arial;color:#000000;background-color:transparent;font-weight:normal;font=
-style:normal;font-variant:normal;text-decoration:none;vertical-align:basel=
ine"> =
ret_value=3Dnew int(std::move(*it.ret_value));</span></p><p dir=3D"lt=
r" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline"> &nbs=
p; a=3Dnew A(std::move(*it.a));</span></p><p=
dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><s=
pan style=3D"font-size:15px;font-family:Arial;color:#000000;background-colo=
r:transparent;font-weight:normal;font-style:normal;font-variant:normal;text=
-decoration:none;vertical-align:baseline"> &=
nbsp; fib1=3Dnew int(std::move(*it.fib=
1));</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;marg=
in-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#00000=
0;background-color:transparent;font-weight:normal;font-style:normal;font-va=
riant:normal;text-decoration:none;vertical-align:baseline"> &nb=
sp; fib2=3Dnew int(=
std::move(*it.fib2));</span></p><p dir=3D"ltr" style=3D"line-height:1.15;ma=
rgin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:A=
rial;color:#000000;background-color:transparent;font-weight:normal;font-sty=
le:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"=
> &nbs=
p;even=3Dnew int(std::move(*it.even));</span></p><p dir=3D"ltr" style=3D"li=
ne-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:1=
5px;font-family:Arial;color:#000000;background-color:transparent;font-weigh=
t:normal;font-style:normal;font-variant:normal;text-decoration:none;vertica=
l-align:baseline"> =
}</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-=
bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;b=
ackground-color:transparent;font-weight:normal;font-style:normal;font-varia=
nt:normal;text-decoration:none;vertical-align:baseline"> =
if (pos>p1 && pos<p4) f=
ib3=3Dnew int(std::move(*it.fib3));</span></p><p dir=3D"ltr" style=3D"line-=
height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px=
;font-family:Arial;color:#000000;background-color:transparent;font-weight:n=
ormal;font-style:normal;font-variant:normal;text-decoration:none;vertical-a=
lign:baseline"> if =
(pos>p2 && pos<p4) b=3Dnew A(std::move(*it.b));</span></p><p =
dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><sp=
an style=3D"font-size:15px;font-family:Arial;color:#000000;background-color=
:transparent;font-weight:normal;font-style:normal;font-variant:normal;text-=
decoration:none;vertical-align:baseline"> &n=
bsp;}</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;mar=
gin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#0000=
00;background-color:transparent;font-weight:normal;font-style:normal;font-v=
ariant:normal;text-decoration:none;vertical-align:baseline"> &n=
bsp; ~iterator() {</span></p><p dir=3D"ltr" style=3D"line=
-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15p=
x;font-family:Arial;color:#000000;background-color:transparent;font-weight:=
normal;font-style:normal;font-variant:normal;text-decoration:none;vertical-=
align:baseline"> if=
(pos>p2 && pos<p4) delete b;</span></p><p dir=3D"ltr" style=
=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-=
size:15px;font-family:Arial;color:#000000;background-color:transparent;font=
-weight:normal;font-style:normal;font-variant:normal;text-decoration:none;v=
ertical-align:baseline"> =
if (pos>p1 && pos<p4) delete fib3;</span></p><p dir=3D"=
ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span styl=
e=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transp=
arent;font-weight:normal;font-style:normal;font-variant:normal;text-decorat=
ion:none;vertical-align:baseline"> &nb=
sp; if (pos>p0 && pos<p4) {</span></p><p dir=3D"l=
tr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline"> &nbs=
p; delete even;</span></p><p dir=3D"ltr" sty=
le=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"fon=
t-size:15px;font-family:Arial;color:#000000;background-color:transparent;fo=
nt-weight:normal;font-style:normal;font-variant:normal;text-decoration:none=
;vertical-align:baseline">  =
; delete fib2;</span></p><p dir=3D"ltr" style=3D"l=
ine-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:=
15px;font-family:Arial;color:#000000;background-color:transparent;font-weig=
ht:normal;font-style:normal;font-variant:normal;text-decoration:none;vertic=
al-align:baseline">  =
; delete fib1;</span></p><p dir=3D"ltr" style=3D"line-hei=
ght:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;fo=
nt-family:Arial;color:#000000;background-color:transparent;font-weight:norm=
al;font-style:normal;font-variant:normal;text-decoration:none;vertical-alig=
n:baseline"> =
delete a;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;m=
argin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:=
Arial;color:#000000;background-color:transparent;font-weight:normal;font-st=
yle:normal;font-variant:normal;text-decoration:none;vertical-align:baseline=
"> &nb=
sp;delete ret_value;</span></p><p dir=3D"ltr" style=3D"line-height:1.15;mar=
gin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Ar=
ial;color:#000000;background-color:transparent;font-weight:normal;font-styl=
e:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">=
}</span></p><p dir=
=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span =
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:tr=
ansparent;font-weight:normal;font-style:normal;font-variant:normal;text-dec=
oration:none;vertical-align:baseline">  =
;}</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin=
-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;=
background-color:transparent;font-weight:normal;font-style:normal;font-vari=
ant:normal;text-decoration:none;vertical-align:baseline">  =
; bool operator!=3D(const iterator &it) {</span></p><=
p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><=
span style=3D"font-size:15px;font-family:Arial;color:#000000;background-col=
or:transparent;font-weight:normal;font-style:normal;font-variant:normal;tex=
t-decoration:none;vertical-align:baseline"> =
return pos!=3Dit.pos;</span></p><p dir=3D"ltr" sty=
le=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"fon=
t-size:15px;font-family:Arial;color:#000000;background-color:transparent;fo=
nt-weight:normal;font-style:normal;font-variant:normal;text-decoration:none=
;vertical-align:baseline"> }</span></p=
><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"=
><span style=3D"font-size:15px;font-family:Arial;color:#000000;background-c=
olor:transparent;font-weight:normal;font-style:normal;font-variant:normal;t=
ext-decoration:none;vertical-align:baseline">  =
; operator bool() {</span></p><p dir=3D"ltr" style=3D"line-height:1.1=
5;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-fami=
ly:Arial;color:#000000;background-color:transparent;font-weight:normal;font=
-style:normal;font-variant:normal;text-decoration:none;vertical-align:basel=
ine"> return pos<=
;p4; //still </span><span style=3D"font-size:15px;font-family:Arial;color:#=
000000;background-color:transparent;font-weight:normal;font-style:normal;fo=
nt-variant:normal;text-decoration:none;vertical-align:baseline">hasn't ende=
d<br></span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;mar=
gin-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#0000=
00;background-color:transparent;font-weight:normal;font-style:normal;font-v=
ariant:normal;text-decoration:none;vertical-align:baseline"> &n=
bsp; }</span></p><p dir=3D"ltr" style=3D"line-height:1.15=
;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-famil=
y:Arial;color:#000000;background-color:transparent;font-weight:normal;font-=
style:normal;font-variant:normal;text-decoration:none;vertical-align:baseli=
ne"> iterator &operator=3D(const i=
terator&) =3D delete;</span></p><p dir=3D"ltr" style=3D"line-height:1.1=
5;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-fami=
ly:Arial;color:#000000;background-color:transparent;font-weight:normal;font=
-style:normal;font-variant:normal;text-decoration:none;vertical-align:basel=
ine"> friend fib_even;</span></p><p di=
r=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span=
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:t=
ransparent;font-weight:normal;font-style:normal;font-variant:normal;text-de=
coration:none;vertical-align:baseline"> };</span></p><p d=
ir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><spa=
n style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:=
transparent;font-weight:normal;font-style:normal;font-variant:normal;text-d=
ecoration:none;vertical-align:baseline"> int n;</span></p=
><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"=
><span style=3D"font-size:15px;font-family:Arial;color:#000000;background-c=
olor:transparent;font-weight:normal;font-style:normal;font-variant:normal;t=
ext-decoration:none;vertical-align:baseline">public:</span></p><p dir=3D"lt=
r" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"font-size:15px;font-family:Arial;color:#000000;background-color:transpa=
rent;font-weight:normal;font-style:normal;font-variant:normal;text-decorati=
on:none;vertical-align:baseline"> fib_even(int n) : n(n) =
{}</span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin=
-bottom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;=
background-color:transparent;font-weight:normal;font-style:normal;font-vari=
ant:normal;text-decoration:none;vertical-align:baseline">  =
;iterator begin() {</span></p><p dir=3D"ltr" style=3D"line-height:1.15;marg=
in-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;font-family:Ari=
al;color:#000000;background-color:transparent;font-weight:normal;font-style=
:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"> =
return iterator(n);</span></p><p dir=
=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span =
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:tr=
ansparent;font-weight:normal;font-style:normal;font-variant:normal;text-dec=
oration:none;vertical-align:baseline"> }</span></p><p dir=
=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bottom:0pt"><span =
style=3D"font-size:15px;font-family:Arial;color:#000000;background-color:tr=
ansparent;font-weight:normal;font-style:normal;font-variant:normal;text-dec=
oration:none;vertical-align:baseline"> iterator end() {</=
span></p><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-bot=
tom:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;back=
ground-color:transparent;font-weight:normal;font-style:normal;font-variant:=
normal;text-decoration:none;vertical-align:baseline"> &nb=
sp; return iterator();</span></p><p dir=3D"ltr" style=3D"line-h=
eight:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;=
font-family:Arial;color:#000000;background-color:transparent;font-weight:no=
rmal;font-style:normal;font-variant:normal;text-decoration:none;vertical-al=
ign:baseline"> }</span></p><p dir=3D"ltr" style=3D"line-h=
eight:1.15;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:15px;=
font-family:Arial;color:#000000;background-color:transparent;font-weight:no=
rmal;font-style:normal;font-variant:normal;text-decoration:none;vertical-al=
ign:baseline">};</span></p><br><span style=3D"font-size:15px;font-family:Ar=
ial;color:#000000;background-color:transparent;font-weight:normal;font-styl=
e:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">=
</span><p dir=3D"ltr" style=3D"line-height:1.15;margin-top:0pt;margin-botto=
m:0pt"><span style=3D"font-size:15px;font-family:Arial;color:#000000;backgr=
ound-color:transparent;font-weight:normal;font-style:normal;font-variant:no=
rmal;text-decoration:none;vertical-align:baseline">So, what do you think?</=
span></p></blockquote></blockquote>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
<br />
<br />
------=_Part_482_15419926.1372343679497--
.
Author: Xeo <hivemaster@hotmail.de>
Date: Thu, 27 Jun 2013 08:01:02 -0700 (PDT)
Raw View
------=_Part_385_27539585.1372345262210
Content-Type: text/plain; charset=ISO-8859-1
On Thursday, June 27, 2013 4:34:39 PM UTC+2, asa...@gmail.com wrote:
>
> 1) *begin* and *end* are the common way to iterate over something. I'm
> agree that sometimes we just want to have *auto coro(args);coro();
> 2) You're rig*ht. I had forgotten that class template arguments are not
> being deducted - even when we just are calling the constructor
>
> If I understood you correctly, you mean to transfrom *int : fib(int n)
> {/*blablabla/*}* to *fib_class fib(int n) {return fib_class(n);}* , when *
> fib_class* is some unnamed data structure.
Yes
auto coro=fib(10);
> auto iter=fib.begin();
>
`fib` is a function. And as I said, if you want to adapt a coroutine to a
range, just use something that's generic to all kinds of functions.
++iter; //what does this mean? what is the value of *iter now?
>
`++it` should be a no-op (which is totally allowed by the standard).
--
---
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_385_27539585.1372345262210
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<br>On Thursday, June 27, 2013 4:34:39 PM UTC+2, asa...@gmail.com wrote:<bl=
ockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border=
-left: 1px #ccc solid;padding-left: 1ex;">1) <i>begin</i> and <i>end</i> ar=
e the common way to iterate over something. I'm agree that sometimes we jus=
t want to have <i>auto coro(args);coro();<br>2) You're rig</i>ht. I had for=
gotten that class template arguments are not being deducted - even when we =
just are calling the constructor<br><br>If I understood you correctly, you =
mean to transfrom <i>int : fib(int n) {/*blablabla/*}</i> to <i>fib_class f=
ib(int n) {return fib_class(n);}</i> , when <i>fib_class</i> is some unname=
d data structure. </blockquote><div> Yes<br><br></div><blockquote clas=
s=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #c=
cc solid;padding-left: 1ex;">auto coro=3Dfib(10);<br>auto iter=3Dfib.begin(=
);<br></blockquote><div>`fib` is a function. And as I said, if you want to =
adapt a coroutine to a range, just use something that's generic to all kind=
s of functions. <br><br></div><blockquote class=3D"gmail_quote" style=3D"ma=
rgin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">=
++iter; //what does this mean? what is the value of *iter now?<br></blockqu=
ote><div>`++it` should be a no-op (which is totally allowed by the standard=
). <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" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
<br />
<br />
------=_Part_385_27539585.1372345262210--
.
Author: asaelr@gmail.com
Date: Thu, 27 Jun 2013 08:17:34 -0700 (PDT)
Raw View
------=_Part_228_15293093.1372346254870
Content-Type: text/plain; charset=ISO-8859-1
>
>
> `fib` is a function. And as I said, if you want to adapt a coroutine to a
> range, just use something that's generic to all kinds of functions.
>
My mistyping. I meant to write *auto inter=coro.begin();* :)
> ++iter; //what does this mean? what is the value of *iter now?
>>
> `++it` should be a no-op (which is totally allowed by the standard).
>
Why should it be no-op? What happens if I call *++it* again?
--
---
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_228_15293093.1372346254870
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bor=
der-left: 1px #ccc solid;padding-left: 1ex;"><br><div>`fib` is a function. =
And as I said, if you want to adapt a coroutine to a range, just use someth=
ing that's generic to all kinds of functions. <br></div></blockquote><div>M=
y mistyping. I meant to write <i>auto inter=3Dcoro.begin();</i> :)<br=
></div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.=
8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div></div><blockquote =
class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #=
ccc solid;padding-left:1ex">++iter; //what does this mean? what is the valu=
e of *iter now?<br></blockquote><div>`++it` should be a no-op (which is tot=
ally allowed by the standard). <br></div></blockquote><div>Why should it be=
no-op? What happens if I call <i>++it</i> again? <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" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
<br />
<br />
------=_Part_228_15293093.1372346254870--
.
Author: Xeo <hivemaster@hotmail.de>
Date: Thu, 27 Jun 2013 09:01:26 -0700 (PDT)
Raw View
------=_Part_1829_24720311.1372348886521
Content-Type: text/plain; charset=ISO-8859-1
>
> Why should it be no-op? What happens if I call *++it* again?
>
Nothing. Why should anything happen? Currently, output iterators'
`operator++` is also no-op, since the concept of "incrementing" doesn't
make sense for them.
--
---
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_1829_24720311.1372348886521
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bor=
der-left: 1px #ccc solid;padding-left: 1ex;">Why should it be no-op? What h=
appens if I call <i>++it</i> again? <br></blockquote><div>Nothing. Why shou=
ld anything happen? Currently, output iterators' `operator++` is also no-op=
, since the concept of "incrementing" doesn't make sense for them. <br></di=
v>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
<br />
<br />
------=_Part_1829_24720311.1372348886521--
.
Author: asaelr@gmail.com
Date: Thu, 27 Jun 2013 10:04:43 -0700 (PDT)
Raw View
------=_Part_272_26375908.1372352683246
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
I think I'm starting to realize the confusing. You mean that operator*=20
should do both the increment and the access. I meant that operator* will do=
=20
the access, and operator++ will do the incrementing (you can see the=20
implementation in my first message).
Incrementing output iterators doesn't make sense, but incrementing a=20
coroutine make. (In *fib* example, it means "yield the next Fibonacci=20
number").
I think that the common concept of iterators is to separate incrementing=20
and accessing, so *for* loops (and, specially, for range loops) can=20
increment, check if we done, and only then access.
=D7=91=D7=AA=D7=90=D7=A8=D7=99=D7=9A =D7=99=D7=95=D7=9D =D7=97=D7=9E=D7=99=
=D7=A9=D7=99, 27 =D7=91=D7=99=D7=95=D7=A0=D7=99 2013 19:01:26 UTC+3, =D7=9E=
=D7=90=D7=AA Xeo:
>
> Why should it be no-op? What happens if I call *++it* again?=20
>>
> Nothing. Why should anything happen? Currently, output iterators'=20
> `operator++` is also no-op, since the concept of "incrementing" doesn't=
=20
> make sense for them.=20
>
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
------=_Part_272_26375908.1372352683246
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
I think I'm starting to realize the confusing. You mean that operator* shou=
ld do both the increment and the access. I meant that operator* will do the=
access, and operator++ will do the incrementing (you can see the implement=
ation in my first message).<br><br>Incrementing output iterators doesn't ma=
ke sense, but incrementing a coroutine make. (In <i>fib</i> example, it mea=
ns "yield the next Fibonacci number").<br>I think that the common concept o=
f iterators is to separate incrementing and accessing, so <i>for</i> loops =
(and, specially, for range loops) can increment, check if we done, and only=
then access.<br><br>=D7=91=D7=AA=D7=90=D7=A8=D7=99=D7=9A =D7=99=D7=95=D7=
=9D =D7=97=D7=9E=D7=99=D7=A9=D7=99, 27 =D7=91=D7=99=D7=95=D7=A0=D7=99 2013 =
19:01:26 UTC+3, =D7=9E=D7=90=D7=AA Xeo:<blockquote class=3D"gmail_quote" st=
yle=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-lef=
t: 1ex;"><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.=
8ex;border-left:1px #ccc solid;padding-left:1ex">Why should it be no-op? Wh=
at happens if I call <i>++it</i> again? <br></blockquote><div>Nothing. Why =
should anything happen? Currently, output iterators' `operator++` is also n=
o-op, since the concept of "incrementing" doesn't make sense for them. <br>=
</div></blockquote>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
<br />
<br />
------=_Part_272_26375908.1372352683246--
.
Author: asaelr@gmail.com
Date: Thu, 27 Jun 2013 18:10:04 -0700 (PDT)
Raw View
------=_Part_86_19872990.1372381804311
Content-Type: text/plain; charset=ISO-8859-1
Another thing - what should *operator()* return when the coroutine is done?
We can't know it's done before the internal function actually ends, so we
can't just check *isdone() *(or, maybe, *operator bool()* ) to know if we
shouldn't call *operator()*.
(One solution is to let the coroutine not to return control just when
yielding, but instead continue running until just before the next *return*statement, but I think it's kind of evil)
--
---
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_86_19872990.1372381804311
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Another thing - what should <i>operator()</i> return when the coroutine is =
done? We can't know it's done before the internal function actually ends, s=
o we can't just check <i>isdone() </i>(or, maybe, <i>operator bool()</i> ) =
to know if we shouldn't call <i>operator()</i>.<br>(One solution is to let =
the coroutine not to return control just when yielding, but instead continu=
e running until just before the next <i>return</i> statement, but I think i=
t's kind of evil)<br>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
<br />
<br />
------=_Part_86_19872990.1372381804311--
.
Author: minchul park <summerlight00@gmail.com>
Date: Sat, 29 Jun 2013 09:55:03 +0900
Raw View
--047d7b2e15d713e3d804e04072e4
Content-Type: text/plain; charset=ISO-8859-1
For the sake of clarity, it's worth to note that the second proposal is a
description of generator, rather than coroutine. They should be
distinguished.
Coroutine is not just about a simple programming pattern like
producer/consumer (which is actually external iterator) - It's more
primitive building block to support every kind of cooperative multitasking,
so it should maintain its own continuation. So if you want to call
something coroutine, it should have its own callstack(which represents
continuation in C++).
Of course, generator has its own advantage. It has much easier to use, and
maybe more efficient on its primary use cases since it's just simple
syntax-sugared state machine functor. Since iterator pattern is widely
adapted in C++ community, it deserves its own syntax. So I'm not against
about generator proposal, but still, it can't be a replacement of coroutine.
And I guess you have doubt about necessity of deep yield. Think about
simple IO scenario. Maybe the most simple pseudo code may looks like below.
void some_protocol(end_point dest) {
session s(dest);
// some processing
s.send(buffer);
s.recv(buffer); // unbounded blocking
// use received data
}
But the code has some performance issue. One recv call can blocks other
computation. It can be resolved by mapping one thread to one session , but
it has its own performance problem. So let's introduce some asynchronous
code.
end_point dest;
session s(dest); // connected and maintained by some other code - its
lifetime is not bounded to the scope.
void async_recv_handler(session& s) {
// use received data
}
void async_protocol(session& s) {
// some processing
s.send(buffer);
s.recv(recv_handler);
}
It's much more complex due to the nature of asynchronous process. Maybe CPS
with lambda can mitigates it, but it's still ugly. However, if we have
"deep yield" backed up by coroutine-based cooperative task scheduler, then
the code becomes drastically simpler.
void some_protocol(end_point dest) {
session s(dest);
s.recv(buffer); // deep yielded inside of network library
// use received data
}
The root cause of the problem is strong coupling between continuation and
thread. We want to map one continuation to one conceptual computation
context, but in C++11, thread is the only way to achieve it since they are
strongly coupled.
The fundamental solution is to decouple continuation from thread and treat
continuation as first-class object. Though it's very hard (or technically
infeasible) to implement it as a first class object in the context of C++,
but coroutine can be the practically sufficient solution which can be
applied almost every cases. The necessity of "deep yield" means this.
I also want to note that generator just maintains only its own function
frame, which is not sufficient to represent continuation in general use
case.
On Fri, Jun 28, 2013 at 10:10 AM, <asaelr@gmail.com> wrote:
> Another thing - what should *operator()* return when the coroutine is
> done? We can't know it's done before the internal function actually ends,
> so we can't just check *isdone() *(or, maybe, *operator bool()* ) to know
> if we shouldn't call *operator()*.
> (One solution is to let the coroutine not to return control just when
> yielding, but instead continue running until just before the next *return*statement, but I think it's kind of evil)
>
> --
>
> ---
> 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/.
>
>
>
--
Min-chul Park (summerlight00@gmail.com / http://summerlight.tistory.com)
--
---
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/.
--047d7b2e15d713e3d804e04072e4
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">For the sake of clarity, it's worth to note that the s=
econd proposal is a description of generator, rather than coroutine. They s=
hould be distinguished.<div><br></div><div>Coroutine is not just about a si=
mple programming pattern like producer/consumer (which is actually external=
iterator) - It's more primitive building block to support every kind o=
f cooperative multitasking, so it should maintain its own continuation. So =
if you want to call something coroutine, it should have its own callstack(w=
hich represents continuation in C++).</div>
<div><br></div><div>Of course, generator has its own advantage. It has much=
easier to use, and maybe more efficient on its primary use cases since it&=
#39;s just simple syntax-sugared state machine functor. Since iterator patt=
ern is widely adapted in C++ community, it deserves its own syntax. So I=
9;m not against about generator proposal, but still, it can't be a repl=
acement of coroutine.<br>
<div><br></div><div><br></div><div>And I guess you have doubt about necessi=
ty of deep yield. Think about simple IO scenario. Maybe the most simple pse=
udo code may looks like below.</div></div><div><br></div><div style>void so=
me_protocol(end_point dest) {</div>
<div style>=A0 session s(dest);</div><div style>=A0 // some processing</div=
><div style>=A0 s.send(buffer);</div><div style>=A0 s.recv(buffer); // unbo=
unded blocking<br></div><div style><br></div><div style>=A0 // use received=
data</div>
<div style>}</div><div style><br></div><div style>But the code has some per=
formance issue. One recv call can blocks other computation. It can be resol=
ved by mapping one thread to one session , but it has its own performance p=
roblem. So let's introduce some asynchronous code.</div>
<div style><br></div><div style>end_point dest;</div><div style>session s(d=
est); // connected and maintained by some other code - its lifetime is not =
bounded to the scope.</div><div style><br></div><div style>void async_recv_=
handler(session& s) {<br>
</div><div style>=A0 // use received data</div><div style>}</div><div style=
><br></div><div style>void async_protocol(session& s) {</div><div style=
><div>=A0 // some processing</div><div>=A0 s.send(buffer);</div></div><div =
style>
=A0 s.recv(recv_handler);</div><div style>}</div><div style><br></div><div =
style>It's much more complex due to the nature of asynchronous process.=
Maybe CPS with lambda can mitigates it, but it's still ugly. However, =
if we have "deep yield" backed up by coroutine-based cooperative =
task scheduler, then the code becomes drastically simpler.</div>
<div style><br></div><div style><div>void some_protocol(end_point dest) {</=
div><div>=A0 session s(dest);</div><div><br></div><div>=A0 s.recv(buffer); =
// deep yielded inside of network library<br></div><div><br></div><div>=A0 =
// use received data</div>
<div>}</div><div><br></div><div><br></div><div style>The root cause of the =
problem is strong coupling between continuation and thread. We want to map =
one continuation to one conceptual computation context, but in C++11, threa=
d is the only way to achieve it since they are strongly coupled.</div>
<div style><br></div><div style>The fundamental solution is to decouple con=
tinuation from thread and treat continuation as first-class object. Though =
it's very hard (or technically infeasible) to implement it as a first c=
lass object in the context of C++, but coroutine can be the practically suf=
ficient solution which can be applied almost every cases. The necessity of =
"deep yield" means this.</div>
<div style><br></div><div style>I also want to note that generator just mai=
ntains only its own function frame, which is not sufficient to represent co=
ntinuation in general use case.=A0</div></div></div><div class=3D"gmail_ext=
ra">
<br><br><div class=3D"gmail_quote">On Fri, Jun 28, 2013 at 10:10 AM, <span=
dir=3D"ltr"><<a href=3D"mailto:asaelr@gmail.com" target=3D"_blank">asae=
lr@gmail.com</a>></span> wrote:<br><blockquote class=3D"gmail_quote" sty=
le=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Another thing - what should <i>operator()</i> return when the coroutine is =
done? We can't know it's done before the internal function actually=
ends, so we can't just check <i>isdone() </i>(or, maybe, <i>operator b=
ool()</i> ) to know if we shouldn't call <i>operator()</i>.<br>
(One solution is to let the coroutine not to return control just when yield=
ing, but instead continue running until just before the next <i>return</i> =
statement, but I think it's kind of evil)<div class=3D"HOEnZb"><div cla=
ss=3D"h5">
<br>
<p></p>
-- <br>
=A0<br>
--- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org" target=3D=
"_blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
=A0<br>
=A0<br>
</div></div></blockquote></div><br><br clear=3D"all"><div><br></div>-- <br>=
<div>Min-chul Park (<a href=3D"mailto:summerlight00@gmail.com" target=3D"_b=
lank">summerlight00@gmail.com</a>=A0/ <a href=3D"http://summerlight.tistory=
..com/" target=3D"_blank">http://summerlight.tistory.com</a>)</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" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
<br />
<br />
--047d7b2e15d713e3d804e04072e4--
.
Author: minchul park <summerlight00@gmail.com>
Date: Sat, 29 Jun 2013 10:02:58 +0900
Raw View
--089e013c6a726a391c04e0408e39
Content-Type: text/plain; charset=ISO-8859-1
Oops, the last code should be fixed as below.
void some_protocol(end_point dest) {
session s(dest);
// some processing
s.send(buffer);
s.recv(buffer); // deep yielded inside of network library
// use received data
}
On Sat, Jun 29, 2013 at 9:55 AM, minchul park <summerlight00@gmail.com>wrote:
> For the sake of clarity, it's worth to note that the second proposal is a
> description of generator, rather than coroutine. They should be
> distinguished.
>
> Coroutine is not just about a simple programming pattern like
> producer/consumer (which is actually external iterator) - It's more
> primitive building block to support every kind of cooperative multitasking,
> so it should maintain its own continuation. So if you want to call
> something coroutine, it should have its own callstack(which represents
> continuation in C++).
>
> Of course, generator has its own advantage. It has much easier to use, and
> maybe more efficient on its primary use cases since it's just simple
> syntax-sugared state machine functor. Since iterator pattern is widely
> adapted in C++ community, it deserves its own syntax. So I'm not against
> about generator proposal, but still, it can't be a replacement of coroutine.
>
>
> And I guess you have doubt about necessity of deep yield. Think about
> simple IO scenario. Maybe the most simple pseudo code may looks like below.
>
> void some_protocol(end_point dest) {
> session s(dest);
> // some processing
> s.send(buffer);
> s.recv(buffer); // unbounded blocking
>
> // use received data
> }
>
> But the code has some performance issue. One recv call can blocks other
> computation. It can be resolved by mapping one thread to one session , but
> it has its own performance problem. So let's introduce some asynchronous
> code.
>
> end_point dest;
> session s(dest); // connected and maintained by some other code - its
> lifetime is not bounded to the scope.
>
> void async_recv_handler(session& s) {
> // use received data
> }
>
> void async_protocol(session& s) {
> // some processing
> s.send(buffer);
> s.recv(recv_handler);
> }
>
> It's much more complex due to the nature of asynchronous process. Maybe
> CPS with lambda can mitigates it, but it's still ugly. However, if we have
> "deep yield" backed up by coroutine-based cooperative task scheduler, then
> the code becomes drastically simpler.
>
> void some_protocol(end_point dest) {
> session s(dest);
>
> s.recv(buffer); // deep yielded inside of network library
>
> // use received data
> }
>
>
> The root cause of the problem is strong coupling between continuation and
> thread. We want to map one continuation to one conceptual computation
> context, but in C++11, thread is the only way to achieve it since they are
> strongly coupled.
>
> The fundamental solution is to decouple continuation from thread and treat
> continuation as first-class object. Though it's very hard (or technically
> infeasible) to implement it as a first class object in the context of C++,
> but coroutine can be the practically sufficient solution which can be
> applied almost every cases. The necessity of "deep yield" means this.
>
> I also want to note that generator just maintains only its own function
> frame, which is not sufficient to represent continuation in general use
> case.
>
>
> On Fri, Jun 28, 2013 at 10:10 AM, <asaelr@gmail.com> wrote:
>
>> Another thing - what should *operator()* return when the coroutine is
>> done? We can't know it's done before the internal function actually ends,
>> so we can't just check *isdone() *(or, maybe, *operator bool()* ) to
>> know if we shouldn't call *operator()*.
>> (One solution is to let the coroutine not to return control just when
>> yielding, but instead continue running until just before the next *return
>> * statement, but I think it's kind of evil)
>>
>> --
>>
>> ---
>> 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/.
>>
>>
>>
>
>
>
> --
> Min-chul Park (summerlight00@gmail.com / http://summerlight.tistory.com)
>
--
Min-chul Park (summerlight00@gmail.com / http://summerlight.tistory.com)
--
---
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/.
--089e013c6a726a391c04e0408e39
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div style=3D"font-family:arial,sans-serif;font-size:13px"=
>Oops, the last code should be fixed as below.</div><div style=3D"font-fami=
ly:arial,sans-serif;font-size:13px"><br></div><div style=3D"font-family:ari=
al,sans-serif;font-size:13px">
void some_protocol(end_point dest) {</div><div style=3D"font-family:arial,s=
ans-serif;font-size:13px">=A0 session s(dest);</div><div style=3D"font-fami=
ly:arial,sans-serif;font-size:13px"><br></div><div style=3D"font-family:ari=
al,sans-serif;font-size:13px">
<div>=A0 // some processing</div><div>=A0 s.send(buffer);</div></div><div s=
tyle=3D"font-family:arial,sans-serif;font-size:13px">=A0 s.recv(buffer); //=
deep yielded inside of network library<br></div><div style=3D"font-family:=
arial,sans-serif;font-size:13px">
<br></div><div style=3D"font-family:arial,sans-serif;font-size:13px">=A0 //=
use received data</div><div style=3D"font-family:arial,sans-serif;font-siz=
e:13px">}</div></div><div class=3D"gmail_extra"><br><br><div class=3D"gmail=
_quote">
On Sat, Jun 29, 2013 at 9:55 AM, minchul park <span dir=3D"ltr"><<a href=
=3D"mailto:summerlight00@gmail.com" target=3D"_blank">summerlight00@gmail.c=
om</a>></span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"marg=
in:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir=3D"ltr">For the sake of clarity, it's worth to note that the s=
econd proposal is a description of generator, rather than coroutine. They s=
hould be distinguished.<div><br></div><div>Coroutine is not just about a si=
mple programming pattern like producer/consumer (which is actually external=
iterator) - It's more primitive building block to support every kind o=
f cooperative multitasking, so it should maintain its own continuation. So =
if you want to call something coroutine, it should have its own callstack(w=
hich represents continuation in C++).</div>
<div><br></div><div>Of course, generator has its own advantage. It has much=
easier to use, and maybe more efficient on its primary use cases since it&=
#39;s just simple syntax-sugared state machine functor. Since iterator patt=
ern is widely adapted in C++ community, it deserves its own syntax. So I=
9;m not against about generator proposal, but still, it can't be a repl=
acement of coroutine.<br>
<div><br></div><div><br></div><div>And I guess you have doubt about necessi=
ty of deep yield. Think about simple IO scenario. Maybe the most simple pse=
udo code may looks like below.</div></div><div><br></div><div>void some_pro=
tocol(end_point dest) {</div>
<div>=A0 session s(dest);</div><div>=A0 // some processing</div><div>=A0 s.=
send(buffer);</div><div>=A0 s.recv(buffer); // unbounded blocking<br></div>=
<div><br></div><div>=A0 // use received data</div>
<div>}</div><div><br></div><div>But the code has some performance issue. On=
e recv call can blocks other computation. It can be resolved by mapping one=
thread to one session , but it has its own performance problem. So let'=
;s introduce some asynchronous code.</div>
<div><br></div><div>end_point dest;</div><div>session s(dest); // connected=
and maintained by some other code - its lifetime is not bounded to the sco=
pe.</div><div><br></div><div>void async_recv_handler(session& s) {<br>
</div><div>=A0 // use received data</div><div>}</div><div><br></div><div>vo=
id async_protocol(session& s) {</div><div><div>=A0 // some processing</=
div><div>=A0 s.send(buffer);</div></div><div>
=A0 s.recv(recv_handler);</div><div>}</div><div><br></div><div>It's muc=
h more complex due to the nature of asynchronous process. Maybe CPS with la=
mbda can mitigates it, but it's still ugly. However, if we have "d=
eep yield" backed up by coroutine-based cooperative task scheduler, th=
en the code becomes drastically simpler.</div>
<div><br></div><div><div>void some_protocol(end_point dest) {</div><div>=A0=
session s(dest);</div><div><br></div><div>=A0 s.recv(buffer); // deep yiel=
ded inside of network library<br></div><div><br></div><div>=A0 // use recei=
ved data</div>
<div>}</div><div><br></div><div><br></div><div>The root cause of the proble=
m is strong coupling between continuation and thread. We want to map one co=
ntinuation to one conceptual computation context, but in C++11, thread is t=
he only way to achieve it since they are strongly coupled.</div>
<div><br></div><div>The fundamental solution is to decouple continuation fr=
om thread and treat continuation as first-class object. Though it's ver=
y hard (or technically infeasible) to implement it as a first class object =
in the context of C++, but coroutine can be the practically sufficient solu=
tion which can be applied almost every cases. The necessity of "deep y=
ield" means this.</div>
<div><br></div><div>I also want to note that generator just maintains only =
its own function frame, which is not sufficient to represent continuation i=
n general use case.=A0</div></div></div><div class=3D"gmail_extra"><div><di=
v class=3D"h5">
<br><br><div class=3D"gmail_quote">On Fri, Jun 28, 2013 at 10:10 AM, <span=
dir=3D"ltr"><<a href=3D"mailto:asaelr@gmail.com" target=3D"_blank">asae=
lr@gmail.com</a>></span> wrote:<br><blockquote class=3D"gmail_quote" sty=
le=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Another thing - what should <i>operator()</i> return when the coroutine is =
done? We can't know it's done before the internal function actually=
ends, so we can't just check <i>isdone() </i>(or, maybe, <i>operator b=
ool()</i> ) to know if we shouldn't call <i>operator()</i>.<br>
(One solution is to let the coroutine not to return control just when yield=
ing, but instead continue running until just before the next <i>return</i> =
statement, but I think it's kind of evil)<div><div>
<br>
<p></p>
-- <br>
=A0<br>
--- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org" target=3D=
"_blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
=A0<br>
=A0<br>
</div></div></blockquote></div><br><br clear=3D"all"><div><br></div></div><=
/div><span class=3D"HOEnZb"><font color=3D"#888888">-- <br><div>Min-chul Pa=
rk (<a href=3D"mailto:summerlight00@gmail.com" target=3D"_blank">summerligh=
t00@gmail.com</a>=A0/ <a href=3D"http://summerlight.tistory.com/" target=3D=
"_blank">http://summerlight.tistory.com</a>)</div>
</font></span></div>
</blockquote></div><br><br clear=3D"all"><div><br></div>-- <br><div>Min-chu=
l Park (<a href=3D"mailto:summerlight00@gmail.com" target=3D"_blank">summer=
light00@gmail.com</a>=A0/ <a href=3D"http://summerlight.tistory.com/" targe=
t=3D"_blank">http://summerlight.tistory.com</a>)</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" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
<br />
<br />
--089e013c6a726a391c04e0408e39--
.