Topic: range-for should call for_each function if it has
Author: =?UTF-8?B?R2HFoXBlciBBxb5tYW4=?= <gasper.azman@gmail.com>
Date: Tue, 9 Oct 2018 13:07:21 +0100
Raw View
--000000000000298abb0577ca95cd
Content-Type: text/plain; charset="UTF-8"
The solution for this is already targeted by the generators of coroutines.
On Tue, Oct 9, 2018 at 1:05 PM <euloanty@live.com> wrote:
> I think it is painful and noisy to write iterators in order to support
> range-for loop.
>
> Here are my reasons:
> 1: semantics of range-for loop are not necessarily equivalent to access
> every iterator in the range.
> 2: For many containers, defining iterators are harder than defining the
> range-for loop directly.
> 3: It is painful to write iterators to support simple data structures.
> 4: For containers like std::deque, std::set, std::map and even lists,
> using iterators to traverse the entire container lose a huge amount of
> performance compared to define a universal for_each function.
>
> For example, if I have a binary search tree:
>
> template<typename T>
> class bst
> {
> };
>
>
> template<typename T,typename Callback>
> void inorder_traverse(const bstnode<T> *p,Callback &&F)
> {
> if(p->left())
> inorder_travel(p->left(),F);
> F(p->value());
> if(p->right())
> inorder_travel(p->right(),F);
> }
> template<typename T,typename Callback>
> inline void for_each(const bst<T> &t,Callback &&F)
> {
> if(t.root())
> inorder_traverse(t.root(),std::forward<Callback>(F));
> }
>
>
>
> bst<std::size_t> b;
> std::size_t sum(0);
> for(const auto &ele : b) // will check whether the "for_each" function
> is defined for the container. If it does have one, call this first.
> sum+=ele;
>
> this will be equivalent to:
>
> bst<std::size_t> b;
> std::size_t sum(0);
> for_each(b,[&](const auto &ele)
> {
> sum+=ele;
> });
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>
--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkX6m5pY7RGG%2BF2_43yq1PMUfkPWegFn5XqnGW%3DkGweG8w%40mail.gmail.com.
--000000000000298abb0577ca95cd
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">The solution for this is already targeted by the generator=
s of coroutines.</div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Tu=
e, Oct 9, 2018 at 1:05 PM <<a href=3D"mailto:euloanty@live.com">euloanty=
@live.com</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=
=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=
=3D"ltr"><div>I think it is painful and noisy to write iterators in order t=
o support range-for loop.</div><div><br></div><div>Here are my reasons:</di=
v><div>1: semantics of range-for loop are not necessarily equivalent to acc=
ess every iterator in the range.</div><div>2: For many containers, defining=
iterators are harder than defining the range-for loop directly.</div><div>=
3: It is painful to write iterators to support simple data structures.</div=
><div>4: For containers like std::deque, std::set, std::map and even lists,=
using iterators to=C2=A0traverse the entire container lose a huge amount o=
f performance compared to define a universal for_each function.</div><div><=
br></div><div>For example, if I have a binary search tree:</div><div><br></=
div><div>template<typename T></div><div>class bst</div><div>{<br></di=
v><div>};</div><div><br></div><div><br></div><div>template<typename T,ty=
pename Callback></div><div>void inorder_traverse(const bstnode<T> =
*p,Callback &&F)</div><div>{</div><div><span style=3D"white-space:p=
re-wrap"> </span>if(p->left())</div><div><span style=3D"white-space:pre-=
wrap"> </span>inorder_travel(p->left(),F);</div><div><span style=3D"whi=
te-space:pre-wrap"> </span>F(p->value());</div><div><span style=3D"white=
-space:pre-wrap"> </span>if(p->right())</div><div><span style=3D"white-s=
pace:pre-wrap"> </span>inorder_travel(p->right(),F);</div><div>}</div><=
div>template<typename T,typename Callback></div><div>inline void for_=
each(const bst<T> &t,Callback &&F)</div><div>{</div><div>=
<span style=3D"white-space:pre-wrap"> </span>if(t.root())</div><div><span s=
tyle=3D"white-space:pre-wrap"> </span>inorder_traverse(t.root(),std::forwa=
rd<Callback>(F));</div><div>}</div><div><br></div><div><br></div><div=
><br></div><div>bst<std::size_t> b;=C2=A0</div><div>std::size_t sum(0=
);<br></div><div>for(const auto &ele : b)=C2=A0 =C2=A0 // will check wh=
ether the "for_each" function is defined for the container. If it=
does have one, call this first.<br></div><div>=C2=A0 =C2=A0 sum+=3Dele;</d=
iv><div><br></div><div>this will be equivalent to:</div><div><br></div><div=
><div>bst<std::size_t> b;=C2=A0</div><div>std::size_t sum(0);<br></di=
v><div>for_each(b,[&](const auto &ele)</div></div><div>{</div><div>=
=C2=A0 =C2=A0 sum+=3Dele;<br></div><div>});</div><div><br></div></div>
<p></p>
-- <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+unsubscribe@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>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3044-=
4223-afd0-218e8ba06893%40isocpp.org</a>.<br>
</blockquote></div>
<p></p>
-- <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+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkX6m5pY7RGG%2BF2_43yq1PMUfkPW=
egFn5XqnGW%3DkGweG8w%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoote=
r">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkX6=
m5pY7RGG%2BF2_43yq1PMUfkPWegFn5XqnGW%3DkGweG8w%40mail.gmail.com</a>.<br />
--000000000000298abb0577ca95cd--
.
Author: euloanty@live.com
Date: Tue, 9 Oct 2018 05:13:09 -0700 (PDT)
Raw View
------=_Part_2021_874735688.1539087189165
Content-Type: multipart/alternative;
boundary="----=_Part_2022_474483989.1539087189165"
------=_Part_2022_474483989.1539087189165
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
But context swapping is slow.
On Tuesday, October 9, 2018 at 8:07:35 PM UTC+8, Ga=C5=A1per A=C5=BEman wro=
te:
>
> The solution for this is already targeted by the generators of coroutines=
..
>
> On Tue, Oct 9, 2018 at 1:05 PM <eulo...@live.com <javascript:>> wrote:
>
>> I think it is painful and noisy to write iterators in order to support=
=20
>> range-for loop.
>>
>> Here are my reasons:
>> 1: semantics of range-for loop are not necessarily equivalent to access=
=20
>> every iterator in the range.
>> 2: For many containers, defining iterators are harder than defining the=
=20
>> range-for loop directly.
>> 3: It is painful to write iterators to support simple data structures.
>> 4: For containers like std::deque, std::set, std::map and even lists,=20
>> using iterators to traverse the entire container lose a huge amount of=
=20
>> performance compared to define a universal for_each function.
>>
>> For example, if I have a binary search tree:
>>
>> template<typename T>
>> class bst
>> {
>> };
>>
>>
>> template<typename T,typename Callback>
>> void inorder_traverse(const bstnode<T> *p,Callback &&F)
>> {
>> if(p->left())
>> inorder_travel(p->left(),F);
>> F(p->value());
>> if(p->right())
>> inorder_travel(p->right(),F);
>> }
>> template<typename T,typename Callback>
>> inline void for_each(const bst<T> &t,Callback &&F)
>> {
>> if(t.root())
>> inorder_traverse(t.root(),std::forward<Callback>(F));
>> }
>>
>>
>>
>> bst<std::size_t> b;=20
>> std::size_t sum(0);
>> for(const auto &ele : b) // will check whether the "for_each" functio=
n=20
>> is defined for the container. If it does have one, call this first.
>> sum+=3Dele;
>>
>> this will be equivalent to:
>>
>> bst<std::size_t> b;=20
>> std::size_t sum(0);
>> for_each(b,[&](const auto &ele)
>> {
>> sum+=3Dele;
>> });
>>
>> --=20
>> You received this message because you are subscribed to the Google Group=
s=20
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n=20
>> email to std-proposal...@isocpp.org <javascript:>.
>> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
>> To view this discussion on the web visit=20
>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba3d13b-30=
44-4223-afd0-218e8ba06893%40isocpp.org=20
>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3=
044-4223-afd0-218e8ba06893%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoo=
ter>
>> .
>>
>
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%40isocpp.or=
g.
------=_Part_2022_474483989.1539087189165
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">But context swapping is slow.<br><br>On Tuesday, October 9=
, 2018 at 8:07:35 PM UTC+8, Ga=C5=A1per A=C5=BEman wrote:<blockquote class=
=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #cc=
c solid;padding-left: 1ex;"><div dir=3D"ltr">The solution for this is alrea=
dy targeted by the generators of coroutines.</div><br><div class=3D"gmail_q=
uote"><div dir=3D"ltr">On Tue, Oct 9, 2018 at 1:05 PM <<a href=3D"javasc=
ript:" target=3D"_blank" gdf-obfuscated-mailto=3D"CFxHss5aBAAJ" rel=3D"nofo=
llow" onmousedown=3D"this.href=3D'javascript:';return true;" onclic=
k=3D"this.href=3D'javascript:';return true;">eulo...@live.com</a>&g=
t; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 =
..8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>I t=
hink it is painful and noisy to write iterators in order to support range-f=
or loop.</div><div><br></div><div>Here are my reasons:</div><div>1: semanti=
cs of range-for loop are not necessarily equivalent to access every iterato=
r in the range.</div><div>2: For many containers, defining iterators are ha=
rder than defining the range-for loop directly.</div><div>3: It is painful =
to write iterators to support simple data structures.</div><div>4: For cont=
ainers like std::deque, std::set, std::map and even lists, using iterators =
to=C2=A0traverse the entire container lose a huge amount of performance com=
pared to define a universal for_each function.</div><div><br></div><div>For=
example, if I have a binary search tree:</div><div><br></div><div>template=
<typename T></div><div>class bst</div><div>{<br></div><div>};</div><d=
iv><br></div><div><br></div><div>template<typename T,typename Callback&g=
t;</div><div>void inorder_traverse(const bstnode<T> *p,Callback &=
&F)</div><div>{</div><div><span style=3D"white-space:pre-wrap"> </span>=
if(p->left())</div><div><span style=3D"white-space:pre-wrap"> </span>in=
order_travel(p->left(),F);</div><div><span style=3D"white-space:pre-wrap=
"> </span>F(p->value());</div><div><span style=3D"white-space:pre-wrap">=
</span>if(p->right())</div><div><span style=3D"white-space:pre-wrap"> =
</span>inorder_travel(p->right(),F);</div><div>}</div><div>template<t=
ypename T,typename Callback></div><div>inline void for_each(const bst<=
;T> &t,Callback &&F)</div><div>{</div><div><span style=3D"wh=
ite-space:pre-wrap"> </span>if(t.root())</div><div><span style=3D"white-spa=
ce:pre-wrap"> </span>inorder_traverse(t.root(),std:<wbr>:forward<Callba=
ck>(F));</div><div>}</div><div><br></div><div><br></div><div><br></div><=
div>bst<std::size_t> b;=C2=A0</div><div>std::size_t sum(0);<br></div>=
<div>for(const auto &ele : b)=C2=A0 =C2=A0 // will check whether the &q=
uot;for_each" function is defined for the container. If it does have o=
ne, call this first.<br></div><div>=C2=A0 =C2=A0 sum+=3Dele;</div><div><br>=
</div><div>this will be equivalent to:</div><div><br></div><div><div>bst<=
;std::size_t> b;=C2=A0</div><div>std::size_t sum(0);<br></div><div>for_e=
ach(b,[&](const auto &ele)</div></div><div>{</div><div>=C2=A0 =C2=
=A0 sum+=3Dele;<br></div><div>});</div><div><br></div></div>
<p></p>
-- <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"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
CFxHss5aBAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:&=
#39;;return true;" onclick=3D"this.href=3D'javascript:';return true=
;">std-proposal...@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"javascript:" target=3D"_bla=
nk" gdf-obfuscated-mailto=3D"CFxHss5aBAAJ" rel=3D"nofollow" onmousedown=3D"=
this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'=
;javascript:';return true;">std-pr...@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank" =
rel=3D"nofollow" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/9ba3d13b-3044-4223-<wbr>afd0-=
218e8ba06893%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3=
%40isocpp.org</a>.<br />
------=_Part_2022_474483989.1539087189165--
------=_Part_2021_874735688.1539087189165--
.
Author: =?UTF-8?B?R2HFoXBlciBBxb5tYW4=?= <gasper.azman@gmail.com>
Date: Tue, 9 Oct 2018 13:14:23 +0100
Raw View
--0000000000004a4f200577caaeb5
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
In the generator case it gets optimized away in most cases, and in others
its only the price of a (predicted) function call. No different than
calling a for_each with a synthesized lambda that you invoke on every
element.
On Tue, Oct 9, 2018 at 1:13 PM <euloanty@live.com> wrote:
> But context swapping is slow.
>
> On Tuesday, October 9, 2018 at 8:07:35 PM UTC+8, Ga=C5=A1per A=C5=BEman w=
rote:
>>
>> The solution for this is already targeted by the generators of coroutine=
s.
>>
>> On Tue, Oct 9, 2018 at 1:05 PM <eulo...@live.com> wrote:
>>
>>> I think it is painful and noisy to write iterators in order to support
>>> range-for loop.
>>>
>>> Here are my reasons:
>>> 1: semantics of range-for loop are not necessarily equivalent to access
>>> every iterator in the range.
>>> 2: For many containers, defining iterators are harder than defining the
>>> range-for loop directly.
>>> 3: It is painful to write iterators to support simple data structures.
>>> 4: For containers like std::deque, std::set, std::map and even lists,
>>> using iterators to traverse the entire container lose a huge amount of
>>> performance compared to define a universal for_each function.
>>>
>>> For example, if I have a binary search tree:
>>>
>>> template<typename T>
>>> class bst
>>> {
>>> };
>>>
>>>
>>> template<typename T,typename Callback>
>>> void inorder_traverse(const bstnode<T> *p,Callback &&F)
>>> {
>>> if(p->left())
>>> inorder_travel(p->left(),F);
>>> F(p->value());
>>> if(p->right())
>>> inorder_travel(p->right(),F);
>>> }
>>> template<typename T,typename Callback>
>>> inline void for_each(const bst<T> &t,Callback &&F)
>>> {
>>> if(t.root())
>>> inorder_traverse(t.root(),std::forward<Callback>(F));
>>> }
>>>
>>>
>>>
>>> bst<std::size_t> b;
>>> std::size_t sum(0);
>>> for(const auto &ele : b) // will check whether the "for_each"
>>> function is defined for the container. If it does have one, call this f=
irst.
>>> sum+=3Dele;
>>>
>>> this will be equivalent to:
>>>
>>> bst<std::size_t> b;
>>> std::size_t sum(0);
>>> for_each(b,[&](const auto &ele)
>>> {
>>> sum+=3Dele;
>>> });
>>>
>>> --
>>> 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-proposal...@isocpp.org.
>>> To post to this group, send email to std-pr...@isocpp.org.
>>> To view this discussion on the web visit
>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3=
044-4223-afd0-218e8ba06893%40isocpp.org
>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba3d13b-=
3044-4223-afd0-218e8ba06893%40isocpp.org?utm_medium=3Demail&utm_source=3Dfo=
oter>
>>> .
>>>
>> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/88165d50-83b=
4-4067-bec3-7c7dab15dce3%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/88165d50-83=
b4-4067-bec3-7c7dab15dce3%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoot=
er>
> .
>
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/CAANG%3DkXGovwTb7i%3Dm5q2KQQu1qmsYddW4B-%3DSe5xH=
u%3Dur%2B%3Df7w%40mail.gmail.com.
--0000000000004a4f200577caaeb5
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">In the generator case it gets optimized away in most cases=
, and in others its only the price of a (predicted) function call. No diffe=
rent than calling a for_each with a synthesized lambda that you invoke on e=
very element.</div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue, =
Oct 9, 2018 at 1:13 PM <<a href=3D"mailto:euloanty@live.com">euloanty@li=
ve.com</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"m=
argin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"l=
tr">But context swapping is slow.<br><br>On Tuesday, October 9, 2018 at 8:0=
7:35 PM UTC+8, Ga=C5=A1per A=C5=BEman wrote:<blockquote class=3D"gmail_quot=
e" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-l=
eft:1ex"><div dir=3D"ltr">The solution for this is already targeted by the =
generators of coroutines.</div><br><div class=3D"gmail_quote"><div dir=3D"l=
tr">On Tue, Oct 9, 2018 at 1:05 PM <<a rel=3D"nofollow">eulo...@live.com=
</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:=
0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><d=
iv>I think it is painful and noisy to write iterators in order to support r=
ange-for loop.</div><div><br></div><div>Here are my reasons:</div><div>1: s=
emantics of range-for loop are not necessarily equivalent to access every i=
terator in the range.</div><div>2: For many containers, defining iterators =
are harder than defining the range-for loop directly.</div><div>3: It is pa=
inful to write iterators to support simple data structures.</div><div>4: Fo=
r containers like std::deque, std::set, std::map and even lists, using iter=
ators to=C2=A0traverse the entire container lose a huge amount of performan=
ce compared to define a universal for_each function.</div><div><br></div><d=
iv>For example, if I have a binary search tree:</div><div><br></div><div>te=
mplate<typename T></div><div>class bst</div><div>{<br></div><div>};</=
div><div><br></div><div><br></div><div>template<typename T,typename Call=
back></div><div>void inorder_traverse(const bstnode<T> *p,Callback=
&&F)</div><div>{</div><div><span style=3D"white-space:pre-wrap"> <=
/span>if(p->left())</div><div><span style=3D"white-space:pre-wrap"> </s=
pan>inorder_travel(p->left(),F);</div><div><span style=3D"white-space:pr=
e-wrap"> </span>F(p->value());</div><div><span style=3D"white-space:pre-=
wrap"> </span>if(p->right())</div><div><span style=3D"white-space:pre-wr=
ap"> </span>inorder_travel(p->right(),F);</div><div>}</div><div>templat=
e<typename T,typename Callback></div><div>inline void for_each(const =
bst<T> &t,Callback &&F)</div><div>{</div><div><span style=
=3D"white-space:pre-wrap"> </span>if(t.root())</div><div><span style=3D"whi=
te-space:pre-wrap"> </span>inorder_traverse(t.root(),std::forward<Callb=
ack>(F));</div><div>}</div><div><br></div><div><br></div><div><br></div>=
<div>bst<std::size_t> b;=C2=A0</div><div>std::size_t sum(0);<br></div=
><div>for(const auto &ele : b)=C2=A0 =C2=A0 // will check whether the &=
quot;for_each" function is defined for the container. If it does have =
one, call this first.<br></div><div>=C2=A0 =C2=A0 sum+=3Dele;</div><div><br=
></div><div>this will be equivalent to:</div><div><br></div><div><div>bst&l=
t;std::size_t> b;=C2=A0</div><div>std::size_t sum(0);<br></div><div>for_=
each(b,[&](const auto &ele)</div></div><div>{</div><div>=C2=A0 =C2=
=A0 sum+=3Dele;<br></div><div>});</div><div><br></div></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank">https://groups.google.com/a/isocpp.org/d/msgid/std-proposa=
ls/9ba3d13b-3044-4223-afd0-218e8ba06893%40isocpp.org</a>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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+unsubscribe@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>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/88165d50-83b4-=
4067-bec3-7c7dab15dce3%40isocpp.org</a>.<br>
</blockquote></div>
<p></p>
-- <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+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkXGovwTb7i%3Dm5q2KQQu1qmsYddW=
4B-%3DSe5xHu%3Dur%2B%3Df7w%40mail.gmail.com?utm_medium=3Demail&utm_source=
=3Dfooter">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAA=
NG%3DkXGovwTb7i%3Dm5q2KQQu1qmsYddW4B-%3DSe5xHu%3Dur%2B%3Df7w%40mail.gmail.c=
om</a>.<br />
--0000000000004a4f200577caaeb5--
.
Author: euloanty@live.com
Date: Tue, 9 Oct 2018 05:20:47 -0700 (PDT)
Raw View
------=_Part_2089_1184629862.1539087647411
Content-Type: multipart/alternative;
boundary="----=_Part_2090_826802483.1539087647411"
------=_Part_2090_826802483.1539087647411
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Even so, the std containers do not define a standard interface for this.=20
Also, range-for loop won't use coroutine to call your function as well. A=
=20
standard interface must be defined before this being achieved.
On Tuesday, October 9, 2018 at 8:14:36 PM UTC+8, Ga=C5=A1per A=C5=BEman wro=
te:
>
> In the generator case it gets optimized away in most cases, and in others=
=20
> its only the price of a (predicted) function call. No different than=20
> calling a for_each with a synthesized lambda that you invoke on every=20
> element.
>
> On Tue, Oct 9, 2018 at 1:13 PM <eulo...@live.com <javascript:>> wrote:
>
>> But context swapping is slow.
>>
>> On Tuesday, October 9, 2018 at 8:07:35 PM UTC+8, Ga=C5=A1per A=C5=BEman =
wrote:
>>>
>>> The solution for this is already targeted by the generators of=20
>>> coroutines.
>>>
>>> On Tue, Oct 9, 2018 at 1:05 PM <eulo...@live.com> wrote:
>>>
>>>> I think it is painful and noisy to write iterators in order to support=
=20
>>>> range-for loop.
>>>>
>>>> Here are my reasons:
>>>> 1: semantics of range-for loop are not necessarily equivalent to acces=
s=20
>>>> every iterator in the range.
>>>> 2: For many containers, defining iterators are harder than defining th=
e=20
>>>> range-for loop directly.
>>>> 3: It is painful to write iterators to support simple data structures.
>>>> 4: For containers like std::deque, std::set, std::map and even lists,=
=20
>>>> using iterators to traverse the entire container lose a huge amount of=
=20
>>>> performance compared to define a universal for_each function.
>>>>
>>>> For example, if I have a binary search tree:
>>>>
>>>> template<typename T>
>>>> class bst
>>>> {
>>>> };
>>>>
>>>>
>>>> template<typename T,typename Callback>
>>>> void inorder_traverse(const bstnode<T> *p,Callback &&F)
>>>> {
>>>> if(p->left())
>>>> inorder_travel(p->left(),F);
>>>> F(p->value());
>>>> if(p->right())
>>>> inorder_travel(p->right(),F);
>>>> }
>>>> template<typename T,typename Callback>
>>>> inline void for_each(const bst<T> &t,Callback &&F)
>>>> {
>>>> if(t.root())
>>>> inorder_traverse(t.root(),std::forward<Callback>(F));
>>>> }
>>>>
>>>>
>>>>
>>>> bst<std::size_t> b;=20
>>>> std::size_t sum(0);
>>>> for(const auto &ele : b) // will check whether the "for_each"=20
>>>> function is defined for the container. If it does have one, call this =
first.
>>>> sum+=3Dele;
>>>>
>>>> this will be equivalent to:
>>>>
>>>> bst<std::size_t> b;=20
>>>> std::size_t sum(0);
>>>> for_each(b,[&](const auto &ele)
>>>> {
>>>> sum+=3Dele;
>>>> });
>>>>
>>>> --=20
>>>> You received this message because you are subscribed to the Google=20
>>>> Groups "ISO C++ Standard - Future Proposals" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send=
=20
>>>> an email to std-proposal...@isocpp.org.
>>>> To post to this group, send email to std-pr...@isocpp.org.
>>>> To view this discussion on the web visit=20
>>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba3d13b-=
3044-4223-afd0-218e8ba06893%40isocpp.org=20
>>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba3d13b=
-3044-4223-afd0-218e8ba06893%40isocpp.org?utm_medium=3Demail&utm_source=3Df=
ooter>
>>>> .
>>>>
>>> --=20
>> You received this message because you are subscribed to the Google Group=
s=20
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n=20
>> email to std-proposal...@isocpp.org <javascript:>.
>> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
>> To view this discussion on the web visit=20
>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/88165d50-83=
b4-4067-bec3-7c7dab15dce3%40isocpp.org=20
>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/88165d50-8=
3b4-4067-bec3-7c7dab15dce3%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoo=
ter>
>> .
>>
>
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/2e6d2e89-434f-4f5b-a20b-4bc5c794ac8d%40isocpp.or=
g.
------=_Part_2090_826802483.1539087647411
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Even so, the std containers do not define a standard inter=
face for this. Also, range-for loop won't use coroutine to call your fu=
nction as well. A standard interface must be defined before this being achi=
eved.<br><br>On Tuesday, October 9, 2018 at 8:14:36 PM UTC+8, Ga=C5=A1per A=
=C5=BEman wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin=
-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"lt=
r">In the generator case it gets optimized away in most cases, and in other=
s its only the price of a (predicted) function call. No different than call=
ing a for_each with a synthesized lambda that you invoke on every element.<=
/div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue, Oct 9, 2018 at=
1:13 PM <<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailt=
o=3D"CEGG3TBbBAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascr=
ipt:';return true;" onclick=3D"this.href=3D'javascript:';return=
true;">eulo...@live.com</a>> wrote:<br></div><blockquote class=3D"gmail=
_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:=
1ex"><div dir=3D"ltr">But context swapping is slow.<br><br>On Tuesday, Octo=
ber 9, 2018 at 8:07:35 PM UTC+8, Ga=C5=A1per A=C5=BEman wrote:<blockquote c=
lass=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #c=
cc solid;padding-left:1ex"><div dir=3D"ltr">The solution for this is alread=
y targeted by the generators of coroutines.</div><br><div class=3D"gmail_qu=
ote"><div dir=3D"ltr">On Tue, Oct 9, 2018 at 1:05 PM <<a rel=3D"nofollow=
">eulo...@live.com</a>> wrote:<br></div><blockquote class=3D"gmail_quote=
" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><=
div dir=3D"ltr"><div>I think it is painful and noisy to write iterators in =
order to support range-for loop.</div><div><br></div><div>Here are my reaso=
ns:</div><div>1: semantics of range-for loop are not necessarily equivalent=
to access every iterator in the range.</div><div>2: For many containers, d=
efining iterators are harder than defining the range-for loop directly.</di=
v><div>3: It is painful to write iterators to support simple data structure=
s.</div><div>4: For containers like std::deque, std::set, std::map and even=
lists, using iterators to=C2=A0traverse the entire container lose a huge a=
mount of performance compared to define a universal for_each function.</div=
><div><br></div><div>For example, if I have a binary search tree:</div><div=
><br></div><div>template<typename T></div><div>class bst</div><div>{<=
br></div><div>};</div><div><br></div><div><br></div><div>template<typena=
me T,typename Callback></div><div>void inorder_traverse(const bstnode<=
;T> *p,Callback &&F)</div><div>{</div><div><span style=3D"white-=
space:pre-wrap"> </span>if(p->left())</div><div><span style=3D"white-spa=
ce:pre-wrap"> </span>inorder_travel(p->left(),F);</div><div><span style=
=3D"white-space:pre-wrap"> </span>F(p->value());</div><div><span style=
=3D"white-space:pre-wrap"> </span>if(p->right())</div><div><span style=
=3D"white-space:pre-wrap"> </span>inorder_travel(p->right(),F);</div><d=
iv>}</div><div>template<typename T,typename Callback></div><div>inlin=
e void for_each(const bst<T> &t,Callback &&F)</div><div>{=
</div><div><span style=3D"white-space:pre-wrap"> </span>if(t.root())</div><=
div><span style=3D"white-space:pre-wrap"> </span>inorder_traverse(t.root()=
,std:<wbr>:forward<Callback>(F));</div><div>}</div><div><br></div><di=
v><br></div><div><br></div><div>bst<std::size_t> b;=C2=A0</div><div>s=
td::size_t sum(0);<br></div><div>for(const auto &ele : b)=C2=A0 =C2=A0 =
// will check whether the "for_each" function is defined for the =
container. If it does have one, call this first.<br></div><div>=C2=A0 =C2=
=A0 sum+=3Dele;</div><div><br></div><div>this will be equivalent to:</div><=
div><br></div><div><div>bst<std::size_t> b;=C2=A0</div><div>std::size=
_t sum(0);<br></div><div>for_each(b,[&](const auto &ele)</div></div=
><div>{</div><div>=C2=A0 =C2=A0 sum+=3Dele;<br></div><div>});</div><div><br=
></div></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/9ba3d13b-3044-4223-<wbr>afd0-=
218e8ba06893%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
CEGG3TBbBAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:&=
#39;;return true;" onclick=3D"this.href=3D'javascript:';return true=
;">std-proposal...@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"javascript:" target=3D"_bla=
nk" gdf-obfuscated-mailto=3D"CEGG3TBbBAAJ" rel=3D"nofollow" onmousedown=3D"=
this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'=
;javascript:';return true;">std-pr...@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank" =
rel=3D"nofollow" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/88165d50-83b4-4067-<wbr>bec3-=
7c7dab15dce3%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/2e6d2e89-434f-4f5b-a20b-4bc5c794ac8d%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/2e6d2e89-434f-4f5b-a20b-4bc5c794ac8d=
%40isocpp.org</a>.<br />
------=_Part_2090_826802483.1539087647411--
------=_Part_2089_1184629862.1539087647411--
.
Author: euloanty@live.com
Date: Tue, 9 Oct 2018 05:23:41 -0700 (PDT)
Raw View
------=_Part_2034_15827166.1539087821936
Content-Type: multipart/alternative;
boundary="----=_Part_2035_1910574866.1539087821937"
------=_Part_2035_1910574866.1539087821937
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
also, std::for_each is a function already defined in the standard library,=
=20
calling this won't add anything compared to add coroutine.
On Tuesday, October 9, 2018 at 8:14:36 PM UTC+8, Ga=C5=A1per A=C5=BEman wro=
te:
>
> In the generator case it gets optimized away in most cases, and in others=
=20
> its only the price of a (predicted) function call. No different than=20
> calling a for_each with a synthesized lambda that you invoke on every=20
> element.
>
> On Tue, Oct 9, 2018 at 1:13 PM <eulo...@live.com <javascript:>> wrote:
>
>> But context swapping is slow.
>>
>> On Tuesday, October 9, 2018 at 8:07:35 PM UTC+8, Ga=C5=A1per A=C5=BEman =
wrote:
>>>
>>> The solution for this is already targeted by the generators of=20
>>> coroutines.
>>>
>>> On Tue, Oct 9, 2018 at 1:05 PM <eulo...@live.com> wrote:
>>>
>>>> I think it is painful and noisy to write iterators in order to support=
=20
>>>> range-for loop.
>>>>
>>>> Here are my reasons:
>>>> 1: semantics of range-for loop are not necessarily equivalent to acces=
s=20
>>>> every iterator in the range.
>>>> 2: For many containers, defining iterators are harder than defining th=
e=20
>>>> range-for loop directly.
>>>> 3: It is painful to write iterators to support simple data structures.
>>>> 4: For containers like std::deque, std::set, std::map and even lists,=
=20
>>>> using iterators to traverse the entire container lose a huge amount of=
=20
>>>> performance compared to define a universal for_each function.
>>>>
>>>> For example, if I have a binary search tree:
>>>>
>>>> template<typename T>
>>>> class bst
>>>> {
>>>> };
>>>>
>>>>
>>>> template<typename T,typename Callback>
>>>> void inorder_traverse(const bstnode<T> *p,Callback &&F)
>>>> {
>>>> if(p->left())
>>>> inorder_travel(p->left(),F);
>>>> F(p->value());
>>>> if(p->right())
>>>> inorder_travel(p->right(),F);
>>>> }
>>>> template<typename T,typename Callback>
>>>> inline void for_each(const bst<T> &t,Callback &&F)
>>>> {
>>>> if(t.root())
>>>> inorder_traverse(t.root(),std::forward<Callback>(F));
>>>> }
>>>>
>>>>
>>>>
>>>> bst<std::size_t> b;=20
>>>> std::size_t sum(0);
>>>> for(const auto &ele : b) // will check whether the "for_each"=20
>>>> function is defined for the container. If it does have one, call this =
first.
>>>> sum+=3Dele;
>>>>
>>>> this will be equivalent to:
>>>>
>>>> bst<std::size_t> b;=20
>>>> std::size_t sum(0);
>>>> for_each(b,[&](const auto &ele)
>>>> {
>>>> sum+=3Dele;
>>>> });
>>>>
>>>> --=20
>>>> You received this message because you are subscribed to the Google=20
>>>> Groups "ISO C++ Standard - Future Proposals" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send=
=20
>>>> an email to std-proposal...@isocpp.org.
>>>> To post to this group, send email to std-pr...@isocpp.org.
>>>> To view this discussion on the web visit=20
>>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba3d13b-=
3044-4223-afd0-218e8ba06893%40isocpp.org=20
>>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba3d13b=
-3044-4223-afd0-218e8ba06893%40isocpp.org?utm_medium=3Demail&utm_source=3Df=
ooter>
>>>> .
>>>>
>>> --=20
>> You received this message because you are subscribed to the Google Group=
s=20
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n=20
>> email to std-proposal...@isocpp.org <javascript:>.
>> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
>> To view this discussion on the web visit=20
>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/88165d50-83=
b4-4067-bec3-7c7dab15dce3%40isocpp.org=20
>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/88165d50-8=
3b4-4067-bec3-7c7dab15dce3%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoo=
ter>
>> .
>>
>
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/7b76fd5e-f3c3-4952-af81-3435456f48b7%40isocpp.or=
g.
------=_Part_2035_1910574866.1539087821937
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">also, std::for_each is a function already defined in the s=
tandard library, calling this won't add anything compared to add corout=
ine.<br><br>On Tuesday, October 9, 2018 at 8:14:36 PM UTC+8, Ga=C5=A1per A=
=C5=BEman wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin=
-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"lt=
r">In the generator case it gets optimized away in most cases, and in other=
s its only the price of a (predicted) function call. No different than call=
ing a for_each with a synthesized lambda that you invoke on every element.<=
/div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue, Oct 9, 2018 at=
1:13 PM <<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailt=
o=3D"CEGG3TBbBAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascr=
ipt:';return true;" onclick=3D"this.href=3D'javascript:';return=
true;">eulo...@live.com</a>> wrote:<br></div><blockquote class=3D"gmail=
_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:=
1ex"><div dir=3D"ltr">But context swapping is slow.<br><br>On Tuesday, Octo=
ber 9, 2018 at 8:07:35 PM UTC+8, Ga=C5=A1per A=C5=BEman wrote:<blockquote c=
lass=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #c=
cc solid;padding-left:1ex"><div dir=3D"ltr">The solution for this is alread=
y targeted by the generators of coroutines.</div><br><div class=3D"gmail_qu=
ote"><div dir=3D"ltr">On Tue, Oct 9, 2018 at 1:05 PM <<a rel=3D"nofollow=
">eulo...@live.com</a>> wrote:<br></div><blockquote class=3D"gmail_quote=
" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><=
div dir=3D"ltr"><div>I think it is painful and noisy to write iterators in =
order to support range-for loop.</div><div><br></div><div>Here are my reaso=
ns:</div><div>1: semantics of range-for loop are not necessarily equivalent=
to access every iterator in the range.</div><div>2: For many containers, d=
efining iterators are harder than defining the range-for loop directly.</di=
v><div>3: It is painful to write iterators to support simple data structure=
s.</div><div>4: For containers like std::deque, std::set, std::map and even=
lists, using iterators to=C2=A0traverse the entire container lose a huge a=
mount of performance compared to define a universal for_each function.</div=
><div><br></div><div>For example, if I have a binary search tree:</div><div=
><br></div><div>template<typename T></div><div>class bst</div><div>{<=
br></div><div>};</div><div><br></div><div><br></div><div>template<typena=
me T,typename Callback></div><div>void inorder_traverse(const bstnode<=
;T> *p,Callback &&F)</div><div>{</div><div><span style=3D"white-=
space:pre-wrap"> </span>if(p->left())</div><div><span style=3D"white-spa=
ce:pre-wrap"> </span>inorder_travel(p->left(),F);</div><div><span style=
=3D"white-space:pre-wrap"> </span>F(p->value());</div><div><span style=
=3D"white-space:pre-wrap"> </span>if(p->right())</div><div><span style=
=3D"white-space:pre-wrap"> </span>inorder_travel(p->right(),F);</div><d=
iv>}</div><div>template<typename T,typename Callback></div><div>inlin=
e void for_each(const bst<T> &t,Callback &&F)</div><div>{=
</div><div><span style=3D"white-space:pre-wrap"> </span>if(t.root())</div><=
div><span style=3D"white-space:pre-wrap"> </span>inorder_traverse(t.root()=
,std:<wbr>:forward<Callback>(F));</div><div>}</div><div><br></div><di=
v><br></div><div><br></div><div>bst<std::size_t> b;=C2=A0</div><div>s=
td::size_t sum(0);<br></div><div>for(const auto &ele : b)=C2=A0 =C2=A0 =
// will check whether the "for_each" function is defined for the =
container. If it does have one, call this first.<br></div><div>=C2=A0 =C2=
=A0 sum+=3Dele;</div><div><br></div><div>this will be equivalent to:</div><=
div><br></div><div><div>bst<std::size_t> b;=C2=A0</div><div>std::size=
_t sum(0);<br></div><div>for_each(b,[&](const auto &ele)</div></div=
><div>{</div><div>=C2=A0 =C2=A0 sum+=3Dele;<br></div><div>});</div><div><br=
></div></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/9ba3d13b-3044-4223-<wbr>afd0-=
218e8ba06893%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
CEGG3TBbBAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:&=
#39;;return true;" onclick=3D"this.href=3D'javascript:';return true=
;">std-proposal...@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"javascript:" target=3D"_bla=
nk" gdf-obfuscated-mailto=3D"CEGG3TBbBAAJ" rel=3D"nofollow" onmousedown=3D"=
this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'=
;javascript:';return true;">std-pr...@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank" =
rel=3D"nofollow" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/88165d50-83b4-4067-<wbr>bec3-=
7c7dab15dce3%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/7b76fd5e-f3c3-4952-af81-3435456f48b7%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/7b76fd5e-f3c3-4952-af81-3435456f48b7=
%40isocpp.org</a>.<br />
------=_Part_2035_1910574866.1539087821937--
------=_Part_2034_15827166.1539087821936--
.
Author: =?UTF-8?B?R2HFoXBlciBBxb5tYW4=?= <gasper.azman@gmail.com>
Date: Tue, 9 Oct 2018 13:28:24 +0100
Raw View
--00000000000071ee0c0577cae05b
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Adding customization points to the language is a "you better have a really
really good reason" kind of thing. If another feature already provides a
way to hook into already existing features without an additional
customization point, you'd expect the standard to avoid adding
customization points.
In this case, it's easy to see how
for (auto range =3D x.in_order_traversal(); auto& element : range) {
element +=3D 1;
}
does its job just fine, without an extra customization point.
On Tue, Oct 9, 2018 at 1:23 PM <euloanty@live.com> wrote:
> also, std::for_each is a function already defined in the standard library=
,
> calling this won't add anything compared to add coroutine.
>
> On Tuesday, October 9, 2018 at 8:14:36 PM UTC+8, Ga=C5=A1per A=C5=BEman w=
rote:
>>
>> In the generator case it gets optimized away in most cases, and in other=
s
>> its only the price of a (predicted) function call. No different than
>> calling a for_each with a synthesized lambda that you invoke on every
>> element.
>>
>> On Tue, Oct 9, 2018 at 1:13 PM <eulo...@live.com> wrote:
>>
>>> But context swapping is slow.
>>>
>>> On Tuesday, October 9, 2018 at 8:07:35 PM UTC+8, Ga=C5=A1per A=C5=BEman=
wrote:
>>>>
>>>> The solution for this is already targeted by the generators of
>>>> coroutines.
>>>>
>>>> On Tue, Oct 9, 2018 at 1:05 PM <eulo...@live.com> wrote:
>>>>
>>>>> I think it is painful and noisy to write iterators in order to suppor=
t
>>>>> range-for loop.
>>>>>
>>>>> Here are my reasons:
>>>>> 1: semantics of range-for loop are not necessarily equivalent to
>>>>> access every iterator in the range.
>>>>> 2: For many containers, defining iterators are harder than defining
>>>>> the range-for loop directly.
>>>>> 3: It is painful to write iterators to support simple data structures=
..
>>>>> 4: For containers like std::deque, std::set, std::map and even lists,
>>>>> using iterators to traverse the entire container lose a huge amount o=
f
>>>>> performance compared to define a universal for_each function.
>>>>>
>>>>> For example, if I have a binary search tree:
>>>>>
>>>>> template<typename T>
>>>>> class bst
>>>>> {
>>>>> };
>>>>>
>>>>>
>>>>> template<typename T,typename Callback>
>>>>> void inorder_traverse(const bstnode<T> *p,Callback &&F)
>>>>> {
>>>>> if(p->left())
>>>>> inorder_travel(p->left(),F);
>>>>> F(p->value());
>>>>> if(p->right())
>>>>> inorder_travel(p->right(),F);
>>>>> }
>>>>> template<typename T,typename Callback>
>>>>> inline void for_each(const bst<T> &t,Callback &&F)
>>>>> {
>>>>> if(t.root())
>>>>> inorder_traverse(t.root(),std::forward<Callback>(F));
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> bst<std::size_t> b;
>>>>> std::size_t sum(0);
>>>>> for(const auto &ele : b) // will check whether the "for_each"
>>>>> function is defined for the container. If it does have one, call this=
first.
>>>>> sum+=3Dele;
>>>>>
>>>>> this will be equivalent to:
>>>>>
>>>>> bst<std::size_t> b;
>>>>> std::size_t sum(0);
>>>>> for_each(b,[&](const auto &ele)
>>>>> {
>>>>> sum+=3Dele;
>>>>> });
>>>>>
>>>>> --
>>>>> 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, sen=
d
>>>>> an email to std-proposal...@isocpp.org.
>>>>> To post to this group, send email to std-pr...@isocpp.org.
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba3d13b=
-3044-4223-afd0-218e8ba06893%40isocpp.org
>>>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba3d13=
b-3044-4223-afd0-218e8ba06893%40isocpp.org?utm_medium=3Demail&utm_source=3D=
footer>
>>>>> .
>>>>>
>>>> --
>>> 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-proposal...@isocpp.org.
>>> To post to this group, send email to std-pr...@isocpp.org.
>>> To view this discussion on the web visit
>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/88165d50-8=
3b4-4067-bec3-7c7dab15dce3%40isocpp.org
>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/88165d50-=
83b4-4067-bec3-7c7dab15dce3%40isocpp.org?utm_medium=3Demail&utm_source=3Dfo=
oter>
>>> .
>>>
>> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/7b76fd5e-f3c=
3-4952-af81-3435456f48b7%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/7b76fd5e-f3=
c3-4952-af81-3435456f48b7%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoot=
er>
> .
>
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/CAANG%3DkUEVjAi4T8BhzhHAQXSJTU%2BceR5Lb8_iTZwhda=
dJU3JvQ%40mail.gmail.com.
--00000000000071ee0c0577cae05b
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Adding customization points to the language is a "you=
better have a really really good reason" kind of thing. If another fe=
ature already provides a way to hook into already existing features without=
an additional customization point, you'd expect the standard to avoid =
adding customization points.<div><br></div><div>In this case, it's easy=
to see how</div><div><br></div><div>for (auto range =3D x.in_order_travers=
al(); auto& element : range) {</div><div>=C2=A0 =C2=A0element=C2=A0+=3D=
1;</div><div>}</div><div><br></div><div>does its job just fine, without an=
extra customization point.</div><div><br></div><div><br></div></div><br><d=
iv class=3D"gmail_quote"><div dir=3D"ltr">On Tue, Oct 9, 2018 at 1:23 PM &l=
t;<a href=3D"mailto:euloanty@live.com">euloanty@live.com</a>> wrote:<br>=
</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-l=
eft:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">also, std::for_each i=
s a function already defined in the standard library, calling this won'=
t add anything compared to add coroutine.<br><br>On Tuesday, October 9, 201=
8 at 8:14:36 PM UTC+8, Ga=C5=A1per A=C5=BEman wrote:<blockquote class=3D"gm=
ail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;p=
adding-left:1ex"><div dir=3D"ltr">In the generator case it gets optimized a=
way in most cases, and in others its only the price of a (predicted) functi=
on call. No different than calling a for_each with a synthesized lambda tha=
t you invoke on every element.</div><br><div class=3D"gmail_quote"><div dir=
=3D"ltr">On Tue, Oct 9, 2018 at 1:13 PM <<a rel=3D"nofollow">eulo...@liv=
e.com</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"ma=
rgin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"lt=
r">But context swapping is slow.<br><br>On Tuesday, October 9, 2018 at 8:07=
:35 PM UTC+8, Ga=C5=A1per A=C5=BEman wrote:<blockquote class=3D"gmail_quote=
" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-le=
ft:1ex"><div dir=3D"ltr">The solution for this is already targeted by the g=
enerators of coroutines.</div><br><div class=3D"gmail_quote"><div dir=3D"lt=
r">On Tue, Oct 9, 2018 at 1:05 PM <<a rel=3D"nofollow">eulo...@live.com<=
/a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0=
0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><di=
v>I think it is painful and noisy to write iterators in order to support ra=
nge-for loop.</div><div><br></div><div>Here are my reasons:</div><div>1: se=
mantics of range-for loop are not necessarily equivalent to access every it=
erator in the range.</div><div>2: For many containers, defining iterators a=
re harder than defining the range-for loop directly.</div><div>3: It is pai=
nful to write iterators to support simple data structures.</div><div>4: For=
containers like std::deque, std::set, std::map and even lists, using itera=
tors to=C2=A0traverse the entire container lose a huge amount of performanc=
e compared to define a universal for_each function.</div><div><br></div><di=
v>For example, if I have a binary search tree:</div><div><br></div><div>tem=
plate<typename T></div><div>class bst</div><div>{<br></div><div>};</d=
iv><div><br></div><div><br></div><div>template<typename T,typename Callb=
ack></div><div>void inorder_traverse(const bstnode<T> *p,Callback =
&&F)</div><div>{</div><div><span style=3D"white-space:pre-wrap"> </=
span>if(p->left())</div><div><span style=3D"white-space:pre-wrap"> </sp=
an>inorder_travel(p->left(),F);</div><div><span style=3D"white-space:pre=
-wrap"> </span>F(p->value());</div><div><span style=3D"white-space:pre-w=
rap"> </span>if(p->right())</div><div><span style=3D"white-space:pre-wra=
p"> </span>inorder_travel(p->right(),F);</div><div>}</div><div>template=
<typename T,typename Callback></div><div>inline void for_each(const b=
st<T> &t,Callback &&F)</div><div>{</div><div><span style=
=3D"white-space:pre-wrap"> </span>if(t.root())</div><div><span style=3D"whi=
te-space:pre-wrap"> </span>inorder_traverse(t.root(),std::forward<Callb=
ack>(F));</div><div>}</div><div><br></div><div><br></div><div><br></div>=
<div>bst<std::size_t> b;=C2=A0</div><div>std::size_t sum(0);<br></div=
><div>for(const auto &ele : b)=C2=A0 =C2=A0 // will check whether the &=
quot;for_each" function is defined for the container. If it does have =
one, call this first.<br></div><div>=C2=A0 =C2=A0 sum+=3Dele;</div><div><br=
></div><div>this will be equivalent to:</div><div><br></div><div><div>bst&l=
t;std::size_t> b;=C2=A0</div><div>std::size_t sum(0);<br></div><div>for_=
each(b,[&](const auto &ele)</div></div><div>{</div><div>=C2=A0 =C2=
=A0 sum+=3Dele;<br></div><div>});</div><div><br></div></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank">https://groups.google.com/a/isocpp.org/d/msgid/std-proposa=
ls/9ba3d13b-3044-4223-afd0-218e8ba06893%40isocpp.org</a>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank">https://groups.google.com/a/isocpp.org/d/msgid/std-proposa=
ls/88165d50-83b4-4067-bec3-7c7dab15dce3%40isocpp.org</a>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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+unsubscribe@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>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/7b76fd5e-f3c3-4952-af81-3435456f48b7%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/7b76fd5e-f3c3-=
4952-af81-3435456f48b7%40isocpp.org</a>.<br>
</blockquote></div>
<p></p>
-- <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+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkUEVjAi4T8BhzhHAQXSJTU%2BceR5=
Lb8_iTZwhdadJU3JvQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkUEVj=
Ai4T8BhzhHAQXSJTU%2BceR5Lb8_iTZwhdadJU3JvQ%40mail.gmail.com</a>.<br />
--00000000000071ee0c0577cae05b--
.
Author: euloanty@live.com
Date: Tue, 9 Oct 2018 05:38:16 -0700 (PDT)
Raw View
------=_Part_1978_3975892.1539088696804
Content-Type: multipart/alternative;
boundary="----=_Part_1979_1167637679.1539088696804"
------=_Part_1979_1167637679.1539088696804
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
But, how could you define range-for loop for the type directly (for example=
=20
like std::deque) instead of using a coroutine of that type.
std::deque<int> d;
std::size_t sum(0):
for(const auto &ele : d)
sum+=3D0;
If you can't, it would be painful to write this for generic code?
On Tuesday, October 9, 2018 at 8:28:38 PM UTC+8, Ga=C5=A1per A=C5=BEman wro=
te:
>
> Adding customization points to the language is a "you better have a reall=
y=20
> really good reason" kind of thing. If another feature already provides a=
=20
> way to hook into already existing features without an additional=20
> customization point, you'd expect the standard to avoid adding=20
> customization points.
>
> In this case, it's easy to see how
>
> for (auto range =3D x.in_order_traversal(); auto& element : range) {
> element +=3D 1;
> }
>
> does its job just fine, without an extra customization point.
>
>
>
> On Tue, Oct 9, 2018 at 1:23 PM <eulo...@live.com <javascript:>> wrote:
>
>> also, std::for_each is a function already defined in the standard=20
>> library, calling this won't add anything compared to add coroutine.
>>
>> On Tuesday, October 9, 2018 at 8:14:36 PM UTC+8, Ga=C5=A1per A=C5=BEman =
wrote:
>>>
>>> In the generator case it gets optimized away in most cases, and in=20
>>> others its only the price of a (predicted) function call. No different =
than=20
>>> calling a for_each with a synthesized lambda that you invoke on every=
=20
>>> element.
>>>
>>> On Tue, Oct 9, 2018 at 1:13 PM <eulo...@live.com> wrote:
>>>
>>>> But context swapping is slow.
>>>>
>>>> On Tuesday, October 9, 2018 at 8:07:35 PM UTC+8, Ga=C5=A1per A=C5=BEma=
n wrote:
>>>>>
>>>>> The solution for this is already targeted by the generators of=20
>>>>> coroutines.
>>>>>
>>>>> On Tue, Oct 9, 2018 at 1:05 PM <eulo...@live.com> wrote:
>>>>>
>>>>>> I think it is painful and noisy to write iterators in order to=20
>>>>>> support range-for loop.
>>>>>>
>>>>>> Here are my reasons:
>>>>>> 1: semantics of range-for loop are not necessarily equivalent to=20
>>>>>> access every iterator in the range.
>>>>>> 2: For many containers, defining iterators are harder than defining=
=20
>>>>>> the range-for loop directly.
>>>>>> 3: It is painful to write iterators to support simple data structure=
s.
>>>>>> 4: For containers like std::deque, std::set, std::map and even lists=
,=20
>>>>>> using iterators to traverse the entire container lose a huge amount =
of=20
>>>>>> performance compared to define a universal for_each function.
>>>>>>
>>>>>> For example, if I have a binary search tree:
>>>>>>
>>>>>> template<typename T>
>>>>>> class bst
>>>>>> {
>>>>>> };
>>>>>>
>>>>>>
>>>>>> template<typename T,typename Callback>
>>>>>> void inorder_traverse(const bstnode<T> *p,Callback &&F)
>>>>>> {
>>>>>> if(p->left())
>>>>>> inorder_travel(p->left(),F);
>>>>>> F(p->value());
>>>>>> if(p->right())
>>>>>> inorder_travel(p->right(),F);
>>>>>> }
>>>>>> template<typename T,typename Callback>
>>>>>> inline void for_each(const bst<T> &t,Callback &&F)
>>>>>> {
>>>>>> if(t.root())
>>>>>> inorder_traverse(t.root(),std::forward<Callback>(F));
>>>>>> }
>>>>>>
>>>>>>
>>>>>>
>>>>>> bst<std::size_t> b;=20
>>>>>> std::size_t sum(0);
>>>>>> for(const auto &ele : b) // will check whether the "for_each"=20
>>>>>> function is defined for the container. If it does have one, call thi=
s first.
>>>>>> sum+=3Dele;
>>>>>>
>>>>>> this will be equivalent to:
>>>>>>
>>>>>> bst<std::size_t> b;=20
>>>>>> std::size_t sum(0);
>>>>>> for_each(b,[&](const auto &ele)
>>>>>> {
>>>>>> sum+=3Dele;
>>>>>> });
>>>>>>
>>>>>> --=20
>>>>>> You received this message because you are subscribed to the Google=
=20
>>>>>> Groups "ISO C++ Standard - Future Proposals" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it,=20
>>>>>> send an email to std-proposal...@isocpp.org.
>>>>>> To post to this group, send email to std-pr...@isocpp.org.
>>>>>> To view this discussion on the web visit=20
>>>>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba3d13=
b-3044-4223-afd0-218e8ba06893%40isocpp.org=20
>>>>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba3d1=
3b-3044-4223-afd0-218e8ba06893%40isocpp.org?utm_medium=3Demail&utm_source=
=3Dfooter>
>>>>>> .
>>>>>>
>>>>> --=20
>>>> You received this message because you are subscribed to the Google=20
>>>> Groups "ISO C++ Standard - Future Proposals" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send=
=20
>>>> an email to std-proposal...@isocpp.org.
>>>> To post to this group, send email to std-pr...@isocpp.org.
>>>> To view this discussion on the web visit=20
>>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/88165d50-=
83b4-4067-bec3-7c7dab15dce3%40isocpp.org=20
>>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/88165d50=
-83b4-4067-bec3-7c7dab15dce3%40isocpp.org?utm_medium=3Demail&utm_source=3Df=
ooter>
>>>> .
>>>>
>>> --=20
>> You received this message because you are subscribed to the Google Group=
s=20
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n=20
>> email to std-proposal...@isocpp.org <javascript:>.
>> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
>> To view this discussion on the web visit=20
>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/7b76fd5e-f3=
c3-4952-af81-3435456f48b7%40isocpp.org=20
>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/7b76fd5e-f=
3c3-4952-af81-3435456f48b7%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoo=
ter>
>> .
>>
>
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/f2f9e546-638d-4ebb-b0c9-f1eb329717f0%40isocpp.or=
g.
------=_Part_1979_1167637679.1539088696804
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div><div>But, how could you define range-for loop for the=
type directly (for example like std::deque) instead of using a coroutine=
=C2=A0of that type.<br></div></div><div><br></div><div>std::deque<int>=
; d;</div><div>std::size_t sum(0):</div><div>for(const auto &ele : d)<b=
r></div><div>=C2=A0 =C2=A0sum+=3D0;</div><div><br></div><div>If you can'=
;t, it would be=C2=A0painful to write this for generic code?</div><div><br>=
</div><div><br></div><div>On Tuesday, October 9, 2018 at 8:28:38 PM UTC+8, =
Ga=C5=A1per A=C5=BEman wrote:<blockquote class=3D"gmail_quote" style=3D"mar=
gin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><=
div dir=3D"ltr">Adding customization points to the language is a "you =
better have a really really good reason" kind of thing. If another fea=
ture already provides a way to hook into already existing features without =
an additional customization point, you'd expect the standard to avoid a=
dding customization points.<div><br></div><div>In this case, it's easy =
to see how</div><div><br></div><div>for (auto range =3D x.in_order_traversa=
l(); auto& element : range) {</div><div>=C2=A0 =C2=A0element=C2=A0+=3D =
1;</div><div>}</div><div><br></div><div>does its job just fine, without an =
extra customization point.</div><div><br></div><div><br></div></div><br><di=
v class=3D"gmail_quote"><div dir=3D"ltr">On Tue, Oct 9, 2018 at 1:23 PM <=
;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"q7JbwPR=
bBAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:';re=
turn true;" onclick=3D"this.href=3D'javascript:';return true;">eulo=
....@live.com</a>> wrote:<br></div><blockquote class=3D"gmail_quote" styl=
e=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div di=
r=3D"ltr">also, std::for_each is a function already defined in the standard=
library, calling this won't add anything compared to add coroutine.<br=
><br>On Tuesday, October 9, 2018 at 8:14:36 PM UTC+8, Ga=C5=A1per A=C5=BEma=
n wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8=
ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">In the gen=
erator case it gets optimized away in most cases, and in others its only th=
e price of a (predicted) function call. No different than calling a for_eac=
h with a synthesized lambda that you invoke on every element.</div><br><div=
class=3D"gmail_quote"><div dir=3D"ltr">On Tue, Oct 9, 2018 at 1:13 PM <=
<a rel=3D"nofollow">eulo...@live.com</a>> wrote:<br></div><blockquote cl=
ass=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;p=
adding-left:1ex"><div dir=3D"ltr">But context swapping is slow.<br><br>On T=
uesday, October 9, 2018 at 8:07:35 PM UTC+8, Ga=C5=A1per A=C5=BEman wrote:<=
blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border=
-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">The solution for th=
is is already targeted by the generators of coroutines.</div><br><div class=
=3D"gmail_quote"><div dir=3D"ltr">On Tue, Oct 9, 2018 at 1:05 PM <<a rel=
=3D"nofollow">eulo...@live.com</a>> wrote:<br></div><blockquote class=3D=
"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding=
-left:1ex"><div dir=3D"ltr"><div>I think it is painful and noisy to write i=
terators in order to support range-for loop.</div><div><br></div><div>Here =
are my reasons:</div><div>1: semantics of range-for loop are not necessaril=
y equivalent to access every iterator in the range.</div><div>2: For many c=
ontainers, defining iterators are harder than defining the range-for loop d=
irectly.</div><div>3: It is painful to write iterators to support simple da=
ta structures.</div><div>4: For containers like std::deque, std::set, std::=
map and even lists, using iterators to=C2=A0traverse the entire container l=
ose a huge amount of performance compared to define a universal for_each fu=
nction.</div><div><br></div><div>For example, if I have a binary search tre=
e:</div><div><br></div><div>template<typename T></div><div>class bst<=
/div><div>{<br></div><div>};</div><div><br></div><div><br></div><div>templa=
te<typename T,typename Callback></div><div>void inorder_traverse(cons=
t bstnode<T> *p,Callback &&F)</div><div>{</div><div><span sty=
le=3D"white-space:pre-wrap"> </span>if(p->left())</div><div><span style=
=3D"white-space:pre-wrap"> </span>inorder_travel(p->left(),F);</div><di=
v><span style=3D"white-space:pre-wrap"> </span>F(p->value());</div><div>=
<span style=3D"white-space:pre-wrap"> </span>if(p->right())</div><div><s=
pan style=3D"white-space:pre-wrap"> </span>inorder_travel(p->right(),F)=
;</div><div>}</div><div>template<typename T,typename Callback></div><=
div>inline void for_each(const bst<T> &t,Callback &&F)</d=
iv><div>{</div><div><span style=3D"white-space:pre-wrap"> </span>if(t.root(=
))</div><div><span style=3D"white-space:pre-wrap"> </span>inorder_traverse=
(t.root(),std:<wbr>:forward<Callback>(F));</div><div>}</div><div><br>=
</div><div><br></div><div><br></div><div>bst<std::size_t> b;=C2=A0</d=
iv><div>std::size_t sum(0);<br></div><div>for(const auto &ele : b)=C2=
=A0 =C2=A0 // will check whether the "for_each" function is defin=
ed for the container. If it does have one, call this first.<br></div><div>=
=C2=A0 =C2=A0 sum+=3Dele;</div><div><br></div><div>this will be equivalent =
to:</div><div><br></div><div><div>bst<std::size_t> b;=C2=A0</div><div=
>std::size_t sum(0);<br></div><div>for_each(b,[&](const auto &ele)<=
/div></div><div>{</div><div>=C2=A0 =C2=A0 sum+=3Dele;<br></div><div>});</di=
v><div><br></div></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/9ba3d13b-3044-4223-<wbr>afd0-=
218e8ba06893%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/88165d50-83b4-4067-<wbr>bec3-=
7c7dab15dce3%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
q7JbwPRbBAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:&=
#39;;return true;" onclick=3D"this.href=3D'javascript:';return true=
;">std-proposal...@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"javascript:" target=3D"_bla=
nk" gdf-obfuscated-mailto=3D"q7JbwPRbBAAJ" rel=3D"nofollow" onmousedown=3D"=
this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'=
;javascript:';return true;">std-pr...@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/7b76fd5e-f3c3-4952-af81-3435456f48b7%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank" =
rel=3D"nofollow" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/7b76fd5e-f3c3-4952-af81-3435456f48b7%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/7b76fd5e-f3c3-4952-af81-3435456f48b7%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/7b76fd5e-f3c3-4952-<wbr>af81-=
3435456f48b7%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div></div>
<p></p>
-- <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+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/f2f9e546-638d-4ebb-b0c9-f1eb329717f0%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/f2f9e546-638d-4ebb-b0c9-f1eb329717f0=
%40isocpp.org</a>.<br />
------=_Part_1979_1167637679.1539088696804--
------=_Part_1978_3975892.1539088696804--
.
Author: euloanty@live.com
Date: Tue, 9 Oct 2018 05:40:30 -0700 (PDT)
Raw View
------=_Part_2097_2086069290.1539088830377
Content-Type: multipart/alternative;
boundary="----=_Part_2098_1526273556.1539088830377"
------=_Part_2098_1526273556.1539088830377
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
I just want to write:
for (auto& element : x) {
element +=3D 1;
}
I don't want to write:
for (auto range =3D x.in_order_traversal(); auto& element : range) {
element +=3D 1;
}
This code won't work withe generic code.
On Tuesday, October 9, 2018 at 8:28:38 PM UTC+8, Ga=C5=A1per A=C5=BEman wro=
te:
>
> Adding customization points to the language is a "you better have a reall=
y=20
> really good reason" kind of thing. If another feature already provides a=
=20
> way to hook into already existing features without an additional=20
> customization point, you'd expect the standard to avoid adding=20
> customization points.
>
> In this case, it's easy to see how
>
> for (auto range =3D x.in_order_traversal(); auto& element : range) {
> element +=3D 1;
> }
>
> does its job just fine, without an extra customization point.
>
>
>
> On Tue, Oct 9, 2018 at 1:23 PM <eulo...@live.com <javascript:>> wrote:
>
>> also, std::for_each is a function already defined in the standard=20
>> library, calling this won't add anything compared to add coroutine.
>>
>> On Tuesday, October 9, 2018 at 8:14:36 PM UTC+8, Ga=C5=A1per A=C5=BEman =
wrote:
>>>
>>> In the generator case it gets optimized away in most cases, and in=20
>>> others its only the price of a (predicted) function call. No different =
than=20
>>> calling a for_each with a synthesized lambda that you invoke on every=
=20
>>> element.
>>>
>>> On Tue, Oct 9, 2018 at 1:13 PM <eulo...@live.com> wrote:
>>>
>>>> But context swapping is slow.
>>>>
>>>> On Tuesday, October 9, 2018 at 8:07:35 PM UTC+8, Ga=C5=A1per A=C5=BEma=
n wrote:
>>>>>
>>>>> The solution for this is already targeted by the generators of=20
>>>>> coroutines.
>>>>>
>>>>> On Tue, Oct 9, 2018 at 1:05 PM <eulo...@live.com> wrote:
>>>>>
>>>>>> I think it is painful and noisy to write iterators in order to=20
>>>>>> support range-for loop.
>>>>>>
>>>>>> Here are my reasons:
>>>>>> 1: semantics of range-for loop are not necessarily equivalent to=20
>>>>>> access every iterator in the range.
>>>>>> 2: For many containers, defining iterators are harder than defining=
=20
>>>>>> the range-for loop directly.
>>>>>> 3: It is painful to write iterators to support simple data structure=
s.
>>>>>> 4: For containers like std::deque, std::set, std::map and even lists=
,=20
>>>>>> using iterators to traverse the entire container lose a huge amount =
of=20
>>>>>> performance compared to define a universal for_each function.
>>>>>>
>>>>>> For example, if I have a binary search tree:
>>>>>>
>>>>>> template<typename T>
>>>>>> class bst
>>>>>> {
>>>>>> };
>>>>>>
>>>>>>
>>>>>> template<typename T,typename Callback>
>>>>>> void inorder_traverse(const bstnode<T> *p,Callback &&F)
>>>>>> {
>>>>>> if(p->left())
>>>>>> inorder_travel(p->left(),F);
>>>>>> F(p->value());
>>>>>> if(p->right())
>>>>>> inorder_travel(p->right(),F);
>>>>>> }
>>>>>> template<typename T,typename Callback>
>>>>>> inline void for_each(const bst<T> &t,Callback &&F)
>>>>>> {
>>>>>> if(t.root())
>>>>>> inorder_traverse(t.root(),std::forward<Callback>(F));
>>>>>> }
>>>>>>
>>>>>>
>>>>>>
>>>>>> bst<std::size_t> b;=20
>>>>>> std::size_t sum(0);
>>>>>> for(const auto &ele : b) // will check whether the "for_each"=20
>>>>>> function is defined for the container. If it does have one, call thi=
s first.
>>>>>> sum+=3Dele;
>>>>>>
>>>>>> this will be equivalent to:
>>>>>>
>>>>>> bst<std::size_t> b;=20
>>>>>> std::size_t sum(0);
>>>>>> for_each(b,[&](const auto &ele)
>>>>>> {
>>>>>> sum+=3Dele;
>>>>>> });
>>>>>>
>>>>>> --=20
>>>>>> You received this message because you are subscribed to the Google=
=20
>>>>>> Groups "ISO C++ Standard - Future Proposals" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it,=20
>>>>>> send an email to std-proposal...@isocpp.org.
>>>>>> To post to this group, send email to std-pr...@isocpp.org.
>>>>>> To view this discussion on the web visit=20
>>>>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba3d13=
b-3044-4223-afd0-218e8ba06893%40isocpp.org=20
>>>>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba3d1=
3b-3044-4223-afd0-218e8ba06893%40isocpp.org?utm_medium=3Demail&utm_source=
=3Dfooter>
>>>>>> .
>>>>>>
>>>>> --=20
>>>> You received this message because you are subscribed to the Google=20
>>>> Groups "ISO C++ Standard - Future Proposals" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send=
=20
>>>> an email to std-proposal...@isocpp.org.
>>>> To post to this group, send email to std-pr...@isocpp.org.
>>>> To view this discussion on the web visit=20
>>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/88165d50-=
83b4-4067-bec3-7c7dab15dce3%40isocpp.org=20
>>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/88165d50=
-83b4-4067-bec3-7c7dab15dce3%40isocpp.org?utm_medium=3Demail&utm_source=3Df=
ooter>
>>>> .
>>>>
>>> --=20
>> You received this message because you are subscribed to the Google Group=
s=20
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n=20
>> email to std-proposal...@isocpp.org <javascript:>.
>> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
>> To view this discussion on the web visit=20
>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/7b76fd5e-f3=
c3-4952-af81-3435456f48b7%40isocpp.org=20
>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/7b76fd5e-f=
3c3-4952-af81-3435456f48b7%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoo=
ter>
>> .
>>
>
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/b6e429b2-e3fb-4a08-9540-32a60fff8ab2%40isocpp.or=
g.
------=_Part_2098_1526273556.1539088830377
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I just want to write:<div><br></div><div><div>for (auto&am=
p; element : x) {</div><div>=C2=A0 =C2=A0element=C2=A0+=3D 1;</div><div>}</=
div><div><br></div><div>I=C2=A0don't want to write:</div><div><div>for =
(auto range =3D x.in_order_traversal(); auto& element : range) {</div><=
div>=C2=A0 =C2=A0element=C2=A0+=3D 1;</div><div>}</div></div><div><br></div=
><div>This code won't work withe generic code.</div><div><br></div>On T=
uesday, October 9, 2018 at 8:28:38 PM UTC+8, Ga=C5=A1per A=C5=BEman wrote:<=
blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bord=
er-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">Adding customi=
zation points to the language is a "you better have a really really go=
od reason" kind of thing. If another feature already provides a way to=
hook into already existing features without an additional customization po=
int, you'd expect the standard to avoid adding customization points.<di=
v><br></div><div>In this case, it's easy to see how</div><div><br></div=
><div>for (auto range =3D x.in_order_traversal(); auto& element : range=
) {</div><div>=C2=A0 =C2=A0element=C2=A0+=3D 1;</div><div>}</div><div><br><=
/div><div>does its job just fine, without an extra customization point.</di=
v><div><br></div><div><br></div></div><br><div class=3D"gmail_quote"><div d=
ir=3D"ltr">On Tue, Oct 9, 2018 at 1:23 PM <<a href=3D"javascript:" targe=
t=3D"_blank" gdf-obfuscated-mailto=3D"q7JbwPRbBAAJ" rel=3D"nofollow" onmous=
edown=3D"this.href=3D'javascript:';return true;" onclick=3D"this.hr=
ef=3D'javascript:';return true;">eulo...@live.com</a>> wrote:<br=
></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-=
left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">also, std::for_each =
is a function already defined in the standard library, calling this won'=
;t add anything compared to add coroutine.<br><br>On Tuesday, October 9, 20=
18 at 8:14:36 PM UTC+8, Ga=C5=A1per A=C5=BEman wrote:<blockquote class=3D"g=
mail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;=
padding-left:1ex"><div dir=3D"ltr">In the generator case it gets optimized =
away in most cases, and in others its only the price of a (predicted) funct=
ion call. No different than calling a for_each with a synthesized lambda th=
at you invoke on every element.</div><br><div class=3D"gmail_quote"><div di=
r=3D"ltr">On Tue, Oct 9, 2018 at 1:13 PM <<a rel=3D"nofollow">eulo...@li=
ve.com</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"m=
argin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"l=
tr">But context swapping is slow.<br><br>On Tuesday, October 9, 2018 at 8:0=
7:35 PM UTC+8, Ga=C5=A1per A=C5=BEman wrote:<blockquote class=3D"gmail_quot=
e" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-l=
eft:1ex"><div dir=3D"ltr">The solution for this is already targeted by the =
generators of coroutines.</div><br><div class=3D"gmail_quote"><div dir=3D"l=
tr">On Tue, Oct 9, 2018 at 1:05 PM <<a rel=3D"nofollow">eulo...@live.com=
</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:=
0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><d=
iv>I think it is painful and noisy to write iterators in order to support r=
ange-for loop.</div><div><br></div><div>Here are my reasons:</div><div>1: s=
emantics of range-for loop are not necessarily equivalent to access every i=
terator in the range.</div><div>2: For many containers, defining iterators =
are harder than defining the range-for loop directly.</div><div>3: It is pa=
inful to write iterators to support simple data structures.</div><div>4: Fo=
r containers like std::deque, std::set, std::map and even lists, using iter=
ators to=C2=A0traverse the entire container lose a huge amount of performan=
ce compared to define a universal for_each function.</div><div><br></div><d=
iv>For example, if I have a binary search tree:</div><div><br></div><div>te=
mplate<typename T></div><div>class bst</div><div>{<br></div><div>};</=
div><div><br></div><div><br></div><div>template<typename T,typename Call=
back></div><div>void inorder_traverse(const bstnode<T> *p,Callback=
&&F)</div><div>{</div><div><span style=3D"white-space:pre-wrap"> <=
/span>if(p->left())</div><div><span style=3D"white-space:pre-wrap"> </s=
pan>inorder_travel(p->left(),F);</div><div><span style=3D"white-space:pr=
e-wrap"> </span>F(p->value());</div><div><span style=3D"white-space:pre-=
wrap"> </span>if(p->right())</div><div><span style=3D"white-space:pre-wr=
ap"> </span>inorder_travel(p->right(),F);</div><div>}</div><div>templat=
e<typename T,typename Callback></div><div>inline void for_each(const =
bst<T> &t,Callback &&F)</div><div>{</div><div><span style=
=3D"white-space:pre-wrap"> </span>if(t.root())</div><div><span style=3D"whi=
te-space:pre-wrap"> </span>inorder_traverse(t.root(),std:<wbr>:forward<=
Callback>(F));</div><div>}</div><div><br></div><div><br></div><div><br><=
/div><div>bst<std::size_t> b;=C2=A0</div><div>std::size_t sum(0);<br>=
</div><div>for(const auto &ele : b)=C2=A0 =C2=A0 // will check whether =
the "for_each" function is defined for the container. If it does =
have one, call this first.<br></div><div>=C2=A0 =C2=A0 sum+=3Dele;</div><di=
v><br></div><div>this will be equivalent to:</div><div><br></div><div><div>=
bst<std::size_t> b;=C2=A0</div><div>std::size_t sum(0);<br></div><div=
>for_each(b,[&](const auto &ele)</div></div><div>{</div><div>=C2=A0=
=C2=A0 sum+=3Dele;<br></div><div>});</div><div><br></div></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/9ba3d13b-3044-4223-<wbr>afd0-=
218e8ba06893%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/88165d50-83b4-4067-<wbr>bec3-=
7c7dab15dce3%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
q7JbwPRbBAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:&=
#39;;return true;" onclick=3D"this.href=3D'javascript:';return true=
;">std-proposal...@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"javascript:" target=3D"_bla=
nk" gdf-obfuscated-mailto=3D"q7JbwPRbBAAJ" rel=3D"nofollow" onmousedown=3D"=
this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'=
;javascript:';return true;">std-pr...@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/7b76fd5e-f3c3-4952-af81-3435456f48b7%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank" =
rel=3D"nofollow" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/7b76fd5e-f3c3-4952-af81-3435456f48b7%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/7b76fd5e-f3c3-4952-af81-3435456f48b7%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/7b76fd5e-f3c3-4952-<wbr>af81-=
3435456f48b7%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div></div>
<p></p>
-- <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+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/b6e429b2-e3fb-4a08-9540-32a60fff8ab2%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/b6e429b2-e3fb-4a08-9540-32a60fff8ab2=
%40isocpp.org</a>.<br />
------=_Part_2098_1526273556.1539088830377--
------=_Part_2097_2086069290.1539088830377--
.
Author: =?UTF-8?B?R2HFoXBlciBBxb5tYW4=?= <gasper.azman@gmail.com>
Date: Tue, 9 Oct 2018 13:44:04 +0100
Raw View
--0000000000006dfbcd0577cb186a
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
By returning a fat iterator that encapsulates the generator from begin(),
and a sentinel that checks it against the generator's end() from end(). It
only takes a few lines of code, and I bet boost can provide a facade that
vanishes in codegen pretty easily.
Or, you know, just use std::for_each and expect it to be customized for
your type if you want generic code.
That said, feel free to propose this, but I personally don't see enough
justification to reserve yet another name in the language, because that's
what the current customization points do.
G
On Tue, Oct 9, 2018 at 1:38 PM <euloanty@live.com> wrote:
> But, how could you define range-for loop for the type directly (for
> example like std::deque) instead of using a coroutine of that type.
>
> std::deque<int> d;
> std::size_t sum(0):
> for(const auto &ele : d)
> sum+=3D0;
>
> If you can't, it would be painful to write this for generic code?
>
>
> On Tuesday, October 9, 2018 at 8:28:38 PM UTC+8, Ga=C5=A1per A=C5=BEman w=
rote:
>>
>> Adding customization points to the language is a "you better have a
>> really really good reason" kind of thing. If another feature already
>> provides a way to hook into already existing features without an additio=
nal
>> customization point, you'd expect the standard to avoid adding
>> customization points.
>>
>> In this case, it's easy to see how
>>
>> for (auto range =3D x.in_order_traversal(); auto& element : range) {
>> element +=3D 1;
>> }
>>
>> does its job just fine, without an extra customization point.
>>
>>
>>
>> On Tue, Oct 9, 2018 at 1:23 PM <eulo...@live.com> wrote:
>>
>>> also, std::for_each is a function already defined in the standard
>>> library, calling this won't add anything compared to add coroutine.
>>>
>>> On Tuesday, October 9, 2018 at 8:14:36 PM UTC+8, Ga=C5=A1per A=C5=BEman=
wrote:
>>>>
>>>> In the generator case it gets optimized away in most cases, and in
>>>> others its only the price of a (predicted) function call. No different=
than
>>>> calling a for_each with a synthesized lambda that you invoke on every
>>>> element.
>>>>
>>>> On Tue, Oct 9, 2018 at 1:13 PM <eulo...@live.com> wrote:
>>>>
>>>>> But context swapping is slow.
>>>>>
>>>>> On Tuesday, October 9, 2018 at 8:07:35 PM UTC+8, Ga=C5=A1per A=C5=BEm=
an wrote:
>>>>>>
>>>>>> The solution for this is already targeted by the generators of
>>>>>> coroutines.
>>>>>>
>>>>>> On Tue, Oct 9, 2018 at 1:05 PM <eulo...@live.com> wrote:
>>>>>>
>>>>>>> I think it is painful and noisy to write iterators in order to
>>>>>>> support range-for loop.
>>>>>>>
>>>>>>> Here are my reasons:
>>>>>>> 1: semantics of range-for loop are not necessarily equivalent to
>>>>>>> access every iterator in the range.
>>>>>>> 2: For many containers, defining iterators are harder than defining
>>>>>>> the range-for loop directly.
>>>>>>> 3: It is painful to write iterators to support simple data
>>>>>>> structures.
>>>>>>> 4: For containers like std::deque, std::set, std::map and even
>>>>>>> lists, using iterators to traverse the entire container lose a huge=
amount
>>>>>>> of performance compared to define a universal for_each function.
>>>>>>>
>>>>>>> For example, if I have a binary search tree:
>>>>>>>
>>>>>>> template<typename T>
>>>>>>> class bst
>>>>>>> {
>>>>>>> };
>>>>>>>
>>>>>>>
>>>>>>> template<typename T,typename Callback>
>>>>>>> void inorder_traverse(const bstnode<T> *p,Callback &&F)
>>>>>>> {
>>>>>>> if(p->left())
>>>>>>> inorder_travel(p->left(),F);
>>>>>>> F(p->value());
>>>>>>> if(p->right())
>>>>>>> inorder_travel(p->right(),F);
>>>>>>> }
>>>>>>> template<typename T,typename Callback>
>>>>>>> inline void for_each(const bst<T> &t,Callback &&F)
>>>>>>> {
>>>>>>> if(t.root())
>>>>>>> inorder_traverse(t.root(),std::forward<Callback>(F));
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> bst<std::size_t> b;
>>>>>>> std::size_t sum(0);
>>>>>>> for(const auto &ele : b) // will check whether the "for_each"
>>>>>>> function is defined for the container. If it does have one, call th=
is first.
>>>>>>> sum+=3Dele;
>>>>>>>
>>>>>>> this will be equivalent to:
>>>>>>>
>>>>>>> bst<std::size_t> b;
>>>>>>> std::size_t sum(0);
>>>>>>> for_each(b,[&](const auto &ele)
>>>>>>> {
>>>>>>> sum+=3Dele;
>>>>>>> });
>>>>>>>
>>>>>>> --
>>>>>>> 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-proposal...@isocpp.org.
>>>>>>> To post to this group, send email to std-pr...@isocpp.org.
>>>>>>> To view this discussion on the web visit
>>>>>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba3d1=
3b-3044-4223-afd0-218e8ba06893%40isocpp.org
>>>>>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba3d=
13b-3044-4223-afd0-218e8ba06893%40isocpp.org?utm_medium=3Demail&utm_source=
=3Dfooter>
>>>>>>> .
>>>>>>>
>>>>>> --
>>>>> 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, sen=
d
>>>>> an email to std-proposal...@isocpp.org.
>>>>> To post to this group, send email to std-pr...@isocpp.org.
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/88165d50=
-83b4-4067-bec3-7c7dab15dce3%40isocpp.org
>>>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/88165d5=
0-83b4-4067-bec3-7c7dab15dce3%40isocpp.org?utm_medium=3Demail&utm_source=3D=
footer>
>>>>> .
>>>>>
>>>> --
>>> 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-proposal...@isocpp.org.
>>> To post to this group, send email to std-pr...@isocpp.org.
>>> To view this discussion on the web visit
>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/7b76fd5e-f=
3c3-4952-af81-3435456f48b7%40isocpp.org
>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/7b76fd5e-=
f3c3-4952-af81-3435456f48b7%40isocpp.org?utm_medium=3Demail&utm_source=3Dfo=
oter>
>>> .
>>>
>> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/f2f9e546-638=
d-4ebb-b0c9-f1eb329717f0%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/f2f9e546-63=
8d-4ebb-b0c9-f1eb329717f0%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoot=
er>
> .
>
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/CAANG%3DkWcM-QVvSaD-7eXCYAoTCUaKNJc_%2BS2ZW_edEz=
esN2zoQ%40mail.gmail.com.
--0000000000006dfbcd0577cb186a
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">By returning a fat iterator that encapsulates the generato=
r from begin(), and a sentinel that checks it against the generator's e=
nd() from end(). It only takes a few lines of code, and I bet boost can pro=
vide a facade that vanishes in codegen pretty easily.<div><br></div><div>Or=
, you know, just use std::for_each and expect it to be customized for your =
type if you want generic code.</div><div><br></div><div>That said, feel fre=
e to propose this, but I personally don't see enough justification to r=
eserve yet another name in the language, because that's what the curren=
t customization points do.</div><div><br></div><div>G<br><div><br></div><di=
v><br></div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue, Oct 9, =
2018 at 1:38 PM <<a href=3D"mailto:euloanty@live.com">euloanty@live.com<=
/a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0=
0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><di=
v><div>But, how could you define range-for loop for the type directly (for =
example like std::deque) instead of using a coroutine=C2=A0of that type.<br=
></div></div><div><br></div><div>std::deque<int> d;</div><div>std::si=
ze_t sum(0):</div><div>for(const auto &ele : d)<br></div><div>=C2=A0 =
=C2=A0sum+=3D0;</div><div><br></div><div>If you can't, it would be=C2=
=A0painful to write this for generic code?</div><div><br></div><div><br></d=
iv><div>On Tuesday, October 9, 2018 at 8:28:38 PM UTC+8, Ga=C5=A1per A=C5=
=BEman wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-lef=
t:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Addin=
g customization points to the language is a "you better have a really =
really good reason" kind of thing. If another feature already provides=
a way to hook into already existing features without an additional customi=
zation point, you'd expect the standard to avoid adding customization p=
oints.<div><br></div><div>In this case, it's easy to see how</div><div>=
<br></div><div>for (auto range =3D x.in_order_traversal(); auto& elemen=
t : range) {</div><div>=C2=A0 =C2=A0element=C2=A0+=3D 1;</div><div>}</div><=
div><br></div><div>does its job just fine, without an extra customization p=
oint.</div><div><br></div><div><br></div></div><br><div class=3D"gmail_quot=
e"><div dir=3D"ltr">On Tue, Oct 9, 2018 at 1:23 PM <<a rel=3D"nofollow">=
eulo...@live.com</a>> wrote:<br></div><blockquote class=3D"gmail_quote" =
style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><di=
v dir=3D"ltr">also, std::for_each is a function already defined in the stan=
dard library, calling this won't add anything compared to add coroutine=
..<br><br>On Tuesday, October 9, 2018 at 8:14:36 PM UTC+8, Ga=C5=A1per A=C5=
=BEman wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-lef=
t:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">In th=
e generator case it gets optimized away in most cases, and in others its on=
ly the price of a (predicted) function call. No different than calling a fo=
r_each with a synthesized lambda that you invoke on every element.</div><br=
><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue, Oct 9, 2018 at 1:13 PM=
<<a rel=3D"nofollow">eulo...@live.com</a>> wrote:<br></div><blockquo=
te class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc so=
lid;padding-left:1ex"><div dir=3D"ltr">But context swapping is slow.<br><br=
>On Tuesday, October 9, 2018 at 8:07:35 PM UTC+8, Ga=C5=A1per A=C5=BEman wr=
ote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;b=
order-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">The solution f=
or this is already targeted by the generators of coroutines.</div><br><div =
class=3D"gmail_quote"><div dir=3D"ltr">On Tue, Oct 9, 2018 at 1:05 PM <<=
a rel=3D"nofollow">eulo...@live.com</a>> wrote:<br></div><blockquote cla=
ss=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;pa=
dding-left:1ex"><div dir=3D"ltr"><div>I think it is painful and noisy to wr=
ite iterators in order to support range-for loop.</div><div><br></div><div>=
Here are my reasons:</div><div>1: semantics of range-for loop are not neces=
sarily equivalent to access every iterator in the range.</div><div>2: For m=
any containers, defining iterators are harder than defining the range-for l=
oop directly.</div><div>3: It is painful to write iterators to support simp=
le data structures.</div><div>4: For containers like std::deque, std::set, =
std::map and even lists, using iterators to=C2=A0traverse the entire contai=
ner lose a huge amount of performance compared to define a universal for_ea=
ch function.</div><div><br></div><div>For example, if I have a binary searc=
h tree:</div><div><br></div><div>template<typename T></div><div>class=
bst</div><div>{<br></div><div>};</div><div><br></div><div><br></div><div>t=
emplate<typename T,typename Callback></div><div>void inorder_traverse=
(const bstnode<T> *p,Callback &&F)</div><div>{</div><div><spa=
n style=3D"white-space:pre-wrap"> </span>if(p->left())</div><div><span s=
tyle=3D"white-space:pre-wrap"> </span>inorder_travel(p->left(),F);</div=
><div><span style=3D"white-space:pre-wrap"> </span>F(p->value());</div><=
div><span style=3D"white-space:pre-wrap"> </span>if(p->right())</div><di=
v><span style=3D"white-space:pre-wrap"> </span>inorder_travel(p->right(=
),F);</div><div>}</div><div>template<typename T,typename Callback></d=
iv><div>inline void for_each(const bst<T> &t,Callback &&F=
)</div><div>{</div><div><span style=3D"white-space:pre-wrap"> </span>if(t.r=
oot())</div><div><span style=3D"white-space:pre-wrap"> </span>inorder_trav=
erse(t.root(),std::forward<Callback>(F));</div><div>}</div><div><br><=
/div><div><br></div><div><br></div><div>bst<std::size_t> b;=C2=A0</di=
v><div>std::size_t sum(0);<br></div><div>for(const auto &ele : b)=C2=A0=
=C2=A0 // will check whether the "for_each" function is defined =
for the container. If it does have one, call this first.<br></div><div>=C2=
=A0 =C2=A0 sum+=3Dele;</div><div><br></div><div>this will be equivalent to:=
</div><div><br></div><div><div>bst<std::size_t> b;=C2=A0</div><div>st=
d::size_t sum(0);<br></div><div>for_each(b,[&](const auto &ele)</di=
v></div><div>{</div><div>=C2=A0 =C2=A0 sum+=3Dele;<br></div><div>});</div><=
div><br></div></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank">https://groups.google.com/a/isocpp.org/d/msgid/std-proposa=
ls/9ba3d13b-3044-4223-afd0-218e8ba06893%40isocpp.org</a>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank">https://groups.google.com/a/isocpp.org/d/msgid/std-proposa=
ls/88165d50-83b4-4067-bec3-7c7dab15dce3%40isocpp.org</a>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/7b76fd5e-f3c3-4952-af81-3435456f48b7%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank">https://groups.google.com/a/isocpp.org/d/msgid/std-proposa=
ls/7b76fd5e-f3c3-4952-af81-3435456f48b7%40isocpp.org</a>.<br>
</blockquote></div>
</blockquote></div></div>
<p></p>
-- <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+unsubscribe@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>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/f2f9e546-638d-4ebb-b0c9-f1eb329717f0%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/f2f9e546-638d-=
4ebb-b0c9-f1eb329717f0%40isocpp.org</a>.<br>
</blockquote></div></div></div>
<p></p>
-- <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+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkWcM-QVvSaD-7eXCYAoTCUaKNJc_%=
2BS2ZW_edEzesN2zoQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkWcM-=
QVvSaD-7eXCYAoTCUaKNJc_%2BS2ZW_edEzesN2zoQ%40mail.gmail.com</a>.<br />
--0000000000006dfbcd0577cb186a--
.
Author: florian.csdt@gmail.com
Date: Tue, 9 Oct 2018 05:45:11 -0700 (PDT)
Raw View
------=_Part_646_395448163.1539089111737
Content-Type: multipart/alternative;
boundary="----=_Part_647_455028956.1539089111737"
------=_Part_647_455028956.1539089111737
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
There are cases where a for_each can be better/faster(/stronger) than=20
ranges: nested loops.
Emulating nested loops with ranges is slow because for each ++, the=20
iterator has to check if it has reached the end of the inner loop or not.
Le mardi 9 octobre 2018 14:28:38 UTC+2, Ga=C5=A1per A=C5=BEman a =C3=A9crit=
:
>
> Adding customization points to the language is a "you better have a reall=
y=20
> really good reason" kind of thing. If another feature already provides a=
=20
> way to hook into already existing features without an additional=20
> customization point, you'd expect the standard to avoid adding=20
> customization points.
>
> In this case, it's easy to see how
>
> for (auto range =3D x.in_order_traversal(); auto& element : range) {
> element +=3D 1;
> }
>
> does its job just fine, without an extra customization point.
>
>
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/71498824-6a5b-40ba-84db-4d4df72e2c94%40isocpp.or=
g.
------=_Part_647_455028956.1539089111737
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>There are cases where a for_each can be better/faster=
(/stronger) than ranges: nested loops.</div><div><br></div><div>Emulating n=
ested loops with ranges is slow because for each ++, the iterator has to ch=
eck if it has reached the end of the inner loop or not.<br></div><br>Le mar=
di 9 octobre 2018 14:28:38 UTC+2, Ga=C5=A1per A=C5=BEman a =C3=A9crit=C2=A0=
:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bo=
rder-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">Adding custo=
mization points to the language is a "you better have a really really =
good reason" kind of thing. If another feature already provides a way =
to hook into already existing features without an additional customization =
point, you'd expect the standard to avoid adding customization points.<=
div><br></div><div>In this case, it's easy to see how</div><div><br></d=
iv><div>for (auto range =3D x.in_order_traversal(); auto& element : ran=
ge) {</div><div>=C2=A0 =C2=A0element=C2=A0+=3D 1;</div><div>}</div><div><br=
></div><div>does its job just fine, without an extra customization point.</=
div><div><br></div></div></blockquote></div>
<p></p>
-- <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+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/71498824-6a5b-40ba-84db-4d4df72e2c94%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/71498824-6a5b-40ba-84db-4d4df72e2c94=
%40isocpp.org</a>.<br />
------=_Part_647_455028956.1539089111737--
------=_Part_646_395448163.1539089111737--
.
Author: euloanty@live.com
Date: Tue, 9 Oct 2018 05:47:41 -0700 (PDT)
Raw View
------=_Part_1915_923829433.1539089261415
Content-Type: multipart/alternative;
boundary="----=_Part_1916_129801295.1539089261416"
------=_Part_1916_129801295.1539089261416
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
I don't think it is the point about coroutine. It is about the interface=20
for containers of range-for loop. The current standard must use iterators=
=20
for containers to iterator the entire container. You have to define a=20
standard interface for this in order for all containers to write customized=
=20
code to support these kinds of usage which is lacking in the standard. No=
=20
matter you use coroutine or for-each, it won't solve the issue directly.
On Tuesday, October 9, 2018 at 8:44:17 PM UTC+8, Ga=C5=A1per A=C5=BEman wro=
te:
>
> By returning a fat iterator that encapsulates the generator from begin(),=
=20
> and a sentinel that checks it against the generator's end() from end(). I=
t=20
> only takes a few lines of code, and I bet boost can provide a facade that=
=20
> vanishes in codegen pretty easily.
>
> Or, you know, just use std::for_each and expect it to be customized for=
=20
> your type if you want generic code.
>
> That said, feel free to propose this, but I personally don't see enough=
=20
> justification to reserve yet another name in the language, because that's=
=20
> what the current customization points do.
>
> G
>
>
>
> On Tue, Oct 9, 2018 at 1:38 PM <eulo...@live.com <javascript:>> wrote:
>
>> But, how could you define range-for loop for the type directly (for=20
>> example like std::deque) instead of using a coroutine of that type.
>>
>> std::deque<int> d;
>> std::size_t sum(0):
>> for(const auto &ele : d)
>> sum+=3D0;
>>
>> If you can't, it would be painful to write this for generic code?
>>
>>
>> On Tuesday, October 9, 2018 at 8:28:38 PM UTC+8, Ga=C5=A1per A=C5=BEman =
wrote:
>>>
>>> Adding customization points to the language is a "you better have a=20
>>> really really good reason" kind of thing. If another feature already=20
>>> provides a way to hook into already existing features without an additi=
onal=20
>>> customization point, you'd expect the standard to avoid adding=20
>>> customization points.
>>>
>>> In this case, it's easy to see how
>>>
>>> for (auto range =3D x.in_order_traversal(); auto& element : range) {
>>> element +=3D 1;
>>> }
>>>
>>> does its job just fine, without an extra customization point.
>>>
>>>
>>>
>>> On Tue, Oct 9, 2018 at 1:23 PM <eulo...@live.com> wrote:
>>>
>>>> also, std::for_each is a function already defined in the standard=20
>>>> library, calling this won't add anything compared to add coroutine.
>>>>
>>>> On Tuesday, October 9, 2018 at 8:14:36 PM UTC+8, Ga=C5=A1per A=C5=BEma=
n wrote:
>>>>>
>>>>> In the generator case it gets optimized away in most cases, and in=20
>>>>> others its only the price of a (predicted) function call. No differen=
t than=20
>>>>> calling a for_each with a synthesized lambda that you invoke on every=
=20
>>>>> element.
>>>>>
>>>>> On Tue, Oct 9, 2018 at 1:13 PM <eulo...@live.com> wrote:
>>>>>
>>>>>> But context swapping is slow.
>>>>>>
>>>>>> On Tuesday, October 9, 2018 at 8:07:35 PM UTC+8, Ga=C5=A1per A=C5=BE=
man wrote:
>>>>>>>
>>>>>>> The solution for this is already targeted by the generators of=20
>>>>>>> coroutines.
>>>>>>>
>>>>>>> On Tue, Oct 9, 2018 at 1:05 PM <eulo...@live.com> wrote:
>>>>>>>
>>>>>>>> I think it is painful and noisy to write iterators in order to=20
>>>>>>>> support range-for loop.
>>>>>>>>
>>>>>>>> Here are my reasons:
>>>>>>>> 1: semantics of range-for loop are not necessarily equivalent to=
=20
>>>>>>>> access every iterator in the range.
>>>>>>>> 2: For many containers, defining iterators are harder than definin=
g=20
>>>>>>>> the range-for loop directly.
>>>>>>>> 3: It is painful to write iterators to support simple data=20
>>>>>>>> structures.
>>>>>>>> 4: For containers like std::deque, std::set, std::map and even=20
>>>>>>>> lists, using iterators to traverse the entire container lose a hug=
e amount=20
>>>>>>>> of performance compared to define a universal for_each function.
>>>>>>>>
>>>>>>>> For example, if I have a binary search tree:
>>>>>>>>
>>>>>>>> template<typename T>
>>>>>>>> class bst
>>>>>>>> {
>>>>>>>> };
>>>>>>>>
>>>>>>>>
>>>>>>>> template<typename T,typename Callback>
>>>>>>>> void inorder_traverse(const bstnode<T> *p,Callback &&F)
>>>>>>>> {
>>>>>>>> if(p->left())
>>>>>>>> inorder_travel(p->left(),F);
>>>>>>>> F(p->value());
>>>>>>>> if(p->right())
>>>>>>>> inorder_travel(p->right(),F);
>>>>>>>> }
>>>>>>>> template<typename T,typename Callback>
>>>>>>>> inline void for_each(const bst<T> &t,Callback &&F)
>>>>>>>> {
>>>>>>>> if(t.root())
>>>>>>>> inorder_traverse(t.root(),std::forward<Callback>(F));
>>>>>>>> }
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> bst<std::size_t> b;=20
>>>>>>>> std::size_t sum(0);
>>>>>>>> for(const auto &ele : b) // will check whether the "for_each"=
=20
>>>>>>>> function is defined for the container. If it does have one, call t=
his first.
>>>>>>>> sum+=3Dele;
>>>>>>>>
>>>>>>>> this will be equivalent to:
>>>>>>>>
>>>>>>>> bst<std::size_t> b;=20
>>>>>>>> std::size_t sum(0);
>>>>>>>> for_each(b,[&](const auto &ele)
>>>>>>>> {
>>>>>>>> sum+=3Dele;
>>>>>>>> });
>>>>>>>>
>>>>>>>> --=20
>>>>>>>> You received this message because you are subscribed to the Google=
=20
>>>>>>>> Groups "ISO C++ Standard - Future Proposals" group.
>>>>>>>> To unsubscribe from this group and stop receiving emails from it,=
=20
>>>>>>>> send an email to std-proposal...@isocpp.org.
>>>>>>>> To post to this group, send email to std-pr...@isocpp.org.
>>>>>>>> To view this discussion on the web visit=20
>>>>>>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba3d=
13b-3044-4223-afd0-218e8ba06893%40isocpp.org=20
>>>>>>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba3=
d13b-3044-4223-afd0-218e8ba06893%40isocpp.org?utm_medium=3Demail&utm_source=
=3Dfooter>
>>>>>>>> .
>>>>>>>>
>>>>>>> --=20
>>>>>> You received this message because you are subscribed to the Google=
=20
>>>>>> Groups "ISO C++ Standard - Future Proposals" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it,=20
>>>>>> send an email to std-proposal...@isocpp.org.
>>>>>> To post to this group, send email to std-pr...@isocpp.org.
>>>>>> To view this discussion on the web visit=20
>>>>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/88165d5=
0-83b4-4067-bec3-7c7dab15dce3%40isocpp.org=20
>>>>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/88165d=
50-83b4-4067-bec3-7c7dab15dce3%40isocpp.org?utm_medium=3Demail&utm_source=
=3Dfooter>
>>>>>> .
>>>>>>
>>>>> --=20
>>>> You received this message because you are subscribed to the Google=20
>>>> Groups "ISO C++ Standard - Future Proposals" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send=
=20
>>>> an email to std-proposal...@isocpp.org.
>>>> To post to this group, send email to std-pr...@isocpp.org.
>>>> To view this discussion on the web visit=20
>>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/7b76fd5e-=
f3c3-4952-af81-3435456f48b7%40isocpp.org=20
>>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/7b76fd5e=
-f3c3-4952-af81-3435456f48b7%40isocpp.org?utm_medium=3Demail&utm_source=3Df=
ooter>
>>>> .
>>>>
>>> --=20
>> You received this message because you are subscribed to the Google Group=
s=20
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n=20
>> email to std-proposal...@isocpp.org <javascript:>.
>> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
>> To view this discussion on the web visit=20
>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/f2f9e546-63=
8d-4ebb-b0c9-f1eb329717f0%40isocpp.org=20
>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/f2f9e546-6=
38d-4ebb-b0c9-f1eb329717f0%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoo=
ter>
>> .
>>
>
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/63319859-3f0a-4799-90e9-fd699ee89f29%40isocpp.or=
g.
------=_Part_1916_129801295.1539089261416
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I don't think it is the point about coroutine. It is a=
bout the interface for containers of range-for loop. The current standard m=
ust use iterators for containers to iterator the entire container. You have=
to define a standard interface for this in order for all containers to wri=
te customized code to support these kinds of usage which is lacking in the =
standard. No matter you use coroutine or for-each, it won't solve the i=
ssue directly.<br><br>On Tuesday, October 9, 2018 at 8:44:17 PM UTC+8, Ga=
=C5=A1per A=C5=BEman wrote:<blockquote class=3D"gmail_quote" style=3D"margi=
n: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><di=
v dir=3D"ltr">By returning a fat iterator that encapsulates the generator f=
rom begin(), and a sentinel that checks it against the generator's end(=
) from end(). It only takes a few lines of code, and I bet boost can provid=
e a facade that vanishes in codegen pretty easily.<div><br></div><div>Or, y=
ou know, just use std::for_each and expect it to be customized for your typ=
e if you want generic code.</div><div><br></div><div>That said, feel free t=
o propose this, but I personally don't see enough justification to rese=
rve yet another name in the language, because that's what the current c=
ustomization points do.</div><div><br></div><div>G<br><div><br></div><div><=
br></div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue, Oct 9, 201=
8 at 1:38 PM <<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-m=
ailto=3D"gYoPd89cBAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'jav=
ascript:';return true;" onclick=3D"this.href=3D'javascript:';re=
turn true;">eulo...@live.com</a>> wrote:<br></div><blockquote class=3D"g=
mail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-l=
eft:1ex"><div dir=3D"ltr"><div><div>But, how could you define range-for loo=
p for the type directly (for example like std::deque) instead of using a co=
routine=C2=A0of that type.<br></div></div><div><br></div><div>std::deque<=
;int> d;</div><div>std::size_t sum(0):</div><div>for(const auto &ele=
: d)<br></div><div>=C2=A0 =C2=A0sum+=3D0;</div><div><br></div><div>If you =
can't, it would be=C2=A0painful to write this for generic code?</div><d=
iv><br></div><div><br></div><div>On Tuesday, October 9, 2018 at 8:28:38 PM =
UTC+8, Ga=C5=A1per A=C5=BEman wrote:<blockquote class=3D"gmail_quote" style=
=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"=
><div dir=3D"ltr">Adding customization points to the language is a "yo=
u better have a really really good reason" kind of thing. If another f=
eature already provides a way to hook into already existing features withou=
t an additional customization point, you'd expect the standard to avoid=
adding customization points.<div><br></div><div>In this case, it's eas=
y to see how</div><div><br></div><div>for (auto range =3D x.in_order_traver=
sal(); auto& element : range) {</div><div>=C2=A0 =C2=A0element=C2=A0+=
=3D 1;</div><div>}</div><div><br></div><div>does its job just fine, without=
an extra customization point.</div><div><br></div><div><br></div></div><br=
><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue, Oct 9, 2018 at 1:23 PM=
<<a rel=3D"nofollow">eulo...@live.com</a>> wrote:<br></div><blockquo=
te class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc so=
lid;padding-left:1ex"><div dir=3D"ltr">also, std::for_each is a function al=
ready defined in the standard library, calling this won't add anything =
compared to add coroutine.<br><br>On Tuesday, October 9, 2018 at 8:14:36 PM=
UTC+8, Ga=C5=A1per A=C5=BEman wrote:<blockquote class=3D"gmail_quote" styl=
e=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex=
"><div dir=3D"ltr">In the generator case it gets optimized away in most cas=
es, and in others its only the price of a (predicted) function call. No dif=
ferent than calling a for_each with a synthesized lambda that you invoke on=
every element.</div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue=
, Oct 9, 2018 at 1:13 PM <<a rel=3D"nofollow">eulo...@live.com</a>> w=
rote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex=
;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">But context =
swapping is slow.<br><br>On Tuesday, October 9, 2018 at 8:07:35 PM UTC+8, G=
a=C5=A1per A=C5=BEman wrote:<blockquote class=3D"gmail_quote" style=3D"marg=
in:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div di=
r=3D"ltr">The solution for this is already targeted by the generators of co=
routines.</div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue, Oct =
9, 2018 at 1:05 PM <<a rel=3D"nofollow">eulo...@live.com</a>> wrote:<=
br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;borde=
r-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>I think it is=
painful and noisy to write iterators in order to support range-for loop.</=
div><div><br></div><div>Here are my reasons:</div><div>1: semantics of rang=
e-for loop are not necessarily equivalent to access every iterator in the r=
ange.</div><div>2: For many containers, defining iterators are harder than =
defining the range-for loop directly.</div><div>3: It is painful to write i=
terators to support simple data structures.</div><div>4: For containers lik=
e std::deque, std::set, std::map and even lists, using iterators to=C2=A0tr=
averse the entire container lose a huge amount of performance compared to d=
efine a universal for_each function.</div><div><br></div><div>For example, =
if I have a binary search tree:</div><div><br></div><div>template<typena=
me T></div><div>class bst</div><div>{<br></div><div>};</div><div><br></d=
iv><div><br></div><div>template<typename T,typename Callback></div><d=
iv>void inorder_traverse(const bstnode<T> *p,Callback &&F)</d=
iv><div>{</div><div><span style=3D"white-space:pre-wrap"> </span>if(p->l=
eft())</div><div><span style=3D"white-space:pre-wrap"> </span>inorder_trav=
el(p->left(),F);</div><div><span style=3D"white-space:pre-wrap"> </span>=
F(p->value());</div><div><span style=3D"white-space:pre-wrap"> </span>if=
(p->right())</div><div><span style=3D"white-space:pre-wrap"> </span>ino=
rder_travel(p->right(),F);</div><div>}</div><div>template<typename T,=
typename Callback></div><div>inline void for_each(const bst<T> &am=
p;t,Callback &&F)</div><div>{</div><div><span style=3D"white-space:=
pre-wrap"> </span>if(t.root())</div><div><span style=3D"white-space:pre-wra=
p"> </span>inorder_traverse(t.root(),std:<wbr>:forward<Callback>(F))=
;</div><div>}</div><div><br></div><div><br></div><div><br></div><div>bst<=
;std::size_t> b;=C2=A0</div><div>std::size_t sum(0);<br></div><div>for(c=
onst auto &ele : b)=C2=A0 =C2=A0 // will check whether the "for_ea=
ch" function is defined for the container. If it does have one, call t=
his first.<br></div><div>=C2=A0 =C2=A0 sum+=3Dele;</div><div><br></div><div=
>this will be equivalent to:</div><div><br></div><div><div>bst<std::size=
_t> b;=C2=A0</div><div>std::size_t sum(0);<br></div><div>for_each(b,[&am=
p;](const auto &ele)</div></div><div>{</div><div>=C2=A0 =C2=A0 sum+=3De=
le;<br></div><div>});</div><div><br></div></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/9ba3d13b-3044-4223-<wbr>afd0-=
218e8ba06893%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/88165d50-83b4-4067-<wbr>bec3-=
7c7dab15dce3%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/7b76fd5e-f3c3-4952-af81-3435456f48b7%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/7b76fd5e-f3c3-4952-af81-3435456f48b7%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/7b76fd5e-f3c3-4952-af81-3435456f48b7%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/7b76fd5e-f3c3-4952-<wbr>af81-=
3435456f48b7%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div></div>
<p></p>
-- <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"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
gYoPd89cBAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:&=
#39;;return true;" onclick=3D"this.href=3D'javascript:';return true=
;">std-proposal...@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"javascript:" target=3D"_bla=
nk" gdf-obfuscated-mailto=3D"gYoPd89cBAAJ" rel=3D"nofollow" onmousedown=3D"=
this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'=
;javascript:';return true;">std-pr...@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/f2f9e546-638d-4ebb-b0c9-f1eb329717f0%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank" =
rel=3D"nofollow" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/f2f9e546-638d-4ebb-b0c9-f1eb329717f0%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/f2f9e546-638d-4ebb-b0c9-f1eb329717f0%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/f2f9e546-638d-4ebb-<wbr>b0c9-=
f1eb329717f0%40isocpp.org</a><wbr>.<br>
</blockquote></div></div></div>
</blockquote></div>
<p></p>
-- <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+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/63319859-3f0a-4799-90e9-fd699ee89f29%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/63319859-3f0a-4799-90e9-fd699ee89f29=
%40isocpp.org</a>.<br />
------=_Part_1916_129801295.1539089261416--
------=_Part_1915_923829433.1539089261415--
.
Author: =?UTF-8?B?R2HFoXBlciBBxb5tYW4=?= <gasper.azman@gmail.com>
Date: Tue, 9 Oct 2018 13:47:49 +0100
Raw View
--000000000000d8b84d0577cb2571
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
I really don't see how this applies to generators from the coroutines TS,
and also how nested loops can somehow be written differently as a function
vs an iterator comparison.
On Tue, Oct 9, 2018 at 1:45 PM <florian.csdt@gmail.com> wrote:
> There are cases where a for_each can be better/faster(/stronger) than
> ranges: nested loops.
>
> Emulating nested loops with ranges is slow because for each ++, the
> iterator has to check if it has reached the end of the inner loop or not.
>
> Le mardi 9 octobre 2018 14:28:38 UTC+2, Ga=C5=A1per A=C5=BEman a =C3=A9cr=
it :
>>
>> Adding customization points to the language is a "you better have a
>> really really good reason" kind of thing. If another feature already
>> provides a way to hook into already existing features without an additio=
nal
>> customization point, you'd expect the standard to avoid adding
>> customization points.
>>
>> In this case, it's easy to see how
>>
>> for (auto range =3D x.in_order_traversal(); auto& element : range) {
>> element +=3D 1;
>> }
>>
>> does its job just fine, without an extra customization point.
>>
>> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/71498824-6a5=
b-40ba-84db-4d4df72e2c94%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/71498824-6a=
5b-40ba-84db-4d4df72e2c94%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoot=
er>
> .
>
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/CAANG%3DkWEU3M8xS7dLkzTzgtucrtyuoGU5koUs4i3ya2Oe=
Gh-QA%40mail.gmail.com.
--000000000000d8b84d0577cb2571
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I really don't see how this applies to generators from=
the coroutines TS, and also how nested loops can somehow be written differ=
ently as a function vs an iterator comparison.</div><br><div class=3D"gmail=
_quote"><div dir=3D"ltr">On Tue, Oct 9, 2018 at 1:45 PM <<a href=3D"mail=
to:florian.csdt@gmail.com">florian.csdt@gmail.com</a>> wrote:<br></div><=
blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px=
#ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>There are cases where a=
for_each can be better/faster(/stronger) than ranges: nested loops.</div><=
div><br></div><div>Emulating nested loops with ranges is slow because for e=
ach ++, the iterator has to check if it has reached the end of the inner lo=
op or not.<br></div><br>Le mardi 9 octobre 2018 14:28:38 UTC+2, Ga=C5=A1per=
A=C5=BEman a =C3=A9crit=C2=A0:<blockquote class=3D"gmail_quote" style=3D"m=
argin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div=
dir=3D"ltr">Adding customization points to the language is a "you bet=
ter have a really really good reason" kind of thing. If another featur=
e already provides a way to hook into already existing features without an =
additional customization point, you'd expect the standard to avoid addi=
ng customization points.<div><br></div><div>In this case, it's easy to =
see how</div><div><br></div><div>for (auto range =3D x.in_order_traversal()=
; auto& element : range) {</div><div>=C2=A0 =C2=A0element=C2=A0+=3D 1;<=
/div><div>}</div><div><br></div><div>does its job just fine, without an ext=
ra customization point.</div><div><br></div></div></blockquote></div>
<p></p>
-- <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+unsubscribe@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>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/71498824-6a5b-40ba-84db-4d4df72e2c94%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/71498824-6a5b-=
40ba-84db-4d4df72e2c94%40isocpp.org</a>.<br>
</blockquote></div>
<p></p>
-- <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+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkWEU3M8xS7dLkzTzgtucrtyuoGU5k=
oUs4i3ya2OeGh-QA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkWEU3M8=
xS7dLkzTzgtucrtyuoGU5koUs4i3ya2OeGh-QA%40mail.gmail.com</a>.<br />
--000000000000d8b84d0577cb2571--
.
Author: euloanty@live.com
Date: Tue, 9 Oct 2018 05:50:53 -0700 (PDT)
Raw View
------=_Part_2137_1316936607.1539089453455
Content-Type: multipart/alternative;
boundary="----=_Part_2138_1193287821.1539089453455"
------=_Part_2138_1193287821.1539089453455
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
maybe it requires a std::range(C) just like std::begin(C), std::end(C). The=
=20
for-each loop will call std::range(C) to extend the code to that code you=
=20
write before.
On Tuesday, October 9, 2018 at 8:44:17 PM UTC+8, Ga=C5=A1per A=C5=BEman wro=
te:
>
> By returning a fat iterator that encapsulates the generator from begin(),=
=20
> and a sentinel that checks it against the generator's end() from end(). I=
t=20
> only takes a few lines of code, and I bet boost can provide a facade that=
=20
> vanishes in codegen pretty easily.
>
> Or, you know, just use std::for_each and expect it to be customized for=
=20
> your type if you want generic code.
>
> That said, feel free to propose this, but I personally don't see enough=
=20
> justification to reserve yet another name in the language, because that's=
=20
> what the current customization points do.
>
> G
>
>
>
> On Tue, Oct 9, 2018 at 1:38 PM <eulo...@live.com <javascript:>> wrote:
>
>> But, how could you define range-for loop for the type directly (for=20
>> example like std::deque) instead of using a coroutine of that type.
>>
>> std::deque<int> d;
>> std::size_t sum(0):
>> for(const auto &ele : d)
>> sum+=3D0;
>>
>> If you can't, it would be painful to write this for generic code?
>>
>>
>> On Tuesday, October 9, 2018 at 8:28:38 PM UTC+8, Ga=C5=A1per A=C5=BEman =
wrote:
>>>
>>> Adding customization points to the language is a "you better have a=20
>>> really really good reason" kind of thing. If another feature already=20
>>> provides a way to hook into already existing features without an additi=
onal=20
>>> customization point, you'd expect the standard to avoid adding=20
>>> customization points.
>>>
>>> In this case, it's easy to see how
>>>
>>> for (auto range =3D x.in_order_traversal(); auto& element : range) {
>>> element +=3D 1;
>>> }
>>>
>>> does its job just fine, without an extra customization point.
>>>
>>>
>>>
>>> On Tue, Oct 9, 2018 at 1:23 PM <eulo...@live.com> wrote:
>>>
>>>> also, std::for_each is a function already defined in the standard=20
>>>> library, calling this won't add anything compared to add coroutine.
>>>>
>>>> On Tuesday, October 9, 2018 at 8:14:36 PM UTC+8, Ga=C5=A1per A=C5=BEma=
n wrote:
>>>>>
>>>>> In the generator case it gets optimized away in most cases, and in=20
>>>>> others its only the price of a (predicted) function call. No differen=
t than=20
>>>>> calling a for_each with a synthesized lambda that you invoke on every=
=20
>>>>> element.
>>>>>
>>>>> On Tue, Oct 9, 2018 at 1:13 PM <eulo...@live.com> wrote:
>>>>>
>>>>>> But context swapping is slow.
>>>>>>
>>>>>> On Tuesday, October 9, 2018 at 8:07:35 PM UTC+8, Ga=C5=A1per A=C5=BE=
man wrote:
>>>>>>>
>>>>>>> The solution for this is already targeted by the generators of=20
>>>>>>> coroutines.
>>>>>>>
>>>>>>> On Tue, Oct 9, 2018 at 1:05 PM <eulo...@live.com> wrote:
>>>>>>>
>>>>>>>> I think it is painful and noisy to write iterators in order to=20
>>>>>>>> support range-for loop.
>>>>>>>>
>>>>>>>> Here are my reasons:
>>>>>>>> 1: semantics of range-for loop are not necessarily equivalent to=
=20
>>>>>>>> access every iterator in the range.
>>>>>>>> 2: For many containers, defining iterators are harder than definin=
g=20
>>>>>>>> the range-for loop directly.
>>>>>>>> 3: It is painful to write iterators to support simple data=20
>>>>>>>> structures.
>>>>>>>> 4: For containers like std::deque, std::set, std::map and even=20
>>>>>>>> lists, using iterators to traverse the entire container lose a hug=
e amount=20
>>>>>>>> of performance compared to define a universal for_each function.
>>>>>>>>
>>>>>>>> For example, if I have a binary search tree:
>>>>>>>>
>>>>>>>> template<typename T>
>>>>>>>> class bst
>>>>>>>> {
>>>>>>>> };
>>>>>>>>
>>>>>>>>
>>>>>>>> template<typename T,typename Callback>
>>>>>>>> void inorder_traverse(const bstnode<T> *p,Callback &&F)
>>>>>>>> {
>>>>>>>> if(p->left())
>>>>>>>> inorder_travel(p->left(),F);
>>>>>>>> F(p->value());
>>>>>>>> if(p->right())
>>>>>>>> inorder_travel(p->right(),F);
>>>>>>>> }
>>>>>>>> template<typename T,typename Callback>
>>>>>>>> inline void for_each(const bst<T> &t,Callback &&F)
>>>>>>>> {
>>>>>>>> if(t.root())
>>>>>>>> inorder_traverse(t.root(),std::forward<Callback>(F));
>>>>>>>> }
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> bst<std::size_t> b;=20
>>>>>>>> std::size_t sum(0);
>>>>>>>> for(const auto &ele : b) // will check whether the "for_each"=
=20
>>>>>>>> function is defined for the container. If it does have one, call t=
his first.
>>>>>>>> sum+=3Dele;
>>>>>>>>
>>>>>>>> this will be equivalent to:
>>>>>>>>
>>>>>>>> bst<std::size_t> b;=20
>>>>>>>> std::size_t sum(0);
>>>>>>>> for_each(b,[&](const auto &ele)
>>>>>>>> {
>>>>>>>> sum+=3Dele;
>>>>>>>> });
>>>>>>>>
>>>>>>>> --=20
>>>>>>>> You received this message because you are subscribed to the Google=
=20
>>>>>>>> Groups "ISO C++ Standard - Future Proposals" group.
>>>>>>>> To unsubscribe from this group and stop receiving emails from it,=
=20
>>>>>>>> send an email to std-proposal...@isocpp.org.
>>>>>>>> To post to this group, send email to std-pr...@isocpp.org.
>>>>>>>> To view this discussion on the web visit=20
>>>>>>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba3d=
13b-3044-4223-afd0-218e8ba06893%40isocpp.org=20
>>>>>>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba3=
d13b-3044-4223-afd0-218e8ba06893%40isocpp.org?utm_medium=3Demail&utm_source=
=3Dfooter>
>>>>>>>> .
>>>>>>>>
>>>>>>> --=20
>>>>>> You received this message because you are subscribed to the Google=
=20
>>>>>> Groups "ISO C++ Standard - Future Proposals" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it,=20
>>>>>> send an email to std-proposal...@isocpp.org.
>>>>>> To post to this group, send email to std-pr...@isocpp.org.
>>>>>> To view this discussion on the web visit=20
>>>>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/88165d5=
0-83b4-4067-bec3-7c7dab15dce3%40isocpp.org=20
>>>>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/88165d=
50-83b4-4067-bec3-7c7dab15dce3%40isocpp.org?utm_medium=3Demail&utm_source=
=3Dfooter>
>>>>>> .
>>>>>>
>>>>> --=20
>>>> You received this message because you are subscribed to the Google=20
>>>> Groups "ISO C++ Standard - Future Proposals" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send=
=20
>>>> an email to std-proposal...@isocpp.org.
>>>> To post to this group, send email to std-pr...@isocpp.org.
>>>> To view this discussion on the web visit=20
>>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/7b76fd5e-=
f3c3-4952-af81-3435456f48b7%40isocpp.org=20
>>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/7b76fd5e=
-f3c3-4952-af81-3435456f48b7%40isocpp.org?utm_medium=3Demail&utm_source=3Df=
ooter>
>>>> .
>>>>
>>> --=20
>> You received this message because you are subscribed to the Google Group=
s=20
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n=20
>> email to std-proposal...@isocpp.org <javascript:>.
>> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
>> To view this discussion on the web visit=20
>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/f2f9e546-63=
8d-4ebb-b0c9-f1eb329717f0%40isocpp.org=20
>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/f2f9e546-6=
38d-4ebb-b0c9-f1eb329717f0%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoo=
ter>
>> .
>>
>
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/4f86006c-d601-4b47-8346-664e58ed2c85%40isocpp.or=
g.
------=_Part_2138_1193287821.1539089453455
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">maybe it requires a std::range(C) just like std::begin(C),=
std::end(C). The for-each loop will call std::range(C) to extend the code =
to that code you write before.<br><br>On Tuesday, October 9, 2018 at 8:44:1=
7 PM UTC+8, Ga=C5=A1per A=C5=BEman wrote:<blockquote class=3D"gmail_quote" =
style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-l=
eft: 1ex;"><div dir=3D"ltr">By returning a fat iterator that encapsulates t=
he generator from begin(), and a sentinel that checks it against the genera=
tor's end() from end(). It only takes a few lines of code, and I bet bo=
ost can provide a facade that vanishes in codegen pretty easily.<div><br></=
div><div>Or, you know, just use std::for_each and expect it to be customize=
d for your type if you want generic code.</div><div><br></div><div>That sai=
d, feel free to propose this, but I personally don't see enough justifi=
cation to reserve yet another name in the language, because that's what=
the current customization points do.</div><div><br></div><div>G<br><div><b=
r></div><div><br></div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On T=
ue, Oct 9, 2018 at 1:38 PM <<a href=3D"javascript:" target=3D"_blank" gd=
f-obfuscated-mailto=3D"gYoPd89cBAAJ" rel=3D"nofollow" onmousedown=3D"this.h=
ref=3D'javascript:';return true;" onclick=3D"this.href=3D'javas=
cript:';return true;">eulo...@live.com</a>> wrote:<br></div><blockqu=
ote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc s=
olid;padding-left:1ex"><div dir=3D"ltr"><div><div>But, how could you define=
range-for loop for the type directly (for example like std::deque) instead=
of using a coroutine=C2=A0of that type.<br></div></div><div><br></div><div=
>std::deque<int> d;</div><div>std::size_t sum(0):</div><div>for(const=
auto &ele : d)<br></div><div>=C2=A0 =C2=A0sum+=3D0;</div><div><br></di=
v><div>If you can't, it would be=C2=A0painful to write this for generic=
code?</div><div><br></div><div><br></div><div>On Tuesday, October 9, 2018 =
at 8:28:38 PM UTC+8, Ga=C5=A1per A=C5=BEman wrote:<blockquote class=3D"gmai=
l_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;pad=
ding-left:1ex"><div dir=3D"ltr">Adding customization points to the language=
is a "you better have a really really good reason" kind of thing=
.. If another feature already provides a way to hook into already existing f=
eatures without an additional customization point, you'd expect the sta=
ndard to avoid adding customization points.<div><br></div><div>In this case=
, it's easy to see how</div><div><br></div><div>for (auto range =3D x.i=
n_order_traversal(); auto& element : range) {</div><div>=C2=A0 =C2=A0el=
ement=C2=A0+=3D 1;</div><div>}</div><div><br></div><div>does its job just f=
ine, without an extra customization point.</div><div><br></div><div><br></d=
iv></div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue, Oct 9, 201=
8 at 1:23 PM <<a rel=3D"nofollow">eulo...@live.com</a>> wrote:<br></d=
iv><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left=
:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">also, std::for_each is a=
function already defined in the standard library, calling this won't a=
dd anything compared to add coroutine.<br><br>On Tuesday, October 9, 2018 a=
t 8:14:36 PM UTC+8, Ga=C5=A1per A=C5=BEman wrote:<blockquote class=3D"gmail=
_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padd=
ing-left:1ex"><div dir=3D"ltr">In the generator case it gets optimized away=
in most cases, and in others its only the price of a (predicted) function =
call. No different than calling a for_each with a synthesized lambda that y=
ou invoke on every element.</div><br><div class=3D"gmail_quote"><div dir=3D=
"ltr">On Tue, Oct 9, 2018 at 1:13 PM <<a rel=3D"nofollow">eulo...@live.c=
om</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margi=
n:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">=
But context swapping is slow.<br><br>On Tuesday, October 9, 2018 at 8:07:35=
PM UTC+8, Ga=C5=A1per A=C5=BEman wrote:<blockquote class=3D"gmail_quote" s=
tyle=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:=
1ex"><div dir=3D"ltr">The solution for this is already targeted by the gene=
rators of coroutines.</div><br><div class=3D"gmail_quote"><div dir=3D"ltr">=
On Tue, Oct 9, 2018 at 1:05 PM <<a rel=3D"nofollow">eulo...@live.com</a>=
> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 =
0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>I=
think it is painful and noisy to write iterators in order to support range=
-for loop.</div><div><br></div><div>Here are my reasons:</div><div>1: seman=
tics of range-for loop are not necessarily equivalent to access every itera=
tor in the range.</div><div>2: For many containers, defining iterators are =
harder than defining the range-for loop directly.</div><div>3: It is painfu=
l to write iterators to support simple data structures.</div><div>4: For co=
ntainers like std::deque, std::set, std::map and even lists, using iterator=
s to=C2=A0traverse the entire container lose a huge amount of performance c=
ompared to define a universal for_each function.</div><div><br></div><div>F=
or example, if I have a binary search tree:</div><div><br></div><div>templa=
te<typename T></div><div>class bst</div><div>{<br></div><div>};</div>=
<div><br></div><div><br></div><div>template<typename T,typename Callback=
></div><div>void inorder_traverse(const bstnode<T> *p,Callback &am=
p;&F)</div><div>{</div><div><span style=3D"white-space:pre-wrap"> </spa=
n>if(p->left())</div><div><span style=3D"white-space:pre-wrap"> </span>=
inorder_travel(p->left(),F);</div><div><span style=3D"white-space:pre-wr=
ap"> </span>F(p->value());</div><div><span style=3D"white-space:pre-wrap=
"> </span>if(p->right())</div><div><span style=3D"white-space:pre-wrap">=
</span>inorder_travel(p->right(),F);</div><div>}</div><div>template<=
;typename T,typename Callback></div><div>inline void for_each(const bst&=
lt;T> &t,Callback &&F)</div><div>{</div><div><span style=3D"=
white-space:pre-wrap"> </span>if(t.root())</div><div><span style=3D"white-s=
pace:pre-wrap"> </span>inorder_traverse(t.root(),std:<wbr>:forward<Call=
back>(F));</div><div>}</div><div><br></div><div><br></div><div><br></div=
><div>bst<std::size_t> b;=C2=A0</div><div>std::size_t sum(0);<br></di=
v><div>for(const auto &ele : b)=C2=A0 =C2=A0 // will check whether the =
"for_each" function is defined for the container. If it does have=
one, call this first.<br></div><div>=C2=A0 =C2=A0 sum+=3Dele;</div><div><b=
r></div><div>this will be equivalent to:</div><div><br></div><div><div>bst&=
lt;std::size_t> b;=C2=A0</div><div>std::size_t sum(0);<br></div><div>for=
_each(b,[&](const auto &ele)</div></div><div>{</div><div>=C2=A0 =C2=
=A0 sum+=3Dele;<br></div><div>});</div><div><br></div></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/9ba3d13b-3044-4223-<wbr>afd0-=
218e8ba06893%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/88165d50-83b4-4067-<wbr>bec3-=
7c7dab15dce3%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/7b76fd5e-f3c3-4952-af81-3435456f48b7%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/7b76fd5e-f3c3-4952-af81-3435456f48b7%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/7b76fd5e-f3c3-4952-af81-3435456f48b7%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/7b76fd5e-f3c3-4952-<wbr>af81-=
3435456f48b7%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div></div>
<p></p>
-- <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"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
gYoPd89cBAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:&=
#39;;return true;" onclick=3D"this.href=3D'javascript:';return true=
;">std-proposal...@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"javascript:" target=3D"_bla=
nk" gdf-obfuscated-mailto=3D"gYoPd89cBAAJ" rel=3D"nofollow" onmousedown=3D"=
this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'=
;javascript:';return true;">std-pr...@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/f2f9e546-638d-4ebb-b0c9-f1eb329717f0%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank" =
rel=3D"nofollow" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/f2f9e546-638d-4ebb-b0c9-f1eb329717f0%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/f2f9e546-638d-4ebb-b0c9-f1eb329717f0%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/f2f9e546-638d-4ebb-<wbr>b0c9-=
f1eb329717f0%40isocpp.org</a><wbr>.<br>
</blockquote></div></div></div>
</blockquote></div>
<p></p>
-- <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+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/4f86006c-d601-4b47-8346-664e58ed2c85%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/4f86006c-d601-4b47-8346-664e58ed2c85=
%40isocpp.org</a>.<br />
------=_Part_2138_1193287821.1539089453455--
------=_Part_2137_1316936607.1539089453455--
.
Author: =?UTF-8?B?R2HFoXBlciBBxb5tYW4=?= <gasper.azman@gmail.com>
Date: Tue, 9 Oct 2018 13:51:40 +0100
Raw View
--0000000000009e28dd0577cb336f
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On Tue, Oct 9, 2018 at 1:47 PM <euloanty@live.com> wrote:
> I don't think it is the point about coroutine. It is about the interface
> for containers of range-for loop. The current standard must use iterators
> for containers to iterator the entire container.
>
Yes, that's the point. The ranged for is not a magic construct, it uses the
standard interface. Let's not add another interface.
> You have to define a standard interface for this in order for all
> containers to write customized code to support these kinds of usage which
> is lacking in the standard. No matter you use coroutine or for-each, it
> won't solve the issue directly.
>
It does - you can easily write a facade that will implement your begin()
and end() directly on the container, if you want. My suggestion was that
putting that facade into boost to wrap a simple coroutine that yields
references to successive elements is a relatively simple exercise and it
*solves your problem* without introducing a separate way to interpret
ranged for-loops that may actually break code because it prefers the new
interface.
>
> On Tuesday, October 9, 2018 at 8:44:17 PM UTC+8, Ga=C5=A1per A=C5=BEman w=
rote:
>>
>> By returning a fat iterator that encapsulates the generator from begin()=
,
>> and a sentinel that checks it against the generator's end() from end(). =
It
>> only takes a few lines of code, and I bet boost can provide a facade tha=
t
>> vanishes in codegen pretty easily.
>>
>> Or, you know, just use std::for_each and expect it to be customized for
>> your type if you want generic code.
>>
>> That said, feel free to propose this, but I personally don't see enough
>> justification to reserve yet another name in the language, because that'=
s
>> what the current customization points do.
>>
>> G
>>
>>
>>
>> On Tue, Oct 9, 2018 at 1:38 PM <eulo...@live.com> wrote:
>>
>>> But, how could you define range-for loop for the type directly (for
>>> example like std::deque) instead of using a coroutine of that type.
>>>
>>> std::deque<int> d;
>>> std::size_t sum(0):
>>> for(const auto &ele : d)
>>> sum+=3D0;
>>>
>>> If you can't, it would be painful to write this for generic code?
>>>
>>>
>>> On Tuesday, October 9, 2018 at 8:28:38 PM UTC+8, Ga=C5=A1per A=C5=BEman=
wrote:
>>>>
>>>> Adding customization points to the language is a "you better have a
>>>> really really good reason" kind of thing. If another feature already
>>>> provides a way to hook into already existing features without an addit=
ional
>>>> customization point, you'd expect the standard to avoid adding
>>>> customization points.
>>>>
>>>> In this case, it's easy to see how
>>>>
>>>> for (auto range =3D x.in_order_traversal(); auto& element : range) {
>>>> element +=3D 1;
>>>> }
>>>>
>>>> does its job just fine, without an extra customization point.
>>>>
>>>>
>>>>
>>>> On Tue, Oct 9, 2018 at 1:23 PM <eulo...@live.com> wrote:
>>>>
>>>>> also, std::for_each is a function already defined in the standard
>>>>> library, calling this won't add anything compared to add coroutine.
>>>>>
>>>>> On Tuesday, October 9, 2018 at 8:14:36 PM UTC+8, Ga=C5=A1per A=C5=BEm=
an wrote:
>>>>>>
>>>>>> In the generator case it gets optimized away in most cases, and in
>>>>>> others its only the price of a (predicted) function call. No differe=
nt than
>>>>>> calling a for_each with a synthesized lambda that you invoke on ever=
y
>>>>>> element.
>>>>>>
>>>>>> On Tue, Oct 9, 2018 at 1:13 PM <eulo...@live.com> wrote:
>>>>>>
>>>>>>> But context swapping is slow.
>>>>>>>
>>>>>>> On Tuesday, October 9, 2018 at 8:07:35 PM UTC+8, Ga=C5=A1per A=C5=
=BEman wrote:
>>>>>>>>
>>>>>>>> The solution for this is already targeted by the generators of
>>>>>>>> coroutines.
>>>>>>>>
>>>>>>>> On Tue, Oct 9, 2018 at 1:05 PM <eulo...@live.com> wrote:
>>>>>>>>
>>>>>>>>> I think it is painful and noisy to write iterators in order to
>>>>>>>>> support range-for loop.
>>>>>>>>>
>>>>>>>>> Here are my reasons:
>>>>>>>>> 1: semantics of range-for loop are not necessarily equivalent to
>>>>>>>>> access every iterator in the range.
>>>>>>>>> 2: For many containers, defining iterators are harder than
>>>>>>>>> defining the range-for loop directly.
>>>>>>>>> 3: It is painful to write iterators to support simple data
>>>>>>>>> structures.
>>>>>>>>> 4: For containers like std::deque, std::set, std::map and even
>>>>>>>>> lists, using iterators to traverse the entire container lose a hu=
ge amount
>>>>>>>>> of performance compared to define a universal for_each function.
>>>>>>>>>
>>>>>>>>> For example, if I have a binary search tree:
>>>>>>>>>
>>>>>>>>> template<typename T>
>>>>>>>>> class bst
>>>>>>>>> {
>>>>>>>>> };
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> template<typename T,typename Callback>
>>>>>>>>> void inorder_traverse(const bstnode<T> *p,Callback &&F)
>>>>>>>>> {
>>>>>>>>> if(p->left())
>>>>>>>>> inorder_travel(p->left(),F);
>>>>>>>>> F(p->value());
>>>>>>>>> if(p->right())
>>>>>>>>> inorder_travel(p->right(),F);
>>>>>>>>> }
>>>>>>>>> template<typename T,typename Callback>
>>>>>>>>> inline void for_each(const bst<T> &t,Callback &&F)
>>>>>>>>> {
>>>>>>>>> if(t.root())
>>>>>>>>> inorder_traverse(t.root(),std::forward<Callback>(F));
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> bst<std::size_t> b;
>>>>>>>>> std::size_t sum(0);
>>>>>>>>> for(const auto &ele : b) // will check whether the "for_each"
>>>>>>>>> function is defined for the container. If it does have one, call =
this first.
>>>>>>>>> sum+=3Dele;
>>>>>>>>>
>>>>>>>>> this will be equivalent to:
>>>>>>>>>
>>>>>>>>> bst<std::size_t> b;
>>>>>>>>> std::size_t sum(0);
>>>>>>>>> for_each(b,[&](const auto &ele)
>>>>>>>>> {
>>>>>>>>> sum+=3Dele;
>>>>>>>>> });
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> You received this message because you are subscribed to the Googl=
e
>>>>>>>>> Groups "ISO C++ Standard - Future Proposals" group.
>>>>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>>>>> send an email to std-proposal...@isocpp.org.
>>>>>>>>> To post to this group, send email to std-pr...@isocpp.org.
>>>>>>>>> To view this discussion on the web visit
>>>>>>>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba3=
d13b-3044-4223-afd0-218e8ba06893%40isocpp.org
>>>>>>>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba=
3d13b-3044-4223-afd0-218e8ba06893%40isocpp.org?utm_medium=3Demail&utm_sourc=
e=3Dfooter>
>>>>>>>>> .
>>>>>>>>>
>>>>>>>> --
>>>>>>> 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-proposal...@isocpp.org.
>>>>>>> To post to this group, send email to std-pr...@isocpp.org.
>>>>>>> To view this discussion on the web visit
>>>>>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/88165d=
50-83b4-4067-bec3-7c7dab15dce3%40isocpp.org
>>>>>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/88165=
d50-83b4-4067-bec3-7c7dab15dce3%40isocpp.org?utm_medium=3Demail&utm_source=
=3Dfooter>
>>>>>>> .
>>>>>>>
>>>>>> --
>>>>> 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, sen=
d
>>>>> an email to std-proposal...@isocpp.org.
>>>>> To post to this group, send email to std-pr...@isocpp.org.
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/7b76fd5e=
-f3c3-4952-af81-3435456f48b7%40isocpp.org
>>>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/7b76fd5=
e-f3c3-4952-af81-3435456f48b7%40isocpp.org?utm_medium=3Demail&utm_source=3D=
footer>
>>>>> .
>>>>>
>>>> --
>>> 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-proposal...@isocpp.org.
>>> To post to this group, send email to std-pr...@isocpp.org.
>>> To view this discussion on the web visit
>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/f2f9e546-6=
38d-4ebb-b0c9-f1eb329717f0%40isocpp.org
>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/f2f9e546-=
638d-4ebb-b0c9-f1eb329717f0%40isocpp.org?utm_medium=3Demail&utm_source=3Dfo=
oter>
>>> .
>>>
>> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/63319859-3f0=
a-4799-90e9-fd699ee89f29%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/63319859-3f=
0a-4799-90e9-fd699ee89f29%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoot=
er>
> .
>
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/CAANG%3DkVpGt-RcmmFZ%3D3NGQrW2KwFOSb92t3WqaviWY5=
VsBQmfQ%40mail.gmail.com.
--0000000000009e28dd0577cb336f
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue=
, Oct 9, 2018 at 1:47 PM <<a href=3D"mailto:euloanty@live.com">euloanty@=
live.com</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D=
"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D=
"ltr">I don't think it is the point about coroutine. It is about the in=
terface for containers of range-for loop. The current standard must use ite=
rators for containers to iterator the entire container.</div></blockquote><=
div>Yes, that's the point. The ranged for is not a magic construct, it =
uses the standard interface. Let's not add another interface.</div><div=
>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;b=
order-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">You have to de=
fine a standard interface for this in order for all containers to write cus=
tomized code to support these kinds of usage which is lacking in the standa=
rd. No matter you use coroutine or for-each, it won't solve the issue d=
irectly.<br></div></blockquote><div>It does - you can easily write a facade=
that will implement your begin() and end() directly on the container, if y=
ou want. My suggestion was that putting that facade into boost to wrap a si=
mple coroutine that yields references to successive elements is a relativel=
y simple exercise and it *solves your problem* without introducing a separa=
te way to interpret ranged for-loops that may actually break code because i=
t prefers the new interface.</div><div>=C2=A0</div><blockquote class=3D"gma=
il_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-lef=
t:1ex"><div dir=3D"ltr"><br>On Tuesday, October 9, 2018 at 8:44:17 PM UTC+8=
, Ga=C5=A1per A=C5=BEman wrote:<blockquote class=3D"gmail_quote" style=3D"m=
argin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div=
dir=3D"ltr">By returning a fat iterator that encapsulates the generator fr=
om begin(), and a sentinel that checks it against the generator's end()=
from end(). It only takes a few lines of code, and I bet boost can provide=
a facade that vanishes in codegen pretty easily.<div><br></div><div>Or, yo=
u know, just use std::for_each and expect it to be customized for your type=
if you want generic code.</div><div><br></div><div>That said, feel free to=
propose this, but I personally don't see enough justification to reser=
ve yet another name in the language, because that's what the current cu=
stomization points do.</div><div><br></div><div>G<br><div><br></div><div><b=
r></div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue, Oct 9, 2018=
at 1:38 PM <<a rel=3D"nofollow">eulo...@live.com</a>> wrote:<br></di=
v><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:=
1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div>But, how could =
you define range-for loop for the type directly (for example like std::dequ=
e) instead of using a coroutine=C2=A0of that type.<br></div></div><div><br>=
</div><div>std::deque<int> d;</div><div>std::size_t sum(0):</div><div=
>for(const auto &ele : d)<br></div><div>=C2=A0 =C2=A0sum+=3D0;</div><di=
v><br></div><div>If you can't, it would be=C2=A0painful to write this f=
or generic code?</div><div><br></div><div><br></div><div>On Tuesday, Octobe=
r 9, 2018 at 8:28:38 PM UTC+8, Ga=C5=A1per A=C5=BEman wrote:<blockquote cla=
ss=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc=
solid;padding-left:1ex"><div dir=3D"ltr">Adding customization points to th=
e language is a "you better have a really really good reason" kin=
d of thing. If another feature already provides a way to hook into already =
existing features without an additional customization point, you'd expe=
ct the standard to avoid adding customization points.<div><br></div><div>In=
this case, it's easy to see how</div><div><br></div><div>for (auto ran=
ge =3D x.in_order_traversal(); auto& element : range) {</div><div>=C2=
=A0 =C2=A0element=C2=A0+=3D 1;</div><div>}</div><div><br></div><div>does it=
s job just fine, without an extra customization point.</div><div><br></div>=
<div><br></div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue=
, Oct 9, 2018 at 1:23 PM <<a rel=3D"nofollow">eulo...@live.com</a>> w=
rote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex=
;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">also, std::f=
or_each is a function already defined in the standard library, calling this=
won't add anything compared to add coroutine.<br><br>On Tuesday, Octob=
er 9, 2018 at 8:14:36 PM UTC+8, Ga=C5=A1per A=C5=BEman wrote:<blockquote cl=
ass=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #cc=
c solid;padding-left:1ex"><div dir=3D"ltr">In the generator case it gets op=
timized away in most cases, and in others its only the price of a (predicte=
d) function call. No different than calling a for_each with a synthesized l=
ambda that you invoke on every element.</div><br><div class=3D"gmail_quote"=
><div dir=3D"ltr">On Tue, Oct 9, 2018 at 1:13 PM <<a rel=3D"nofollow">eu=
lo...@live.com</a>> wrote:<br></div><blockquote class=3D"gmail_quote" st=
yle=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div =
dir=3D"ltr">But context swapping is slow.<br><br>On Tuesday, October 9, 201=
8 at 8:07:35 PM UTC+8, Ga=C5=A1per A=C5=BEman wrote:<blockquote class=3D"gm=
ail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;p=
adding-left:1ex"><div dir=3D"ltr">The solution for this is already targeted=
by the generators of coroutines.</div><br><div class=3D"gmail_quote"><div =
dir=3D"ltr">On Tue, Oct 9, 2018 at 1:05 PM <<a rel=3D"nofollow">eulo...@=
live.com</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D=
"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D=
"ltr"><div>I think it is painful and noisy to write iterators in order to s=
upport range-for loop.</div><div><br></div><div>Here are my reasons:</div><=
div>1: semantics of range-for loop are not necessarily equivalent to access=
every iterator in the range.</div><div>2: For many containers, defining it=
erators are harder than defining the range-for loop directly.</div><div>3: =
It is painful to write iterators to support simple data structures.</div><d=
iv>4: For containers like std::deque, std::set, std::map and even lists, us=
ing iterators to=C2=A0traverse the entire container lose a huge amount of p=
erformance compared to define a universal for_each function.</div><div><br>=
</div><div>For example, if I have a binary search tree:</div><div><br></div=
><div>template<typename T></div><div>class bst</div><div>{<br></div><=
div>};</div><div><br></div><div><br></div><div>template<typename T,typen=
ame Callback></div><div>void inorder_traverse(const bstnode<T> *p,=
Callback &&F)</div><div>{</div><div><span style=3D"white-space:pre-=
wrap"> </span>if(p->left())</div><div><span style=3D"white-space:pre-wra=
p"> </span>inorder_travel(p->left(),F);</div><div><span style=3D"white-=
space:pre-wrap"> </span>F(p->value());</div><div><span style=3D"white-sp=
ace:pre-wrap"> </span>if(p->right())</div><div><span style=3D"white-spac=
e:pre-wrap"> </span>inorder_travel(p->right(),F);</div><div>}</div><div=
>template<typename T,typename Callback></div><div>inline void for_eac=
h(const bst<T> &t,Callback &&F)</div><div>{</div><div><sp=
an style=3D"white-space:pre-wrap"> </span>if(t.root())</div><div><span styl=
e=3D"white-space:pre-wrap"> </span>inorder_traverse(t.root(),std::forward&=
lt;Callback>(F));</div><div>}</div><div><br></div><div><br></div><div><b=
r></div><div>bst<std::size_t> b;=C2=A0</div><div>std::size_t sum(0);<=
br></div><div>for(const auto &ele : b)=C2=A0 =C2=A0 // will check wheth=
er the "for_each" function is defined for the container. If it do=
es have one, call this first.<br></div><div>=C2=A0 =C2=A0 sum+=3Dele;</div>=
<div><br></div><div>this will be equivalent to:</div><div><br></div><div><d=
iv>bst<std::size_t> b;=C2=A0</div><div>std::size_t sum(0);<br></div><=
div>for_each(b,[&](const auto &ele)</div></div><div>{</div><div>=C2=
=A0 =C2=A0 sum+=3Dele;<br></div><div>});</div><div><br></div></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank">https://groups.google.com/a/isocpp.org/d/msgid/std-proposa=
ls/9ba3d13b-3044-4223-afd0-218e8ba06893%40isocpp.org</a>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank">https://groups.google.com/a/isocpp.org/d/msgid/std-proposa=
ls/88165d50-83b4-4067-bec3-7c7dab15dce3%40isocpp.org</a>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/7b76fd5e-f3c3-4952-af81-3435456f48b7%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank">https://groups.google.com/a/isocpp.org/d/msgid/std-proposa=
ls/7b76fd5e-f3c3-4952-af81-3435456f48b7%40isocpp.org</a>.<br>
</blockquote></div>
</blockquote></div></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/f2f9e546-638d-4ebb-b0c9-f1eb329717f0%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank">https://groups.google.com/a/isocpp.org/d/msgid/std-proposa=
ls/f2f9e546-638d-4ebb-b0c9-f1eb329717f0%40isocpp.org</a>.<br>
</blockquote></div></div></div>
</blockquote></div>
<p></p>
-- <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+unsubscribe@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>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/63319859-3f0a-4799-90e9-fd699ee89f29%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/63319859-3f0a-=
4799-90e9-fd699ee89f29%40isocpp.org</a>.<br>
</blockquote></div></div>
<p></p>
-- <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+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkVpGt-RcmmFZ%3D3NGQrW2KwFOSb9=
2t3WqaviWY5VsBQmfQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkVpGt=
-RcmmFZ%3D3NGQrW2KwFOSb92t3WqaviWY5VsBQmfQ%40mail.gmail.com</a>.<br />
--0000000000009e28dd0577cb336f--
.
Author: euloanty@live.com
Date: Tue, 9 Oct 2018 06:01:38 -0700 (PDT)
Raw View
------=_Part_2104_1273126576.1539090098657
Content-Type: multipart/alternative;
boundary="----=_Part_2105_567395987.1539090098658"
------=_Part_2105_567395987.1539090098658
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
It won't. std::deque, std::set, std::map they all do not define this.
On Tuesday, October 9, 2018 at 8:51:53 PM UTC+8, Ga=C5=A1per A=C5=BEman wro=
te:
>
>
>
> On Tue, Oct 9, 2018 at 1:47 PM <eulo...@live.com <javascript:>> wrote:
>
>> I don't think it is the point about coroutine. It is about the interface=
=20
>> for containers of range-for loop. The current standard must use iterator=
s=20
>> for containers to iterator the entire container.
>>
> Yes, that's the point. The ranged for is not a magic construct, it uses=
=20
> the standard interface. Let's not add another interface.
> =20
>
>> You have to define a standard interface for this in order for all=20
>> containers to write customized code to support these kinds of usage whic=
h=20
>> is lacking in the standard. No matter you use coroutine or for-each, it=
=20
>> won't solve the issue directly.
>>
> It does - you can easily write a facade that will implement your begin()=
=20
> and end() directly on the container, if you want. My suggestion was that=
=20
> putting that facade into boost to wrap a simple coroutine that yields=20
> references to successive elements is a relatively simple exercise and it=
=20
> *solves your problem* without introducing a separate way to interpret=20
> ranged for-loops that may actually break code because it prefers the new=
=20
> interface.
> =20
>
>>
>> On Tuesday, October 9, 2018 at 8:44:17 PM UTC+8, Ga=C5=A1per A=C5=BEman =
wrote:
>>>
>>> By returning a fat iterator that encapsulates the generator from=20
>>> begin(), and a sentinel that checks it against the generator's end() fr=
om=20
>>> end(). It only takes a few lines of code, and I bet boost can provide a=
=20
>>> facade that vanishes in codegen pretty easily.
>>>
>>> Or, you know, just use std::for_each and expect it to be customized for=
=20
>>> your type if you want generic code.
>>>
>>> That said, feel free to propose this, but I personally don't see enough=
=20
>>> justification to reserve yet another name in the language, because that=
's=20
>>> what the current customization points do.
>>>
>>> G
>>>
>>>
>>>
>>> On Tue, Oct 9, 2018 at 1:38 PM <eulo...@live.com> wrote:
>>>
>>>> But, how could you define range-for loop for the type directly (for=20
>>>> example like std::deque) instead of using a coroutine of that type.
>>>>
>>>> std::deque<int> d;
>>>> std::size_t sum(0):
>>>> for(const auto &ele : d)
>>>> sum+=3D0;
>>>>
>>>> If you can't, it would be painful to write this for generic code?
>>>>
>>>>
>>>> On Tuesday, October 9, 2018 at 8:28:38 PM UTC+8, Ga=C5=A1per A=C5=BEma=
n wrote:
>>>>>
>>>>> Adding customization points to the language is a "you better have a=
=20
>>>>> really really good reason" kind of thing. If another feature already=
=20
>>>>> provides a way to hook into already existing features without an addi=
tional=20
>>>>> customization point, you'd expect the standard to avoid adding=20
>>>>> customization points.
>>>>>
>>>>> In this case, it's easy to see how
>>>>>
>>>>> for (auto range =3D x.in_order_traversal(); auto& element : range) {
>>>>> element +=3D 1;
>>>>> }
>>>>>
>>>>> does its job just fine, without an extra customization point.
>>>>>
>>>>>
>>>>>
>>>>> On Tue, Oct 9, 2018 at 1:23 PM <eulo...@live.com> wrote:
>>>>>
>>>>>> also, std::for_each is a function already defined in the standard=20
>>>>>> library, calling this won't add anything compared to add coroutine.
>>>>>>
>>>>>> On Tuesday, October 9, 2018 at 8:14:36 PM UTC+8, Ga=C5=A1per A=C5=BE=
man wrote:
>>>>>>>
>>>>>>> In the generator case it gets optimized away in most cases, and in=
=20
>>>>>>> others its only the price of a (predicted) function call. No differ=
ent than=20
>>>>>>> calling a for_each with a synthesized lambda that you invoke on eve=
ry=20
>>>>>>> element.
>>>>>>>
>>>>>>> On Tue, Oct 9, 2018 at 1:13 PM <eulo...@live.com> wrote:
>>>>>>>
>>>>>>>> But context swapping is slow.
>>>>>>>>
>>>>>>>> On Tuesday, October 9, 2018 at 8:07:35 PM UTC+8, Ga=C5=A1per A=C5=
=BEman wrote:
>>>>>>>>>
>>>>>>>>> The solution for this is already targeted by the generators of=20
>>>>>>>>> coroutines.
>>>>>>>>>
>>>>>>>>> On Tue, Oct 9, 2018 at 1:05 PM <eulo...@live.com> wrote:
>>>>>>>>>
>>>>>>>>>> I think it is painful and noisy to write iterators in order to=
=20
>>>>>>>>>> support range-for loop.
>>>>>>>>>>
>>>>>>>>>> Here are my reasons:
>>>>>>>>>> 1: semantics of range-for loop are not necessarily equivalent to=
=20
>>>>>>>>>> access every iterator in the range.
>>>>>>>>>> 2: For many containers, defining iterators are harder than=20
>>>>>>>>>> defining the range-for loop directly.
>>>>>>>>>> 3: It is painful to write iterators to support simple data=20
>>>>>>>>>> structures.
>>>>>>>>>> 4: For containers like std::deque, std::set, std::map and even=
=20
>>>>>>>>>> lists, using iterators to traverse the entire container lose a h=
uge amount=20
>>>>>>>>>> of performance compared to define a universal for_each function.
>>>>>>>>>>
>>>>>>>>>> For example, if I have a binary search tree:
>>>>>>>>>>
>>>>>>>>>> template<typename T>
>>>>>>>>>> class bst
>>>>>>>>>> {
>>>>>>>>>> };
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> template<typename T,typename Callback>
>>>>>>>>>> void inorder_traverse(const bstnode<T> *p,Callback &&F)
>>>>>>>>>> {
>>>>>>>>>> if(p->left())
>>>>>>>>>> inorder_travel(p->left(),F);
>>>>>>>>>> F(p->value());
>>>>>>>>>> if(p->right())
>>>>>>>>>> inorder_travel(p->right(),F);
>>>>>>>>>> }
>>>>>>>>>> template<typename T,typename Callback>
>>>>>>>>>> inline void for_each(const bst<T> &t,Callback &&F)
>>>>>>>>>> {
>>>>>>>>>> if(t.root())
>>>>>>>>>> inorder_traverse(t.root(),std::forward<Callback>(F));
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> bst<std::size_t> b;=20
>>>>>>>>>> std::size_t sum(0);
>>>>>>>>>> for(const auto &ele : b) // will check whether the "for_each"=
=20
>>>>>>>>>> function is defined for the container. If it does have one, call=
this first.
>>>>>>>>>> sum+=3Dele;
>>>>>>>>>>
>>>>>>>>>> this will be equivalent to:
>>>>>>>>>>
>>>>>>>>>> bst<std::size_t> b;=20
>>>>>>>>>> std::size_t sum(0);
>>>>>>>>>> for_each(b,[&](const auto &ele)
>>>>>>>>>> {
>>>>>>>>>> sum+=3Dele;
>>>>>>>>>> });
>>>>>>>>>>
>>>>>>>>>> --=20
>>>>>>>>>> You received this message because you are subscribed to the=20
>>>>>>>>>> Google Groups "ISO C++ Standard - Future Proposals" group.
>>>>>>>>>> To unsubscribe from this group and stop receiving emails from it=
,=20
>>>>>>>>>> send an email to std-proposal...@isocpp.org.
>>>>>>>>>> To post to this group, send email to std-pr...@isocpp.org.
>>>>>>>>>> To view this discussion on the web visit=20
>>>>>>>>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9ba=
3d13b-3044-4223-afd0-218e8ba06893%40isocpp.org=20
>>>>>>>>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9b=
a3d13b-3044-4223-afd0-218e8ba06893%40isocpp.org?utm_medium=3Demail&utm_sour=
ce=3Dfooter>
>>>>>>>>>> .
>>>>>>>>>>
>>>>>>>>> --=20
>>>>>>>> You received this message because you are subscribed to the Google=
=20
>>>>>>>> Groups "ISO C++ Standard - Future Proposals" group.
>>>>>>>> To unsubscribe from this group and stop receiving emails from it,=
=20
>>>>>>>> send an email to std-proposal...@isocpp.org.
>>>>>>>> To post to this group, send email to std-pr...@isocpp.org.
>>>>>>>> To view this discussion on the web visit=20
>>>>>>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/88165=
d50-83b4-4067-bec3-7c7dab15dce3%40isocpp.org=20
>>>>>>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/8816=
5d50-83b4-4067-bec3-7c7dab15dce3%40isocpp.org?utm_medium=3Demail&utm_source=
=3Dfooter>
>>>>>>>> .
>>>>>>>>
>>>>>>> --=20
>>>>>> You received this message because you are subscribed to the Google=
=20
>>>>>> Groups "ISO C++ Standard - Future Proposals" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it,=20
>>>>>> send an email to std-proposal...@isocpp.org.
>>>>>> To post to this group, send email to std-pr...@isocpp.org.
>>>>>> To view this discussion on the web visit=20
>>>>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/7b76fd5=
e-f3c3-4952-af81-3435456f48b7%40isocpp.org=20
>>>>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/7b76fd=
5e-f3c3-4952-af81-3435456f48b7%40isocpp.org?utm_medium=3Demail&utm_source=
=3Dfooter>
>>>>>> .
>>>>>>
>>>>> --=20
>>>> You received this message because you are subscribed to the Google=20
>>>> Groups "ISO C++ Standard - Future Proposals" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send=
=20
>>>> an email to std-proposal...@isocpp.org.
>>>> To post to this group, send email to std-pr...@isocpp.org.
>>>> To view this discussion on the web visit=20
>>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/f2f9e546-=
638d-4ebb-b0c9-f1eb329717f0%40isocpp.org=20
>>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/f2f9e546=
-638d-4ebb-b0c9-f1eb329717f0%40isocpp.org?utm_medium=3Demail&utm_source=3Df=
ooter>
>>>> .
>>>>
>>> --=20
>> You received this message because you are subscribed to the Google Group=
s=20
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n=20
>> email to std-proposal...@isocpp.org <javascript:>.
>> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
>> To view this discussion on the web visit=20
>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/63319859-3f=
0a-4799-90e9-fd699ee89f29%40isocpp.org=20
>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/63319859-3=
f0a-4799-90e9-fd699ee89f29%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoo=
ter>
>> .
>>
>
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/1d897701-97c1-4b7d-8ba6-02c047954c45%40isocpp.or=
g.
------=_Part_2105_567395987.1539090098658
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">It won't. std::deque, std::set, std::map they all do n=
ot define this.<br><br>On Tuesday, October 9, 2018 at 8:51:53 PM UTC+8, Ga=
=C5=A1per A=C5=BEman wrote:<blockquote class=3D"gmail_quote" style=3D"margi=
n: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><di=
v dir=3D"ltr"><br><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue, O=
ct 9, 2018 at 1:47 PM <<a href=3D"javascript:" target=3D"_blank" gdf-obf=
uscated-mailto=3D"1rGypjldBAAJ" rel=3D"nofollow" onmousedown=3D"this.href=
=3D'javascript:';return true;" onclick=3D"this.href=3D'javascri=
pt:';return true;">eulo...@live.com</a>> wrote:<br></div><blockquote=
class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc soli=
d;padding-left:1ex"><div dir=3D"ltr">I don't think it is the point abou=
t coroutine. It is about the interface for containers of range-for loop. Th=
e current standard must use iterators for containers to iterator the entire=
container.</div></blockquote><div>Yes, that's the point. The ranged fo=
r is not a magic construct, it uses the standard interface. Let's not a=
dd another interface.</div><div>=C2=A0</div><blockquote class=3D"gmail_quot=
e" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">=
<div dir=3D"ltr">You have to define a standard interface for this in order =
for all containers to write customized code to support these kinds of usage=
which is lacking in the standard. No matter you use coroutine or for-each,=
it won't solve the issue directly.<br></div></blockquote><div>It does =
- you can easily write a facade that will implement your begin() and end() =
directly on the container, if you want. My suggestion was that putting that=
facade into boost to wrap a simple coroutine that yields references to suc=
cessive elements is a relatively simple exercise and it *solves your proble=
m* without introducing a separate way to interpret ranged for-loops that ma=
y actually break code because it prefers the new interface.</div><div>=C2=
=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;borde=
r-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><br>On Tuesday, Oc=
tober 9, 2018 at 8:44:17 PM UTC+8, Ga=C5=A1per A=C5=BEman wrote:<blockquote=
class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px =
#ccc solid;padding-left:1ex"><div dir=3D"ltr">By returning a fat iterator t=
hat encapsulates the generator from begin(), and a sentinel that checks it =
against the generator's end() from end(). It only takes a few lines of =
code, and I bet boost can provide a facade that vanishes in codegen pretty =
easily.<div><br></div><div>Or, you know, just use std::for_each and expect =
it to be customized for your type if you want generic code.</div><div><br><=
/div><div>That said, feel free to propose this, but I personally don't =
see enough justification to reserve yet another name in the language, becau=
se that's what the current customization points do.</div><div><br></div=
><div>G<br><div><br></div><div><br></div><br><div class=3D"gmail_quote"><di=
v dir=3D"ltr">On Tue, Oct 9, 2018 at 1:38 PM <<a rel=3D"nofollow">eulo..=
..@live.com</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=
=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=
=3D"ltr"><div><div>But, how could you define range-for loop for the type di=
rectly (for example like std::deque) instead of using a coroutine=C2=A0of t=
hat type.<br></div></div><div><br></div><div>std::deque<int> d;</div>=
<div>std::size_t sum(0):</div><div>for(const auto &ele : d)<br></div><d=
iv>=C2=A0 =C2=A0sum+=3D0;</div><div><br></div><div>If you can't, it wou=
ld be=C2=A0painful to write this for generic code?</div><div><br></div><div=
><br></div><div>On Tuesday, October 9, 2018 at 8:28:38 PM UTC+8, Ga=C5=A1pe=
r A=C5=BEman wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;marg=
in-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"=
>Adding customization points to the language is a "you better have a r=
eally really good reason" kind of thing. If another feature already pr=
ovides a way to hook into already existing features without an additional c=
ustomization point, you'd expect the standard to avoid adding customiza=
tion points.<div><br></div><div>In this case, it's easy to see how</div=
><div><br></div><div>for (auto range =3D x.in_order_traversal(); auto& =
element : range) {</div><div>=C2=A0 =C2=A0element=C2=A0+=3D 1;</div><div>}<=
/div><div><br></div><div>does its job just fine, without an extra customiza=
tion point.</div><div><br></div><div><br></div></div><br><div class=3D"gmai=
l_quote"><div dir=3D"ltr">On Tue, Oct 9, 2018 at 1:23 PM <<a rel=3D"nofo=
llow">eulo...@live.com</a>> wrote:<br></div><blockquote class=3D"gmail_q=
uote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1e=
x"><div dir=3D"ltr">also, std::for_each is a function already defined in th=
e standard library, calling this won't add anything compared to add cor=
outine.<br><br>On Tuesday, October 9, 2018 at 8:14:36 PM UTC+8, Ga=C5=A1per=
A=C5=BEman wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margi=
n-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">=
In the generator case it gets optimized away in most cases, and in others i=
ts only the price of a (predicted) function call. No different than calling=
a for_each with a synthesized lambda that you invoke on every element.</di=
v><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue, Oct 9, 2018 at 1:=
13 PM <<a rel=3D"nofollow">eulo...@live.com</a>> wrote:<br></div><blo=
ckquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #c=
cc solid;padding-left:1ex"><div dir=3D"ltr">But context swapping is slow.<b=
r><br>On Tuesday, October 9, 2018 at 8:07:35 PM UTC+8, Ga=C5=A1per A=C5=BEm=
an wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.=
8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">The solut=
ion for this is already targeted by the generators of coroutines.</div><br>=
<div class=3D"gmail_quote"><div dir=3D"ltr">On Tue, Oct 9, 2018 at 1:05 PM =
<<a rel=3D"nofollow">eulo...@live.com</a>> wrote:<br></div><blockquot=
e class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc sol=
id;padding-left:1ex"><div dir=3D"ltr"><div>I think it is painful and noisy =
to write iterators in order to support range-for loop.</div><div><br></div>=
<div>Here are my reasons:</div><div>1: semantics of range-for loop are not =
necessarily equivalent to access every iterator in the range.</div><div>2: =
For many containers, defining iterators are harder than defining the range-=
for loop directly.</div><div>3: It is painful to write iterators to support=
simple data structures.</div><div>4: For containers like std::deque, std::=
set, std::map and even lists, using iterators to=C2=A0traverse the entire c=
ontainer lose a huge amount of performance compared to define a universal f=
or_each function.</div><div><br></div><div>For example, if I have a binary =
search tree:</div><div><br></div><div>template<typename T></div><div>=
class bst</div><div>{<br></div><div>};</div><div><br></div><div><br></div><=
div>template<typename T,typename Callback></div><div>void inorder_tra=
verse(const bstnode<T> *p,Callback &&F)</div><div>{</div><div=
><span style=3D"white-space:pre-wrap"> </span>if(p->left())</div><div><s=
pan style=3D"white-space:pre-wrap"> </span>inorder_travel(p->left(),F);=
</div><div><span style=3D"white-space:pre-wrap"> </span>F(p->value());</=
div><div><span style=3D"white-space:pre-wrap"> </span>if(p->right())</di=
v><div><span style=3D"white-space:pre-wrap"> </span>inorder_travel(p->r=
ight(),F);</div><div>}</div><div>template<typename T,typename Callback&g=
t;</div><div>inline void for_each(const bst<T> &t,Callback &&=
amp;F)</div><div>{</div><div><span style=3D"white-space:pre-wrap"> </span>i=
f(t.root())</div><div><span style=3D"white-space:pre-wrap"> </span>inorder=
_traverse(t.root(),std:<wbr>:forward<Callback>(F));</div><div>}</div>=
<div><br></div><div><br></div><div><br></div><div>bst<std::size_t> b;=
=C2=A0</div><div>std::size_t sum(0);<br></div><div>for(const auto &ele =
: b)=C2=A0 =C2=A0 // will check whether the "for_each" function i=
s defined for the container. If it does have one, call this first.<br></div=
><div>=C2=A0 =C2=A0 sum+=3Dele;</div><div><br></div><div>this will be equiv=
alent to:</div><div><br></div><div><div>bst<std::size_t> b;=C2=A0</di=
v><div>std::size_t sum(0);<br></div><div>for_each(b,[&](const auto &=
;ele)</div></div><div>{</div><div>=C2=A0 =C2=A0 sum+=3Dele;<br></div><div>}=
);</div><div><br></div></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/9ba3d13b-3044-4223-afd0-218e8ba06893%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/9ba3d13b-3044-4223-<wbr>afd0-=
218e8ba06893%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/88165d50-83b4-4067-bec3-7c7dab15dce3%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/88165d50-83b4-4067-<wbr>bec3-=
7c7dab15dce3%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/7b76fd5e-f3c3-4952-af81-3435456f48b7%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/7b76fd5e-f3c3-4952-af81-3435456f48b7%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/7b76fd5e-f3c3-4952-af81-3435456f48b7%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/7b76fd5e-f3c3-4952-<wbr>af81-=
3435456f48b7%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/f2f9e546-638d-4ebb-b0c9-f1eb329717f0%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/f2f9e546-638d-4ebb-b0c9-f1eb329717f0%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/f2f9e546-638d-4ebb-b0c9-f1eb329717f0%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/f2f9e546-638d-4ebb-<wbr>b0c9-=
f1eb329717f0%40isocpp.org</a><wbr>.<br>
</blockquote></div></div></div>
</blockquote></div>
<p></p>
-- <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"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
1rGypjldBAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:&=
#39;;return true;" onclick=3D"this.href=3D'javascript:';return true=
;">std-proposal...@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"javascript:" target=3D"_bla=
nk" gdf-obfuscated-mailto=3D"1rGypjldBAAJ" rel=3D"nofollow" onmousedown=3D"=
this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'=
;javascript:';return true;">std-pr...@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/63319859-3f0a-4799-90e9-fd699ee89f29%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank" =
rel=3D"nofollow" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/63319859-3f0a-4799-90e9-fd699ee89f29%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/63319859-3f0a-4799-90e9-fd699ee89f29%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/63319859-3f0a-4799-<wbr>90e9-=
fd699ee89f29%40isocpp.org</a><wbr>.<br>
</blockquote></div></div>
</blockquote></div>
<p></p>
-- <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+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/1d897701-97c1-4b7d-8ba6-02c047954c45%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/1d897701-97c1-4b7d-8ba6-02c047954c45=
%40isocpp.org</a>.<br />
------=_Part_2105_567395987.1539090098658--
------=_Part_2104_1273126576.1539090098657--
.
Author: florian.csdt@gmail.com
Date: Tue, 9 Oct 2018 06:22:00 -0700 (PDT)
Raw View
------=_Part_964_81866724.1539091320956
Content-Type: multipart/alternative;
boundary="----=_Part_965_755541422.1539091320957"
------=_Part_965_755541422.1539091320957
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Let's have an exemple:
Imagine you have a type that internally is a vector of vectors, and you=20
want to iterate over all its elements: https://gcc.godbolt.org/z/rXRID9
As you can see, the code with the foreach is both simpler to write and=20
gives better assembly.
I haven't run benchmarcks, but I can assure you that if the loop body is=20
small, the difference will be far from negligible.
It might seems a bit cumbersome to write a container like that and expect=
=20
people to always iterate on the inner elements, but that's exactly what a=
=20
Deque is and does (set and map are also similar).
So there is an interest into formalizing a "for_each" like approach that=20
does not rely on ranges and iterators.
Le mardi 9 octobre 2018 14:48:02 UTC+2, Ga=C5=A1per A=C5=BEman a =C3=A9crit=
:
>
> I really don't see how this applies to generators from the coroutines TS,=
=20
> and also how nested loops can somehow be written differently as a functio=
n=20
> vs an iterator comparison.
>
> On Tue, Oct 9, 2018 at 1:45 PM <floria...@gmail.com <javascript:>> wrote:
>
>> There are cases where a for_each can be better/faster(/stronger) than=20
>> ranges: nested loops.
>>
>> Emulating nested loops with ranges is slow because for each ++, the=20
>> iterator has to check if it has reached the end of the inner loop or not=
..
>>
>> Le mardi 9 octobre 2018 14:28:38 UTC+2, Ga=C5=A1per A=C5=BEman a =C3=A9c=
rit :
>>>
>>> Adding customization points to the language is a "you better have a=20
>>> really really good reason" kind of thing. If another feature already=20
>>> provides a way to hook into already existing features without an additi=
onal=20
>>> customization point, you'd expect the standard to avoid adding=20
>>> customization points.
>>>
>>> In this case, it's easy to see how
>>>
>>> for (auto range =3D x.in_order_traversal(); auto& element : range) {
>>> element +=3D 1;
>>> }
>>>
>>> does its job just fine, without an extra customization point.
>>>
>>> --=20
>> You received this message because you are subscribed to the Google Group=
s=20
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n=20
>> email to std-proposal...@isocpp.org <javascript:>.
>> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
>> To view this discussion on the web visit=20
>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/71498824-6a=
5b-40ba-84db-4d4df72e2c94%40isocpp.org=20
>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/71498824-6=
a5b-40ba-84db-4d4df72e2c94%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoo=
ter>
>> .
>>
>
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/f2908073-3b79-4e20-9a6f-f323f2ef4116%40isocpp.or=
g.
------=_Part_965_755541422.1539091320957
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Let's have an exemple:</div><div>Imagine you have=
a type that internally is a vector of vectors, and you want to iterate ove=
r all its elements: https://gcc.godbolt.org/z/rXRID9</div><div>As you can s=
ee, the code with the foreach is both simpler to write and gives better ass=
embly.</div><div>I haven't run benchmarcks, but I can assure you that i=
f the loop body is small, the difference will be far from negligible.</div>=
<div><br></div><div>It might seems a bit cumbersome to write a container li=
ke that and expect people to always iterate on the inner elements, but that=
's exactly what a Deque is and does (set and map are also similar).</di=
v><div><br></div><div>So there is an interest into formalizing a "for_=
each" like approach that does not rely on ranges and iterators.<br></d=
iv><div><br></div><br>Le mardi 9 octobre 2018 14:48:02 UTC+2, Ga=C5=A1per A=
=C5=BEman a =C3=A9crit=C2=A0:<blockquote class=3D"gmail_quote" style=3D"mar=
gin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><=
div dir=3D"ltr">I really don't see how this applies to generators from =
the coroutines TS, and also how nested loops can somehow be written differe=
ntly as a function vs an iterator comparison.</div><br><div class=3D"gmail_=
quote"><div dir=3D"ltr">On Tue, Oct 9, 2018 at 1:45 PM <<a href=3D"javas=
cript:" target=3D"_blank" gdf-obfuscated-mailto=3D"5Ade4QNdBAAJ" rel=3D"nof=
ollow" onmousedown=3D"this.href=3D'javascript:';return true;" oncli=
ck=3D"this.href=3D'javascript:';return true;">floria...@gmail.com</=
a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 =
0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div=
>There are cases where a for_each can be better/faster(/stronger) than rang=
es: nested loops.</div><div><br></div><div>Emulating nested loops with rang=
es is slow because for each ++, the iterator has to check if it has reached=
the end of the inner loop or not.<br></div><br>Le mardi 9 octobre 2018 14:=
28:38 UTC+2, Ga=C5=A1per A=C5=BEman a =C3=A9crit=C2=A0:<blockquote class=3D=
"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc soli=
d;padding-left:1ex"><div dir=3D"ltr">Adding customization points to the lan=
guage is a "you better have a really really good reason" kind of =
thing. If another feature already provides a way to hook into already exist=
ing features without an additional customization point, you'd expect th=
e standard to avoid adding customization points.<div><br></div><div>In this=
case, it's easy to see how</div><div><br></div><div>for (auto range =
=3D x.in_order_traversal(); auto& element : range) {</div><div>=C2=A0 =
=C2=A0element=C2=A0+=3D 1;</div><div>}</div><div><br></div><div>does its jo=
b just fine, without an extra customization point.</div><div><br></div></di=
v></blockquote></div>
<p></p>
-- <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"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
5Ade4QNdBAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:&=
#39;;return true;" onclick=3D"this.href=3D'javascript:';return true=
;">std-proposal...@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"javascript:" target=3D"_bla=
nk" gdf-obfuscated-mailto=3D"5Ade4QNdBAAJ" rel=3D"nofollow" onmousedown=3D"=
this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'=
;javascript:';return true;">std-pr...@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/71498824-6a5b-40ba-84db-4d4df72e2c94%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank" =
rel=3D"nofollow" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/71498824-6a5b-40ba-84db-4d4df72e2c94%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/71498824-6a5b-40ba-84db-4d4df72e2c94%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/71498824-6a5b-40ba-<wbr>84db-=
4d4df72e2c94%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/f2908073-3b79-4e20-9a6f-f323f2ef4116%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/f2908073-3b79-4e20-9a6f-f323f2ef4116=
%40isocpp.org</a>.<br />
------=_Part_965_755541422.1539091320957--
------=_Part_964_81866724.1539091320956--
.
Author: euloanty@live.com
Date: Tue, 9 Oct 2018 06:27:34 -0700 (PDT)
Raw View
------=_Part_2071_2132306839.1539091654418
Content-Type: multipart/alternative;
boundary="----=_Part_2072_925570653.1539091654419"
------=_Part_2072_925570653.1539091654419
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Gasper wants to use coroutine instead of writing for_each. I think it is a=
=20
cool idea.
I think defining a range(C) coroutine like begin(C), end(C) as a standard=
=20
would be better.
On Tuesday, October 9, 2018 at 9:22:01 PM UTC+8, floria...@gmail.com wrote:
>
> Let's have an exemple:
> Imagine you have a type that internally is a vector of vectors, and you=
=20
> want to iterate over all its elements: https://gcc.godbolt.org/z/rXRID9
> As you can see, the code with the foreach is both simpler to write and=20
> gives better assembly.
> I haven't run benchmarcks, but I can assure you that if the loop body is=
=20
> small, the difference will be far from negligible.
>
> It might seems a bit cumbersome to write a container like that and expect=
=20
> people to always iterate on the inner elements, but that's exactly what a=
=20
> Deque is and does (set and map are also similar).
>
> So there is an interest into formalizing a "for_each" like approach that=
=20
> does not rely on ranges and iterators.
>
>
> Le mardi 9 octobre 2018 14:48:02 UTC+2, Ga=C5=A1per A=C5=BEman a =C3=A9cr=
it :
>>
>> I really don't see how this applies to generators from the coroutines TS=
,=20
>> and also how nested loops can somehow be written differently as a functi=
on=20
>> vs an iterator comparison.
>>
>> On Tue, Oct 9, 2018 at 1:45 PM <floria...@gmail.com> wrote:
>>
>>> There are cases where a for_each can be better/faster(/stronger) than=
=20
>>> ranges: nested loops.
>>>
>>> Emulating nested loops with ranges is slow because for each ++, the=20
>>> iterator has to check if it has reached the end of the inner loop or no=
t.
>>>
>>> Le mardi 9 octobre 2018 14:28:38 UTC+2, Ga=C5=A1per A=C5=BEman a =C3=A9=
crit :
>>>>
>>>> Adding customization points to the language is a "you better have a=20
>>>> really really good reason" kind of thing. If another feature already=
=20
>>>> provides a way to hook into already existing features without an addit=
ional=20
>>>> customization point, you'd expect the standard to avoid adding=20
>>>> customization points.
>>>>
>>>> In this case, it's easy to see how
>>>>
>>>> for (auto range =3D x.in_order_traversal(); auto& element : range) {
>>>> element +=3D 1;
>>>> }
>>>>
>>>> does its job just fine, without an extra customization point.
>>>>
>>>> --=20
>>> You received this message because you are subscribed to the Google=20
>>> Groups "ISO C++ Standard - Future Proposals" group.
>>> To unsubscribe from this group and stop receiving emails from it, send=
=20
>>> an email to std-proposal...@isocpp.org.
>>> To post to this group, send email to std-pr...@isocpp.org.
>>> To view this discussion on the web visit=20
>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/71498824-6=
a5b-40ba-84db-4d4df72e2c94%40isocpp.org=20
>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/71498824-=
6a5b-40ba-84db-4d4df72e2c94%40isocpp.org?utm_medium=3Demail&utm_source=3Dfo=
oter>
>>> .
>>>
>>
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/d65b4573-9d90-4a62-9ba3-97d006285ab9%40isocpp.or=
g.
------=_Part_2072_925570653.1539091654419
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Gasper wants to use coroutine instead of writing for_each.=
I think it is a cool idea.<div><br></div><div>I think defining a range(C) =
coroutine like begin(C), end(C) as a standard would be better.<br><br>On Tu=
esday, October 9, 2018 at 9:22:01 PM UTC+8, floria...@gmail.com wrote:<bloc=
kquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-l=
eft: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div>Let's hav=
e an exemple:</div><div>Imagine you have a type that internally is a vector=
of vectors, and you want to iterate over all its elements: <a href=3D"http=
s://gcc.godbolt.org/z/rXRID9" target=3D"_blank" rel=3D"nofollow" onmousedow=
n=3D"this.href=3D'https://www.google.com/url?q\x3dhttps%3A%2F%2Fgcc.god=
bolt.org%2Fz%2FrXRID9\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEzBhukgk5p6oZ=
gK8YPMgibY2qfjw';return true;" onclick=3D"this.href=3D'https://www.=
google.com/url?q\x3dhttps%3A%2F%2Fgcc.godbolt.org%2Fz%2FrXRID9\x26sa\x3dD\x=
26sntz\x3d1\x26usg\x3dAFQjCNEzBhukgk5p6oZgK8YPMgibY2qfjw';return true;"=
>https://gcc.godbolt.org/z/<wbr>rXRID9</a></div><div>As you can see, the co=
de with the foreach is both simpler to write and gives better assembly.</di=
v><div>I haven't run benchmarcks, but I can assure you that if the loop=
body is small, the difference will be far from negligible.</div><div><br><=
/div><div>It might seems a bit cumbersome to write a container like that an=
d expect people to always iterate on the inner elements, but that's exa=
ctly what a Deque is and does (set and map are also similar).</div><div><br=
></div><div>So there is an interest into formalizing a "for_each"=
like approach that does not rely on ranges and iterators.<br></div><div><b=
r></div><br>Le mardi 9 octobre 2018 14:48:02 UTC+2, Ga=C5=A1per A=C5=BEman =
a =C3=A9crit=C2=A0:<blockquote class=3D"gmail_quote" style=3D"margin:0;marg=
in-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"=
>I really don't see how this applies to generators from the coroutines =
TS, and also how nested loops can somehow be written differently as a funct=
ion vs an iterator comparison.</div><br><div class=3D"gmail_quote"><div dir=
=3D"ltr">On Tue, Oct 9, 2018 at 1:45 PM <<a rel=3D"nofollow">floria...@g=
mail.com</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D=
"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D=
"ltr"><div>There are cases where a for_each can be better/faster(/stronger)=
than ranges: nested loops.</div><div><br></div><div>Emulating nested loops=
with ranges is slow because for each ++, the iterator has to check if it h=
as reached the end of the inner loop or not.<br></div><br>Le mardi 9 octobr=
e 2018 14:28:38 UTC+2, Ga=C5=A1per A=C5=BEman a =C3=A9crit=C2=A0:<blockquot=
e class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px=
#ccc solid;padding-left:1ex"><div dir=3D"ltr">Adding customization points =
to the language is a "you better have a really really good reason"=
; kind of thing. If another feature already provides a way to hook into alr=
eady existing features without an additional customization point, you'd=
expect the standard to avoid adding customization points.<div><br></div><d=
iv>In this case, it's easy to see how</div><div><br></div><div>for (aut=
o range =3D x.in_order_traversal(); auto& element : range) {</div><div>=
=C2=A0 =C2=A0element=C2=A0+=3D 1;</div><div>}</div><div><br></div><div>does=
its job just fine, without an extra customization point.</div><div><br></d=
iv></div></blockquote></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/71498824-6a5b-40ba-84db-4d4df72e2c94%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/71498824-6a5b-40ba-84db-4d4df72e2c94%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/71498824-6a5b-40ba-84db-4d4df72e2c94%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/71498824-6a5b-40ba-<wbr>84db-=
4d4df72e2c94%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div></blockquote></div></div>
<p></p>
-- <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+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/d65b4573-9d90-4a62-9ba3-97d006285ab9%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/d65b4573-9d90-4a62-9ba3-97d006285ab9=
%40isocpp.org</a>.<br />
------=_Part_2072_925570653.1539091654419--
------=_Part_2071_2132306839.1539091654418--
.
Author: florian.csdt@gmail.com
Date: Tue, 9 Oct 2018 06:31:45 -0700 (PDT)
Raw View
------=_Part_2119_729668747.1539091905253
Content-Type: multipart/alternative;
boundary="----=_Part_2120_244927635.1539091905253"
------=_Part_2120_244927635.1539091905253
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
I'm a bit doubtful about the speed of coroutines as generators
Le mardi 9 octobre 2018 15:27:34 UTC+2, ejsvifq mabmip a =C3=A9crit :
>
> Gasper wants to use coroutine instead of writing for_each. I think it is =
a=20
> cool idea.
>
> I think defining a range(C) coroutine like begin(C), end(C) as a standard=
=20
> would be better.
>
>
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/b49af51f-2404-43a6-8d69-f0c6de72d07f%40isocpp.or=
g.
------=_Part_2120_244927635.1539091905253
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I'm a bit doubtful about the speed of coroutines as ge=
nerators<br><br>Le mardi 9 octobre 2018 15:27:34 UTC+2, ejsvifq mabmip a =
=C3=A9crit=C2=A0:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"l=
tr">Gasper wants to use coroutine instead of writing for_each. I think it i=
s a cool idea.<div><br></div><div>I think defining a range(C) coroutine lik=
e begin(C), end(C) as a standard would be better.<br><br></div></div></bloc=
kquote></div>
<p></p>
-- <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+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/b49af51f-2404-43a6-8d69-f0c6de72d07f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/b49af51f-2404-43a6-8d69-f0c6de72d07f=
%40isocpp.org</a>.<br />
------=_Part_2120_244927635.1539091905253--
------=_Part_2119_729668747.1539091905253--
.
Author: =?UTF-8?B?R2HFoXBlciBBxb5tYW4=?= <gasper.azman@gmail.com>
Date: Tue, 9 Oct 2018 14:32:19 +0100
Raw View
--00000000000004852d0577cbc5de
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
The simple ones get inlined and you get perfect codegen.
On Tue, Oct 9, 2018 at 2:31 PM <florian.csdt@gmail.com> wrote:
> I'm a bit doubtful about the speed of coroutines as generators
>
> Le mardi 9 octobre 2018 15:27:34 UTC+2, ejsvifq mabmip a =C3=A9crit :
>>
>> Gasper wants to use coroutine instead of writing for_each. I think it is
>> a cool idea.
>>
>> I think defining a range(C) coroutine like begin(C), end(C) as a standar=
d
>> would be better.
>>
>> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/b49af51f-240=
4-43a6-8d69-f0c6de72d07f%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/b49af51f-24=
04-43a6-8d69-f0c6de72d07f%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoot=
er>
> .
>
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/CAANG%3DkWY9NRxzysRgx8bU5cmBWk%3DSDHFsjnZ5Axvf3%=
2B83A3jDg%40mail.gmail.com.
--00000000000004852d0577cbc5de
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">The simple ones get inlined and you get perfect codegen.</=
div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue, Oct 9, 2018 at =
2:31 PM <<a href=3D"mailto:florian.csdt@gmail.com">florian.csdt@gmail.co=
m</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin=
:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">I=
'm a bit doubtful about the speed of coroutines as generators<br><br>Le=
mardi 9 octobre 2018 15:27:34 UTC+2, ejsvifq mabmip a =C3=A9crit=C2=A0:<bl=
ockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-l=
eft:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Gasper wants to use c=
oroutine instead of writing for_each. I think it is a cool idea.<div><br></=
div><div>I think defining a range(C) coroutine like begin(C), end(C) as a s=
tandard would be better.<br><br></div></div></blockquote></div>
<p></p>
-- <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+unsubscribe@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>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/b49af51f-2404-43a6-8d69-f0c6de72d07f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/b49af51f-2404-=
43a6-8d69-f0c6de72d07f%40isocpp.org</a>.<br>
</blockquote></div>
<p></p>
-- <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+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkWY9NRxzysRgx8bU5cmBWk%3DSDHF=
sjnZ5Axvf3%2B83A3jDg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoote=
r">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkWY=
9NRxzysRgx8bU5cmBWk%3DSDHFsjnZ5Axvf3%2B83A3jDg%40mail.gmail.com</a>.<br />
--00000000000004852d0577cbc5de--
.
Author: florian.csdt@gmail.com
Date: Tue, 9 Oct 2018 06:39:12 -0700 (PDT)
Raw View
------=_Part_634_1324523500.1539092352855
Content-Type: multipart/alternative;
boundary="----=_Part_635_1120281707.1539092352855"
------=_Part_635_1120281707.1539092352855
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Exactly like the flattened iterator should also be inlined and lead to=20
perfect codegen but does not in practice?
Le mardi 9 octobre 2018 15:32:33 UTC+2, Ga=C5=A1per A=C5=BEman a =C3=A9crit=
:
>
> The simple ones get inlined and you get perfect codegen.
>
> On Tue, Oct 9, 2018 at 2:31 PM <floria...@gmail.com <javascript:>> wrote:
>
>> I'm a bit doubtful about the speed of coroutines as generators
>>
>> Le mardi 9 octobre 2018 15:27:34 UTC+2, ejsvifq mabmip a =C3=A9crit :
>>>
>>> Gasper wants to use coroutine instead of writing for_each. I think it i=
s=20
>>> a cool idea.
>>>
>>> I think defining a range(C) coroutine like begin(C), end(C) as a=20
>>> standard would be better.
>>>
>>> --=20
>> You received this message because you are subscribed to the Google Group=
s=20
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n=20
>> email to std-proposal...@isocpp.org <javascript:>.
>> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
>> To view this discussion on the web visit=20
>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/b49af51f-24=
04-43a6-8d69-f0c6de72d07f%40isocpp.org=20
>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/b49af51f-2=
404-43a6-8d69-f0c6de72d07f%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoo=
ter>
>> .
>>
>
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/2b0a9411-4967-4f96-bbbe-9c2eaa13d0ad%40isocpp.or=
g.
------=_Part_635_1120281707.1539092352855
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Exactly like the flattened iterator should also be inlined=
and lead to perfect codegen but does not in practice?<br><br>Le mardi 9 oc=
tobre 2018 15:32:33 UTC+2, Ga=C5=A1per A=C5=BEman a =C3=A9crit=C2=A0:<block=
quote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-le=
ft: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">The simple ones get=
inlined and you get perfect codegen.</div><br><div class=3D"gmail_quote"><=
div dir=3D"ltr">On Tue, Oct 9, 2018 at 2:31 PM <<a href=3D"javascript:" =
target=3D"_blank" gdf-obfuscated-mailto=3D"Y7IVq3FfBAAJ" rel=3D"nofollow" o=
nmousedown=3D"this.href=3D'javascript:';return true;" onclick=3D"th=
is.href=3D'javascript:';return true;">floria...@gmail.com</a>> w=
rote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex=
;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">I'm a bi=
t doubtful about the speed of coroutines as generators<br><br>Le mardi 9 oc=
tobre 2018 15:27:34 UTC+2, ejsvifq mabmip a =C3=A9crit=C2=A0:<blockquote cl=
ass=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #cc=
c solid;padding-left:1ex"><div dir=3D"ltr">Gasper wants to use coroutine in=
stead of writing for_each. I think it is a cool idea.<div><br></div><div>I =
think defining a range(C) coroutine like begin(C), end(C) as a standard wou=
ld be better.<br><br></div></div></blockquote></div>
<p></p>
-- <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"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
Y7IVq3FfBAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:&=
#39;;return true;" onclick=3D"this.href=3D'javascript:';return true=
;">std-proposal...@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"javascript:" target=3D"_bla=
nk" gdf-obfuscated-mailto=3D"Y7IVq3FfBAAJ" rel=3D"nofollow" onmousedown=3D"=
this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'=
;javascript:';return true;">std-pr...@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/b49af51f-2404-43a6-8d69-f0c6de72d07f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank" =
rel=3D"nofollow" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/b49af51f-2404-43a6-8d69-f0c6de72d07f%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/b49af51f-2404-43a6-8d69-f0c6de72d07f%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/b49af51f-2404-43a6-<wbr>8d69-=
f0c6de72d07f%40isocpp.org</a><wbr>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/2b0a9411-4967-4f96-bbbe-9c2eaa13d0ad%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/2b0a9411-4967-4f96-bbbe-9c2eaa13d0ad=
%40isocpp.org</a>.<br />
------=_Part_635_1120281707.1539092352855--
------=_Part_634_1324523500.1539092352855--
.
Author: =?UTF-8?B?R2HFoXBlciBBxb5tYW4=?= <gasper.azman@gmail.com>
Date: Tue, 9 Oct 2018 14:42:34 +0100
Raw View
--000000000000aa18db0577cbe9aa
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
No, it's better with coroutines, because they look like the inverted
for_each:
std::generator<reference> iterate() {
for (auto& v : data) {
for (auto& e : v) {
co_yield e;
}
}
}
The body of the for-loop gets pretty much directly pasted into the co-yield
section, after inlining, exactly the way the lambda does.
I'll try to prove it to you when I get home and have time to play with
this, I think godbolt has a coroutine-enabled compiler somewhere.
On Tue, Oct 9, 2018 at 2:39 PM <florian.csdt@gmail.com> wrote:
> Exactly like the flattened iterator should also be inlined and lead to
> perfect codegen but does not in practice?
>
> Le mardi 9 octobre 2018 15:32:33 UTC+2, Ga=C5=A1per A=C5=BEman a =C3=A9cr=
it :
>>
>> The simple ones get inlined and you get perfect codegen.
>>
>> On Tue, Oct 9, 2018 at 2:31 PM <floria...@gmail.com> wrote:
>>
>>> I'm a bit doubtful about the speed of coroutines as generators
>>>
>>> Le mardi 9 octobre 2018 15:27:34 UTC+2, ejsvifq mabmip a =C3=A9crit :
>>>>
>>>> Gasper wants to use coroutine instead of writing for_each. I think it
>>>> is a cool idea.
>>>>
>>>> I think defining a range(C) coroutine like begin(C), end(C) as a
>>>> standard would be better.
>>>>
>>>> --
>>> 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-proposal...@isocpp.org.
>>> To post to this group, send email to std-pr...@isocpp.org.
>>> To view this discussion on the web visit
>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/b49af51f-2=
404-43a6-8d69-f0c6de72d07f%40isocpp.org
>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/b49af51f-=
2404-43a6-8d69-f0c6de72d07f%40isocpp.org?utm_medium=3Demail&utm_source=3Dfo=
oter>
>>> .
>>>
>> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/2b0a9411-496=
7-4f96-bbbe-9c2eaa13d0ad%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/2b0a9411-49=
67-4f96-bbbe-9c2eaa13d0ad%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoot=
er>
> .
>
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/CAANG%3DkWFtX0y2%2Bx6stzGtF%3DmVy9gkKmn0kFXQ3cU5=
cHzhgg-%3DQ%40mail.gmail.com.
--000000000000aa18db0577cbe9aa
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">No, it's better with coroutines, because they look lik=
e the inverted for_each:<div><br></div><div>std::generator<reference>=
iterate() {</div><div><div style=3D"color:rgb(0,0,0);background-color:rgb(=
255,255,254)"><div> <span style=3D"color:rgb(0,0,255)">=C2=A0 for</s=
pan> (<span style=3D"color:rgb(0,0,255)">auto</span>& v : data) {</div>=
<div> <span style=3D"color:rgb(0,0,255)">=C2=A0 =C2=A0 for</span=
> (<span style=3D"color:rgb(0,0,255)">auto</span>& e : v) {</div><div>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 co_yield e;</div><div>=C2=A0 =C2=A0 }</div><div=
>=C2=A0 }</div><div> }</div></div></div><div><br></div><div>The body of =
the for-loop gets pretty much directly pasted into the co-yield section, af=
ter inlining, exactly the way the lambda does.</div><div><br></div><div>I&#=
39;ll try to prove it to you when I get home and have time to play with thi=
s, I think godbolt has a coroutine-enabled compiler somewhere.</div></div><=
br><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue, Oct 9, 2018 at 2:39 =
PM <<a href=3D"mailto:florian.csdt@gmail.com">florian.csdt@gmail.com</a>=
> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 =
0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Exactl=
y like the flattened iterator should also be inlined and lead to perfect co=
degen but does not in practice?<br><br>Le mardi 9 octobre 2018 15:32:33 UTC=
+2, Ga=C5=A1per A=C5=BEman a =C3=A9crit=C2=A0:<blockquote class=3D"gmail_qu=
ote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding=
-left:1ex"><div dir=3D"ltr">The simple ones get inlined and you get perfect=
codegen.</div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue, Oct =
9, 2018 at 2:31 PM <<a rel=3D"nofollow">floria...@gmail.com</a>> wrot=
e:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;bo=
rder-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">I'm a bit d=
oubtful about the speed of coroutines as generators<br><br>Le mardi 9 octob=
re 2018 15:27:34 UTC+2, ejsvifq mabmip a =C3=A9crit=C2=A0:<blockquote class=
=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc s=
olid;padding-left:1ex"><div dir=3D"ltr">Gasper wants to use coroutine inste=
ad of writing for_each. I think it is a cool idea.<div><br></div><div>I thi=
nk defining a range(C) coroutine like begin(C), end(C) as a standard would =
be better.<br><br></div></div></blockquote></div>
<p></p>
-- <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 rel=3D"nofollow">std-proposal...@isocpp.org</a>.<br>
To post to this group, send email to <a rel=3D"nofollow">std-pr...@isocpp.o=
rg</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/b49af51f-2404-43a6-8d69-f0c6de72d07f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank">https://groups.google.com/a/isocpp.org/d/msgid/std-proposa=
ls/b49af51f-2404-43a6-8d69-f0c6de72d07f%40isocpp.org</a>.<br>
</blockquote></div>
</blockquote></div>
<p></p>
-- <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+unsubscribe@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>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/2b0a9411-4967-4f96-bbbe-9c2eaa13d0ad%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/2b0a9411-4967-=
4f96-bbbe-9c2eaa13d0ad%40isocpp.org</a>.<br>
</blockquote></div>
<p></p>
-- <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+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkWFtX0y2%2Bx6stzGtF%3DmVy9gkK=
mn0kFXQ3cU5cHzhgg-%3DQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoo=
ter">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAANG%3Dk=
WFtX0y2%2Bx6stzGtF%3DmVy9gkKmn0kFXQ3cU5cHzhgg-%3DQ%40mail.gmail.com</a>.<br=
/>
--000000000000aa18db0577cbe9aa--
.
Author: Matthew Woehlke <mwoehlke.floss@gmail.com>
Date: Tue, 9 Oct 2018 10:27:37 -0400
Raw View
On 09/10/2018 08.05, euloanty@live.com wrote:
> I think it is painful and noisy to write iterators in order to support
> range-for loop.
> [...]
> bst<std::size_t> b;
> std::size_t sum(0);
> for(const auto &ele : b) // will check whether the "for_each" function
> is defined for the container. If it does have one, call this first.
> sum+=ele;
>
> this will be equivalent to:
>
> bst<std::size_t> b;
> std::size_t sum(0);
> for_each(b,[&](const auto &ele)
> {
> sum+=ele;
> });
....and how, exactly, will you implement a `break` with this? Especially
if your implementation of `for_each` is using recursive calls?
--
Matthew
--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/6bf233ce-06ed-c3aa-4808-7a0291cea41e%40gmail.com.
.
Author: euloanty@live.com
Date: Tue, 9 Oct 2018 07:52:32 -0700 (PDT)
Raw View
------=_Part_933_661536372.1539096752808
Content-Type: multipart/alternative;
boundary="----=_Part_934_1850676164.1539096752809"
------=_Part_934_1850676164.1539096752809
Content-Type: text/plain; charset="UTF-8"
throw an exception and catch it :)
lol. better just use a coroutine.
On Tuesday, October 9, 2018 at 10:27:40 PM UTC+8, Matthew Woehlke wrote:
>
> On 09/10/2018 08.05, eulo...@live.com <javascript:> wrote:
> > I think it is painful and noisy to write iterators in order to support
> > range-for loop.
> > [...]
> > bst<std::size_t> b;
> > std::size_t sum(0);
> > for(const auto &ele : b) // will check whether the "for_each"
> function
> > is defined for the container. If it does have one, call this first.
> > sum+=ele;
> >
> > this will be equivalent to:
> >
> > bst<std::size_t> b;
> > std::size_t sum(0);
> > for_each(b,[&](const auto &ele)
> > {
> > sum+=ele;
> > });
>
> ...and how, exactly, will you implement a `break` with this? Especially
> if your implementation of `for_each` is using recursive calls?
>
> --
> Matthew
>
--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/24692d6c-c68a-414e-9f65-6f25f21169e6%40isocpp.org.
------=_Part_934_1850676164.1539096752809
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">throw an exception and catch it :)<div><br></div><div>lol.=
better just use a coroutine.<br><br>On Tuesday, October 9, 2018 at 10:27:4=
0 PM UTC+8, Matthew Woehlke wrote:<blockquote class=3D"gmail_quote" style=
=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: =
1ex;">On 09/10/2018 08.05, <a href=3D"javascript:" target=3D"_blank" gdf-ob=
fuscated-mailto=3D"RaEtqHNiBAAJ" rel=3D"nofollow" onmousedown=3D"this.href=
=3D'javascript:';return true;" onclick=3D"this.href=3D'javascri=
pt:';return true;">eulo...@live.com</a> wrote:
<br>> I think it is painful and noisy to write iterators in order to sup=
port=20
<br>> range-for loop.
<br>> [...]
<br>> bst<std::size_t> b;=20
<br>> std::size_t sum(0);
<br>> for(const auto &ele : b) =C2=A0 =C2=A0// will check whether th=
e "for_each" function=20
<br>> is defined for the container. If it does have one, call this first=
..
<br>> =C2=A0 =C2=A0 sum+=3Dele;
<br>>=20
<br>> this will be equivalent to:
<br>>=20
<br>> bst<std::size_t> b;=20
<br>> std::size_t sum(0);
<br>> for_each(b,[&](const auto &ele)
<br>> {
<br>> =C2=A0 =C2=A0 sum+=3Dele;
<br>> });
<br>
<br>...and how, exactly, will you implement a `break` with this? Especially
<br>if your implementation of `for_each` is using recursive calls?
<br>
<br>--=20
<br>Matthew
<br></blockquote></div></div>
<p></p>
-- <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+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/24692d6c-c68a-414e-9f65-6f25f21169e6%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/24692d6c-c68a-414e-9f65-6f25f21169e6=
%40isocpp.org</a>.<br />
------=_Part_934_1850676164.1539096752809--
------=_Part_933_661536372.1539096752808--
.