Topic: Just like we got lambda-functions, can we get
Author: jeanmichael.celerier@gmail.com
Date: Fri, 22 Dec 2017 06:12:49 -0800 (PST)
Raw View
------=_Part_8244_1445355803.1513951969012
Content-Type: multipart/alternative;
boundary="----=_Part_8245_1750818314.1513951969012"
------=_Part_8245_1750818314.1513951969012
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
The idea being, the capture would be used to be able to define inline=20
structures able to reach into the parent scope.=20
eg.=20
int x =3D ...;
[=3D] struct {=20
auto get_foo() { return x+1; }
auto get_bar() { return x*x; }
} my_struct;=20
my_generic_function(my_struct);
A direct application is an alternative to the proposed std::overload for=20
variants: instead of=20
int x =3D ...;
std::visit(
std::overload(
[=3D] (int v) { x+v; }
, [=3D] (float v) { x+v; }
, [=3D] (const std::string& v) { v[x]; }),
a_variant);
you'd get =20
int x =3D ...;
[=3D] struct {=20
auto operator()(int v) { x+v; }
auto operator()(float v) { x+v; }
auto operator()(const std::string& v) { v[x]; }
} my_struct;=20
std::visit(my_struct, a_variant);
which only captures once instead of once per overload and as such could=20
reduce the number of copies in these cases (the std::overload approach has=
=20
other valid use-cases though ; there is place for both !).
Being able to define structures inlines would simplify syntax a bit more:=
=20
std::visit([=3D] struct {=20
auto operator()(int v) { x+v; }
auto operator()(float v) { x+v; }
auto operator()(const std::string& v) { v[x]; }
} , a_variant);
Best,
Jean-Micha=C3=ABl
--=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/6c35db8b-6939-4e8b-8052-c491d1093333%40isocpp.or=
g.
------=_Part_8245_1750818314.1513951969012
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">The idea being, the capture would be used to be able to de=
fine inline structures able to reach into the parent scope.=C2=A0<div><br><=
div><br></div><div>eg.=C2=A0</div><div><br></div><div>=C2=A0 =C2=A0 int x =
=3D ...;</div><div>=C2=A0 =C2=A0 [=3D] struct {=C2=A0</div><div>=C2=A0 =C2=
=A0 =C2=A0 auto get_foo() { return x+1; }</div>=C2=A0 =C2=A0 =C2=A0 auto ge=
t_bar() { return x*x; }<div>=C2=A0 =C2=A0 } my_struct;=C2=A0</div><div><br>=
</div><div>=C2=A0 =C2=A0 my_generic_function(my_struct);</div><div><br></di=
v><div>A direct application is an alternative to the proposed std::overload=
for variants: instead of=C2=A0</div><div><br class=3D"Apple-interchange-ne=
wline">=C2=A0 =C2=A0 int x =3D ...;<br></div><div>=C2=A0 =C2=A0 std::visit(=
</div><div>=C2=A0 =C2=A0 =C2=A0 std::overload(</div><div>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 [=3D] (int v) { x+v; }</div><div>=C2=A0 =C2=A0 =C2=A0 , [=3D] (f=
loat v) { x+v; }</div>=C2=A0 =C2=A0 =C2=A0 , [=3D] (const std::string& =
v) { v[x]; }),<div>=C2=A0 =C2=A0 =C2=A0 a_variant);</div><div><br></div><di=
v>you'd get=C2=A0=C2=A0<div><div><br class=3D"Apple-interchange-newline=
">=C2=A0 =C2=A0 int x =3D ...;<br class=3D"Apple-interchange-newline">=C2=
=A0 =C2=A0 [=3D] struct {=C2=A0</div><div>=C2=A0 =C2=A0 =C2=A0 auto operato=
r()(int v) { x+v; }</div>=C2=A0 =C2=A0 =C2=A0 auto operator()(float v) { x+=
v; }<br class=3D"Apple-interchange-newline">=C2=A0 =C2=A0 =C2=A0 auto opera=
tor()(const std::string& v) { v[x]; }<div>=C2=A0 =C2=A0 } my_struct;=C2=
=A0</div></div></div><div>=C2=A0 =C2=A0 std::visit(my_struct, a_variant);</=
div><div><br></div></div><div>which only captures once instead of once per =
overload and as such could reduce the number of copies in these cases (the =
std::overload approach has other valid use-cases though ; there is place fo=
r both !).</div><div><br></div><div>Being able to define structures inlines=
would simplify syntax a bit more:=C2=A0</div><div><br></div><div>=C2=A0 =
=C2=A0 std::visit([=3D] struct {=C2=A0<div>=C2=A0 =C2=A0 =C2=A0 auto operat=
or()(int v) { x+v; }</div>=C2=A0 =C2=A0 =C2=A0 auto operator()(float v) { x=
+v; }<br class=3D"Apple-interchange-newline">=C2=A0 =C2=A0 =C2=A0 auto oper=
ator()(const std::string& v) { v[x]; }<br>=C2=A0 =C2=A0 =C2=A0} , a_var=
iant);</div><div><br></div><div>Best,</div><div>Jean-Micha=C3=ABl</div></di=
v>
<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/6c35db8b-6939-4e8b-8052-c491d1093333%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/6c35db8b-6939-4e8b-8052-c491d1093333=
%40isocpp.org</a>.<br />
------=_Part_8245_1750818314.1513951969012--
------=_Part_8244_1445355803.1513951969012--
.
Author: "'Johannes Schaub' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Fri, 22 Dec 2017 20:33:35 +0100
Raw View
2017-12-22 15:12 GMT+01:00 <jeanmichael.celerier@gmail.com>:
> The idea being, the capture would be used to be able to define inline
> structures able to reach into the parent scope.
>
>
> eg.
>
> int x = ...;
> [=] struct {
> auto get_foo() { return x+1; }
> auto get_bar() { return x*x; }
> } my_struct;
>
> my_generic_function(my_struct);
>
> A direct application is an alternative to the proposed std::overload for
> variants: instead of
>
> int x = ...;
> std::visit(
> std::overload(
> [=] (int v) { x+v; }
> , [=] (float v) { x+v; }
> , [=] (const std::string& v) { v[x]; }),
> a_variant);
>
> you'd get
>
> int x = ...;
> [=] struct {
> auto operator()(int v) { x+v; }
> auto operator()(float v) { x+v; }
> auto operator()(const std::string& v) { v[x]; }
> } my_struct;
> std::visit(my_struct, a_variant);
>
> which only captures once instead of once per overload and as such could
> reduce the number of copies in these cases (the std::overload approach has
> other valid use-cases though ; there is place for both !).
>
> Being able to define structures inlines would simplify syntax a bit more:
>
> std::visit([=] struct {
> auto operator()(int v) { x+v; }
> auto operator()(float v) { x+v; }
> auto operator()(const std::string& v) { v[x]; }
> } , a_variant);
>
I like this idea. Just my 2bitcoins: I would change it to be always an
object. So the "my_struct" of above would then be
auto my_struct = [=] struct {
...
};
The rationale is that it prevents people from abusing it for things like
SomeThing<[=] struct { ... }> s;
IMO that will be a rare use-case and dangerous if it captures locals,
and it makes the more common object-case needlessly wordy. For that, I
would make a different proposal that drops the '[]', which would
always be a type
SomeThing<struct { ... }> s;
--
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/CANu6V4VXA0Ont7%3D6VrOW39CqTtWRoX44sUiCutxw9Ja8knKU5g%40mail.gmail.com.
.
Author: Jan Wilmans <janwilmans@gmail.com>
Date: Fri, 22 Dec 2017 23:25:39 +0100
Raw View
--001a1140ae440b8c080560f54da6
Content-Type: text/plain; charset="UTF-8"
Ok, and what purpose would it serve? What is the usecase?
--
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/CADtNNhgYKBRjhRJ-CBnGdO07xHoPRD0oYVAAxF54OhzcFhs33w%40mail.gmail.com.
--001a1140ae440b8c080560f54da6
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Ok, and what purpose would it serve? What is the usecase?<=
div><br></div><div class=3D"gmail_extra">
</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/CADtNNhgYKBRjhRJ-CBnGdO07xHoPRD0oYVAA=
xF54OhzcFhs33w%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CADtNNhgYKBRjhRJ-=
CBnGdO07xHoPRD0oYVAAxF54OhzcFhs33w%40mail.gmail.com</a>.<br />
--001a1140ae440b8c080560f54da6--
.
Author: Toby Allsopp <toby@mi6.gen.nz>
Date: Sat, 23 Dec 2017 02:45:06 -0800 (PST)
Raw View
------=_Part_10220_1147433915.1514025906174
Content-Type: multipart/alternative;
boundary="----=_Part_10221_57408619.1514025906174"
------=_Part_10221_57408619.1514025906174
Content-Type: text/plain; charset="UTF-8"
On Saturday, 23 December 2017 11:26:01 UTC+13, Jan Wilmans wrote:
>
> Ok, and what purpose would it serve? What is the usecase?
>
I fairly often wish for something like this. The case where I think it
would be a significant win is where you want to declare a local class
derived from some other class, as then you end up needing to write a
constructor.
For example:
struct base {
virtual ~base() = default;
virtual bool foo() = 0;
};
auto make_derived(bool b) {
struct derived : base {
explicit derived(bool b) : b(b) {}
bool b;
bool foo() override { return b; }
};
return derived{b};
}
It would be much more convenient (and easier to read) if I could instead
write something like:
auto make_derived(bool b) {
return struct [=] : base {
bool foo() override { return b; }
};
}
When I've thought about this in the past it's seemed like something that
would be really nice but doesn't really make anything new possible.
Cheers,
Toby.
--
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/6a8239fc-0c37-4537-9197-55d3221638ac%40isocpp.org.
------=_Part_10221_57408619.1514025906174
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Saturday, 23 December 2017 11:26:01 UTC+13, Jan Wilmans=
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">Ok, a=
nd what purpose would it serve? What is the usecase?</div></blockquote><div=
><br></div><div>I fairly often wish for something like this. The case where=
I think it would be a significant win is where you want to declare a local=
class derived from some other class, as then you end up needing to write a=
constructor.</div><div><br></div><div>For example:</div><div><br></div><di=
v><div style=3D"background-color: rgb(255, 255, 254); line-height: 19px;"><=
div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); bo=
rder-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; wor=
d-wrap: break-word;"><code class=3D"prettyprint" style=3D""><div class=3D"s=
ubprettyprint" style=3D""><font color=3D"#660066"><span style=3D"font-size:=
14px; white-space: pre;"><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">struct</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">base=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">virtual</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">~</span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">base</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">defau=
lt</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">virtual</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">bool</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> foo</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-p=
rettify">0</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">};</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> make_derived</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">bool</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> b</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">struct</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> derived </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">base</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">explicit</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> derived</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">bool</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> b</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> b</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">b</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">{}</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">bool</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> b</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">bool</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> foo</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">override</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #008;" class=3D"styled-by-prettify">return</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> b</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">};</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">return</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> derived</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">b</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</sp=
an></span></font><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br></span></div></code></div><br>It would be much more convenient (and eas=
ier to read) if I could instead write something like:</div></div><div style=
=3D"background-color: rgb(255, 255, 254); line-height: 19px;"><br></div><di=
v style=3D"background-color: rgb(255, 255, 254); line-height: 19px;"><div c=
lass=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-=
color: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wra=
p: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><=
span style=3D"" class=3D"styled-by-prettify"><div class=3D"subprettyprint" =
style=3D""><font color=3D"#000000">auto make_derived(bool b) {</font></div>=
<div class=3D"subprettyprint" style=3D""><font color=3D"#000000">=C2=A0 =C2=
=A0 return struct [=3D] : base {</font></div><div class=3D"subprettyprint" =
style=3D""><font color=3D"#000000">=C2=A0 =C2=A0 =C2=A0 =C2=A0 bool foo() o=
verride { return b; }</font></div><div class=3D"subprettyprint" style=3D"">=
<font color=3D"#000000">=C2=A0 =C2=A0 };</font></div><div class=3D"subprett=
yprint" style=3D""><font color=3D"#000000">}</font></div></span></div></cod=
e></div><br>When I've thought about this in the past it's seemed li=
ke something that would be really nice but doesn't really make anything=
new possible.</div><div style=3D"background-color: rgb(255, 255, 254); lin=
e-height: 19px;"><br></div><div style=3D"background-color: rgb(255, 255, 25=
4); line-height: 19px;">Cheers,</div><div style=3D"background-color: rgb(25=
5, 255, 254); line-height: 19px;">Toby.</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/6a8239fc-0c37-4537-9197-55d3221638ac%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/6a8239fc-0c37-4537-9197-55d3221638ac=
%40isocpp.org</a>.<br />
------=_Part_10221_57408619.1514025906174--
------=_Part_10220_1147433915.1514025906174--
.
Author: mihailnajdenov@gmail.com
Date: Sat, 23 Dec 2017 03:51:06 -0800 (PST)
Raw View
------=_Part_10302_134263369.1514029866384
Content-Type: multipart/alternative;
boundary="----=_Part_10303_1528168464.1514029866384"
------=_Part_10303_1528168464.1514029866384
Content-Type: text/plain; charset="UTF-8"
Agreed with Toby Allsopp above - it pops up from time to time (I have
almost *identical* code as the derived : base example, but in my case I was
passing a lambda to an interface, accepting a child of Collable interface
and I needed a stub) but there are plenty of workarounds and as mr. Allsopp
said - hardly enabling technology.
But there is more, I think.
First - universal captures are not the best practice in general, certainly
not some sort of recommendation.
Second - local classes, and this includes lambdas, are by definition *not*
stimulating code reuse AND easily lead to code bloat - [](auto a, auto b){
return a < b; } is worse then std::less<> almost in every way.
I don't think *any* form of local, anonymous classes should be encouraged,
especially now with structured bindings where we can use ugly (but
non-local and reusable) constructs, like pair and tuple, and make them
pretty to use.
>
--
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/62684972-eea7-476f-8a81-51dff40afe00%40isocpp.org.
------=_Part_10303_1528168464.1514029866384
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Agreed with=C2=A0<span style=3D"display: inline !impo=
rtant; float: none; background-color: transparent; color: rgb(34, 34, 34); =
font-family: "Arial","Helvetica",sans-serif; font-size:=
13px; font-style: normal; font-variant: normal; font-weight: 400; letter-s=
pacing: normal; orphans: 2; text-align: left; text-decoration: none; text-i=
ndent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-spa=
ce: normal; word-spacing: 0px;">Toby Allsopp above - it pops up from time t=
o time (I have almost *identical* code as the derived : base example, but i=
n my case I was passing a lambda to an interface, accepting a child of Coll=
able interface and I needed a stub) but there are plenty of workarounds and=
as mr.=C2=A0 <span style=3D"display: inline !important; float: none; backg=
round-color: transparent; color: rgb(34, 34, 34); font-family: "Arial&=
quot;,"Helvetica",sans-serif; font-size: 13px; font-style: normal=
; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: =
2; text-align: left; text-decoration: none; text-indent: 0px; text-transfor=
m: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing:=
0px;">Allsopp said - hardly enabling technology.</span></span></div><div><=
span style=3D"display: inline !important; float: none; background-color: tr=
ansparent; color: rgb(34, 34, 34); font-family: "Arial","Hel=
vetica",sans-serif; font-size: 13px; font-style: normal; font-variant:=
normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: =
left; text-decoration: none; text-indent: 0px; text-transform: none; -webki=
t-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"><span st=
yle=3D"display: inline !important; float: none; background-color: transpare=
nt; color: rgb(34, 34, 34); font-family: "Arial","Helvetica&=
quot;,sans-serif; font-size: 13px; font-style: normal; font-variant: normal=
; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; t=
ext-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-=
stroke-width: 0px; white-space: normal; word-spacing: 0px;"><br></span></sp=
an></div><div><span style=3D"display: inline !important; float: none; backg=
round-color: transparent; color: rgb(34, 34, 34); font-family: "Arial&=
quot;,"Helvetica",sans-serif; font-size: 13px; font-style: normal=
; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: =
2; text-align: left; text-decoration: none; text-indent: 0px; text-transfor=
m: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing:=
0px;"><span style=3D"display: inline !important; float: none; background-c=
olor: transparent; color: rgb(34, 34, 34); font-family: "Arial",&=
quot;Helvetica",sans-serif; font-size: 13px; font-style: normal; font-=
variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text=
-align: left; text-decoration: none; text-indent: 0px; text-transform: none=
; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;">=
<br></span></span></div><div><span style=3D"display: inline !important; flo=
at: none; background-color: transparent; color: rgb(34, 34, 34); font-famil=
y: "Arial","Helvetica",sans-serif; font-size: 13px; fon=
t-style: normal; font-variant: normal; font-weight: 400; letter-spacing: no=
rmal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px=
; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal=
; word-spacing: 0px;"><span style=3D"display: inline !important; float: non=
e; background-color: transparent; color: rgb(34, 34, 34); font-family: &quo=
t;Arial","Helvetica",sans-serif; font-size: 13px; font-style=
: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; o=
rphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-=
transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-=
spacing: 0px;">But there is more, I think. </span></span></div><div><span s=
tyle=3D"display: inline !important; float: none; background-color: transpar=
ent; color: rgb(34, 34, 34); font-family: "Arial","Helvetica=
",sans-serif; font-size: 13px; font-style: normal; font-variant: norma=
l; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; =
text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text=
-stroke-width: 0px; white-space: normal; word-spacing: 0px;"><span style=3D=
"display: inline !important; float: none; background-color: transparent; co=
lor: rgb(34, 34, 34); font-family: "Arial","Helvetica",=
sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font=
-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-de=
coration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke=
-width: 0px; white-space: normal; word-spacing: 0px;">First - universal cap=
tures are not the best practice in general, certainly not some sort of reco=
mmendation.</span></span></div><div><span style=3D"display: inline !importa=
nt; float: none; background-color: transparent; color: rgb(34, 34, 34); fon=
t-family: "Arial","Helvetica",sans-serif; font-size: 13=
px; font-style: normal; font-variant: normal; font-weight: 400; letter-spac=
ing: normal; orphans: 2; text-align: left; text-decoration: none; text-inde=
nt: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space:=
normal; word-spacing: 0px;"><span style=3D"display: inline !important; flo=
at: none; background-color: transparent; color: rgb(34, 34, 34); font-famil=
y: "Arial","Helvetica",sans-serif; font-size: 13px; fon=
t-style: normal; font-variant: normal; font-weight: 400; letter-spacing: no=
rmal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px=
; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal=
; word-spacing: 0px;">Second - local classes, and this includes lambdas, ar=
e by definition <i>not</i> stimulating code reuse AND easily lead to code b=
loat - [](auto a, auto b){ return a < b; } is worse then std::less<&g=
t; almost in every way.</span></span></div><div><span style=3D"display: inl=
ine !important; float: none; background-color: transparent; color: rgb(34, =
34, 34); font-family: "Arial","Helvetica",sans-serif; f=
ont-size: 13px; font-style: normal; font-variant: normal; font-weight: 400;=
letter-spacing: normal; orphans: 2; text-align: left; text-decoration: non=
e; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; =
white-space: normal; word-spacing: 0px;"><span style=3D"display: inline !im=
portant; float: none; background-color: transparent; color: rgb(34, 34, 34)=
; font-family: "Arial","Helvetica",sans-serif; font-siz=
e: 13px; font-style: normal; font-variant: normal; font-weight: 400; letter=
-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text=
-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-s=
pace: normal; word-spacing: 0px;"><br></span></span></div><div><span style=
=3D"display: inline !important; float: none; background-color: transparent;=
color: rgb(34, 34, 34); font-family: "Arial","Helvetica&quo=
t;,sans-serif; font-size: 13px; font-style: normal; font-variant: normal; f=
ont-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text=
-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-str=
oke-width: 0px; white-space: normal; word-spacing: 0px;"><span style=3D"dis=
play: inline !important; float: none; background-color: transparent; color:=
rgb(34, 34, 34); font-family: "Arial","Helvetica",sans=
-serif; font-size: 13px; font-style: normal; font-variant: normal; font-wei=
ght: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decora=
tion: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-wid=
th: 0px; white-space: normal; word-spacing: 0px;">I don't think *any* f=
orm of local, anonymous classes should be encouraged, especially now with s=
tructured bindings where we can use ugly (but non-local and reusable) const=
ructs, like pair and tuple, and make them pretty to use. =C2=A0</span></spa=
n></div><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"><div =
style=3D"background-color:rgb(255,255,254);line-height:19px"></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/62684972-eea7-476f-8a81-51dff40afe00%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/62684972-eea7-476f-8a81-51dff40afe00=
%40isocpp.org</a>.<br />
------=_Part_10303_1528168464.1514029866384--
------=_Part_10302_134263369.1514029866384--
.
Author: jeanmichael.celerier@gmail.com
Date: Sun, 24 Dec 2017 03:59:43 -0800 (PST)
Raw View
------=_Part_13061_2059528880.1514116783955
Content-Type: multipart/alternative;
boundary="----=_Part_13062_1844314417.1514116783956"
------=_Part_13062_1844314417.1514116783956
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Hi, thanks for your answers everyone :)=20
> but there are plenty of workarounds
indeed, but I think that langauges should evolve to remove the need for=20
workarounds.
> First - universal captures are not the best practice in general,=20
certainly not some sort of recommendation.
Yes, I only put a [=3D] as an example here but of course any kind of captur=
e=20
should be able to work.
> Second - local classes, and this includes lambdas, are by definition *not=
*=20
stimulating code reuse AND easily lead to code bloat - [](auto a, auto b){=
=20
return a < b; } is worse then std::less<> almost in every way.
I thoroughly disagree with this. Lambdas are the n=C2=B01 feature that made=
=20
working in modern C++ a remotely pleasant experience.=20
Why do you think that the lambda you posted is worse than std::less ?=20
A quick inspection show that the lambda version produces less code in GCC &=
=20
MSVC, and exactly the same code in Clang:=20
lambda: https://godbolt.org/g/rkG1k8
std::less: https://godbolt.org/g/Zdy9sP
If it didn't, it would certainly be a problem for your compiler's optimizer=
..
Interestingly, for MSVC there is a two-instructions difference in the=20
comparison itself:=20
std::less<void>::operator()<int &,int &>, COMDAT PROC
mov eax, DWORD PTR __Left$[esp-4]
mov ecx, DWORD PTR [eax]
mov eax, DWORD PTR __Right$[esp-4]
cmp ecx, DWORD PTR [eax]
setl al
ret 8
versus
??$?RHH@<lambda_e0791130af6ca6ee892f7f57d6208fb5>@@QBE_NHH@Z, COMDAT PROC
mov eax, DWORD PTR _x$[esp-4]
cmp eax, DWORD PTR _y$[esp-4]
setl al
ret 8
=20
certainly because std::less<> has an operator()(const T&, const U&) and we=
=20
could pass a comparator that works by value which could potentially grant=
=20
an additional small speed gain for ints.=20
This is another advantage (in my eyes) of using lambdas here: the ability=
=20
to optimize this kind of stuff on a per-case basis. Big elements ? pass by=
=20
const-ref. Small elements ? Go for pass-by-value. This could certainly be=
=20
genericized with Boost.CallTraits, but apparently GCC doesn't optimize this=
=20
any more than the std::less version : https://godbolt.org/g/EvzJmq and the=
=20
lambda version stays smaller, so for now it's still an overall win for=20
lambdas.=20
About code reuse, there are plenty of cases where it is meaningful, and=20
there are also plenty of cases where it is not. I have plenty of local=20
anonymous classes in my code, today, and I won't start giving them a name=
=20
just because. What matters in reuse is the public API, and more often than=
=20
not, anonymous structs are useful as implementation details for which you=
=20
want to be in the smallest possible scope. eg instead of making the functor=
=20
of std::apply / std::visit visible, I find it much clearer to to something=
=20
aking to :=20
auto my_public_api_function(const T& some_variant) {=20
struct {
double operator()(int x) { return x * 2.; }
double operator()(const std::string& x) { return x.size() * 2.; }
} vis;
return std::visit(vis, some_variant);
}
I don't think the struct here should be in any case part of the public API.
Likewise, for instance let's take the relatively common pattern of=20
iterating on a tuple, as seen in the brigand or other metaprogramming=20
libraries:=20
int count_kittens(std::tuple<KittiesA, KittiesB, KittiesC> tpl) {=20
int num_kittens =3D 0;
brigand::for_each<decltype(tpl)>([&] (const auto& kitties) { =20
num_kittens +=3D kitties.size(); }, tpl);
return num_kittens;
}
here, and more generally in static-polymorphism-heavy codebases, you don't=
=20
want to have a=20
struct kitten_counter {
template<typename T>
int operator()(const T& kitties) { return kitties.size(); }
};
int count_kittens(std::tuple<KittiesA, KittiesB, KittiesC> tpl) {=20
int num_kittens =3D 0;
brigand::for_each<decltype(tpl)>(kitten_counter{}, tpl);
return num_kittens;
}
This brings nothing good, just more pain for the one that will be reading=
=20
your code since he now has to scroll back and forth between two pieces of=
=20
code which entirely breaks the visual flow, and more pain for the one=20
writing your code since he now has to give a name to something that clearly=
=20
did not need one.
Likewise, I think that everyone using Qt can say that being able to use=20
lambdas for callbacks has really made using Qt5 a pleasure, instead of=20
going through the little dance of adding a new slot, local members to your=
=20
class that will keep the state necessary for this callback, etc etc...=20
every single time.
So, with that said, back to the proposal:=20
* It's 100% syntactic sugar.
* I agree with Johannes that it should be a value; this was just poorly=20
thought out. If someone wants a type he can just decltype() it anyways like=
=20
we can for lambda todays.
* The rationale is to provide more generalization in this age of whole=20
programs living in .hpp's and polymorphism moving towards static-ness if=20
possible, for instance with concepts:=20
The main thing that differenciate lambdas and "more general" anonymous=20
structs is that lambdas only have an operator()(...). But for instance if=
=20
your client code requires a more complex data structure with more than a=20
single operation and shared state between the operations (think builder=20
pattern where your client takes a builder in argument), then you currently=
=20
have to make the little dance with constructors that Toby showcased.=20
I argue that this distinction should not exist: the number of operations on=
=20
your datatype should not be a determining factor in saying "it's anonymous=
=20
and can capture" / "it should not be anonymous, and if it is it can't=20
capture anyways so you're in for some pain".
The last time I had this was for instance with some library code that=20
looked like this:=20
auto build_widget(T& widget_info, ...) {=20
auto sl =3D new QSlider{...};
sl->setRange(widget_info.get_min(), widget_info.get_max());
.. other setup-up stuff ..
return sl;
}
Some code was passing whole structs with other data as T, but at some point=
=20
I had to do something like:=20
{=20
int min =3D ...;
int max =3D ...;
if(whatever(max))=20
min =3D ...;
return build_slider(???, ...);
}
so, here, the ideal solution I want to be able to write is:=20
return build_slider([min,max] struct {=20
int get_min() { return min; } // like lambdas are, this should maybe=
=20
be const by default ?
int get_max() { return max; }
}, ...);
But currently, it looks like=20
struct {=20
int min, max;
int get_min() const { return min; }
int get_max() const { return max; }
} info{min, max};
=20
return build_slider(info, ...);
which needs more tokens, requires more names to find, and overall just=20
takes more time to read, write, and understand (now you have 2*2distinct=20
elements named min & max!) etc etc.
Best,
Jean-Micha=C3=ABl
On Saturday, December 23, 2017 at 12:51:06 PM UTC+1, mihailn...@gmail.com=
=20
wrote:
>
> Agreed with Toby Allsopp above - it pops up from time to time (I have=20
> almost *identical* code as the derived : base example, but in my case I w=
as=20
> passing a lambda to an interface, accepting a child of Collable interface=
=20
> and I needed a stub) but there are plenty of workarounds and as mr. Alls=
opp=20
> said - hardly enabling technology.
>
>
> But there is more, I think.=20
> First - universal captures are not the best practice in general, certainl=
y=20
> not some sort of recommendation.
> Second - local classes, and this includes lambdas, are by definition *not=
*=20
> stimulating code reuse AND easily lead to code bloat - [](auto a, auto b)=
{=20
> return a < b; } is worse then std::less<> almost in every way.
>
> I don't think *any* form of local, anonymous classes should be encouraged=
,=20
> especially now with structured bindings where we can use ugly (but=20
> non-local and reusable) constructs, like pair and tuple, and make them=20
> pretty to use. =20
>
>>
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/9dbc619c-55c3-4f3c-8412-613c03141126%40isocpp.or=
g.
------=_Part_13062_1844314417.1514116783956
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hi, thanks for your answers everyone :) <br><br>> <span=
style=3D"display:inline!important;float:none;background-color:transparent;=
color:rgb(34,34,34);font-family:"Arial","Helvetica",san=
s-serif;font-size:13px;font-style:normal;font-variant:normal;font-weight:40=
0;letter-spacing:normal;text-align:left;text-decoration:none;text-indent:0p=
x;text-transform:none;white-space:normal;word-spacing:0px">but there are pl=
enty of workarounds<br><br>indeed, but I think that langauges should evolve=
to remove the need for workarounds.<br><br> </span><div><span style=3D"dis=
play:inline!important;float:none;background-color:transparent;color:rgb(34,=
34,34);font-family:"Arial","Helvetica",sans-serif;font-=
size:13px;font-style:normal;font-variant:normal;font-weight:400;letter-spac=
ing:normal;text-align:left;text-decoration:none;text-indent:0px;text-transf=
orm:none;white-space:normal;word-spacing:0px"><span style=3D"display:inline=
!important;float:none;background-color:transparent;color:rgb(34,34,34);font=
-family:"Arial","Helvetica",sans-serif;font-size:13px;f=
ont-style:normal;font-variant:normal;font-weight:400;letter-spacing:normal;=
text-align:left;text-decoration:none;text-indent:0px;text-transform:none;wh=
ite-space:normal;word-spacing:0px">> First - universal captures are not =
the best practice in general, certainly not some sort of recommendation.</s=
pan></span></div><div><span style=3D"display:inline!important;float:none;ba=
ckground-color:transparent;color:rgb(34,34,34);font-family:"Arial"=
;,"Helvetica",sans-serif;font-size:13px;font-style:normal;font-va=
riant:normal;font-weight:400;letter-spacing:normal;text-align:left;text-dec=
oration:none;text-indent:0px;text-transform:none;white-space:normal;word-sp=
acing:0px"><span style=3D"display:inline!important;float:none;background-co=
lor:transparent;color:rgb(34,34,34);font-family:"Arial","Hel=
vetica",sans-serif;font-size:13px;font-style:normal;font-variant:norma=
l;font-weight:400;letter-spacing:normal;text-align:left;text-decoration:non=
e;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">=
<br></span></span></div><div><span style=3D"display:inline!important;float:=
none;background-color:transparent;color:rgb(34,34,34);font-family:"Ari=
al","Helvetica",sans-serif;font-size:13px;font-style:normal;=
font-variant:normal;font-weight:400;letter-spacing:normal;text-align:left;t=
ext-decoration:none;text-indent:0px;text-transform:none;white-space:normal;=
word-spacing:0px"><span style=3D"display:inline!important;float:none;backgr=
ound-color:transparent;color:rgb(34,34,34);font-family:"Arial",&q=
uot;Helvetica",sans-serif;font-size:13px;font-style:normal;font-varian=
t:normal;font-weight:400;letter-spacing:normal;text-align:left;text-decorat=
ion:none;text-indent:0px;text-transform:none;white-space:normal;word-spacin=
g:0px">Yes, I only put a [=3D] as an example here but of course any kind of=
capture should be able to work.<br></span></span></div><div><span style=3D=
"display:inline!important;float:none;background-color:transparent;color:rgb=
(34,34,34);font-family:"Arial","Helvetica",sans-serif;f=
ont-size:13px;font-style:normal;font-variant:normal;font-weight:400;letter-=
spacing:normal;text-align:left;text-decoration:none;text-indent:0px;text-tr=
ansform:none;white-space:normal;word-spacing:0px"><span style=3D"display:in=
line!important;float:none;background-color:transparent;color:rgb(34,34,34);=
font-family:"Arial","Helvetica",sans-serif;font-size:13=
px;font-style:normal;font-variant:normal;font-weight:400;letter-spacing:nor=
mal;text-align:left;text-decoration:none;text-indent:0px;text-transform:non=
e;white-space:normal;word-spacing:0px"><br></span></span></div><div><span s=
tyle=3D"display:inline!important;float:none;background-color:transparent;co=
lor:rgb(34,34,34);font-family:"Arial","Helvetica",sans-=
serif;font-size:13px;font-style:normal;font-variant:normal;font-weight:400;=
letter-spacing:normal;text-align:left;text-decoration:none;text-indent:0px;=
text-transform:none;white-space:normal;word-spacing:0px"><span style=3D"dis=
play:inline!important;float:none;background-color:transparent;color:rgb(34,=
34,34);font-family:"Arial","Helvetica",sans-serif;font-=
size:13px;font-style:normal;font-variant:normal;font-weight:400;letter-spac=
ing:normal;text-align:left;text-decoration:none;text-indent:0px;text-transf=
orm:none;white-space:normal;word-spacing:0px">></span></span><span style=
=3D"display:inline!important;float:none;background-color:transparent;color:=
rgb(34,34,34);font-family:"Arial","Helvetica",sans-seri=
f;font-size:13px;font-style:normal;font-variant:normal;font-weight:400;lett=
er-spacing:normal;text-align:left;text-decoration:none;text-indent:0px;text=
-transform:none;white-space:normal;word-spacing:0px"><span style=3D"display=
:inline!important;float:none;background-color:transparent;color:rgb(34,34,3=
4);font-family:"Arial","Helvetica",sans-serif;font-size=
:13px;font-style:normal;font-variant:normal;font-weight:400;letter-spacing:=
normal;text-align:left;text-decoration:none;text-indent:0px;text-transform:=
none;white-space:normal;word-spacing:0px"> Second - local classes, and this=
includes lambdas, are by definition <i>not</i>
stimulating code reuse AND easily lead to code bloat - [](auto a, auto=20
b){ return a < b; } is worse then std::less<> almost in every=20
way.</span></span></div><br>I thoroughly disagree with this. Lambdas are th=
e n=C2=B01 feature that made working in modern C++ a remotely pleasant expe=
rience. <br>Why do you think that the lambda you posted is worse than std::=
less ? <br>A quick inspection show that the lambda version produces less co=
de in GCC & MSVC, and exactly the same code in Clang: <br>lambda: https=
://godbolt.org/g/rkG1k8<br>std::less: https://godbolt.org/g/Zdy9sP<br><br>I=
f it didn't, it would certainly be a problem for your compiler's op=
timizer.<br><br>Interestingly, for MSVC there is a two-instructions differe=
nce in the comparison itself: <br><br><span style=3D"font-family: courier n=
ew, monospace;">std::less<void>::operator()<int &,int &>=
;, COMDAT PROC<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 mov=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0 eax, DWORD PTR __Left$[esp-4]<br>=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0 mov=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ecx, DWORD PTR [=
eax]<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 mov=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 eax, DWORD PTR __Right$[esp-4]<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 cmp=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ecx, DWORD PTR [eax]<br>=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 setl=C2=A0=C2=A0=C2=A0=C2=A0 al<br>=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ret=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0 8</span><br><br>versus<br><br><span style=3D"font-family: courier new, =
monospace;">??$?RHH@<lambda_e0791130af6ca6ee892f7f57d6208fb5>@@QBE_NH=
H@Z, COMDAT PROC<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 mov=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0 eax, DWORD PTR _x$[esp-4]<br>=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 cmp=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 eax, DWORD PTR _y$[esp=
-4]<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 setl=C2=A0=C2=A0=C2=A0=C2=
=A0 al<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ret=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 8</span><br>=C2=A0<br>certainly because std::less<> has =
an operator()(const T&, const U&) and we could pass a comparator th=
at works by value which could potentially grant an additional small speed g=
ain for ints. <br>This is another advantage (in my eyes) of using lambdas h=
ere: the ability to optimize this kind of stuff on a per-case basis. Big el=
ements ? pass by const-ref. Small elements ? Go for pass-by-value. This cou=
ld certainly be genericized with Boost.CallTraits, but apparently GCC doesn=
't optimize this any more than the std::less version : https://godbolt.=
org/g/EvzJmq and the lambda version stays smaller, so for now it's stil=
l an overall win for lambdas. <br><br>About code reuse, there are plenty of=
cases where it is meaningful, and there are also plenty of cases where it =
is not. I have plenty of local anonymous classes in my code, today, and I w=
on't start giving them a name just because. What matters in reuse is th=
e public API, and more often than not, anonymous structs are useful as impl=
ementation details for which you want to be in the smallest possible scope.=
eg instead of making the functor of std::apply / std::visit visible, I fin=
d it much clearer to to something aking to : <br><br><br>=C2=A0=C2=A0=C2=A0=
auto my_public_api_function(const T& some_variant) { <br>=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 struct {<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 double operator(=
)(int x) { return x * 2.; }<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 double operator(=
)(const std::string& x) { return x.size() * 2.; }<br>=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 } vis;<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return std::visit(vis=
, some_variant);<br>=C2=A0=C2=A0=C2=A0 }<br><br>I don't think the struc=
t here should be in any case part of the public API.<br>Likewise, for insta=
nce let's take the relatively common pattern of iterating on a tuple, a=
s seen in the brigand or other metaprogramming libraries: <br><br>=C2=A0=C2=
=A0=C2=A0 int count_kittens(std::tuple<KittiesA, KittiesB, KittiesC> =
tpl) { <br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int num_kittens =3D 0;<br>=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0 brigand::for_each<decltype(tpl)>([&] (co=
nst auto& kitties) {=C2=A0 num_kittens +=3D kitties.size(); }, tpl);<br=
>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return num_kittens;<br>=C2=A0=C2=A0=C2=A0 }=
<br><br>here, and more generally in static-polymorphism-heavy codebases, yo=
u don't want to have a <br><br>=C2=A0=C2=A0=C2=A0 struct kitten_counter=
{<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 template<typename T><br>=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0 int operator()(const T& kitties) { return kitt=
ies.size(); }<br>=C2=A0=C2=A0=C2=A0 };<br><br>=C2=A0=C2=A0=C2=A0 int count_=
kittens(std::tuple<KittiesA, KittiesB, KittiesC> tpl) { <br>=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0 int num_kittens =3D 0;<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0 brigand::for_each<decltype(tpl)>(kitten_counter{}, tpl);<br>=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 return num_kittens;<br>=C2=A0=C2=A0=C2=A0 }<br>=
<br>This brings nothing good, just more pain for the one that will be readi=
ng your code since he now has to scroll back and forth between two pieces o=
f code which entirely breaks the visual flow, and more pain for the one wri=
ting your code since he now has to give a name to something that clearly di=
d not need one.<br>Likewise, I think that everyone using Qt can say that be=
ing able to use lambdas for callbacks has really made using Qt5 a pleasure,=
instead of going through the little dance of adding a new slot, local memb=
ers to your class that will keep the state necessary for this callback, etc=
etc... every single time.<br><br>So, with that said, back to the proposal:=
<br><br>* It's 100% syntactic sugar.<br>* I agree with Johannes that i=
t should be a value; this was just poorly thought out. If someone wants a t=
ype he can just decltype() it anyways like we can for lambda todays.<br>* T=
he rationale is to provide more generalization in this age of whole program=
s living in .hpp's and polymorphism moving towards static-ness if possi=
ble, for instance with concepts: <br><br>The main thing that differenciate =
lambdas and "more general" anonymous structs is that lambdas only=
have an operator()(...). But for instance if your client code requires a m=
ore complex data structure with more than a single operation and shared sta=
te between the operations (think builder pattern where your client takes a =
builder in argument), then you currently have to make the little dance with=
constructors that Toby showcased. <br>I argue that this distinction should=
not exist: the number of operations on your datatype should not be a deter=
mining factor in saying "it's anonymous and can capture" / &q=
uot;it should not be anonymous, and if it is it can't capture anyways s=
o you're in for some pain".<br><br>The last time I had this was fo=
r instance with some library code that looked like this: <br><br>=C2=A0=C2=
=A0=C2=A0 auto build_widget(T& widget_info, ...) { <br>=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 auto sl =3D new QSlider{...};<br>=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 sl->setRange(widget_info.get_min(), widget_info.get_max());<br>=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .. other setup-up stuff ..<br>=C2=A0=C2=A0=
=C2=A0=C2=A0 return sl;<br>=C2=A0=C2=A0=C2=A0 }<br><br>Some code was passin=
g whole structs with other data as T, but at some point I had to do somethi=
ng like: <br><br>=C2=A0=C2=A0 { <br>=C2=A0=C2=A0=C2=A0=C2=A0 int min =3D ..=
..;<br>=C2=A0=C2=A0=C2=A0=C2=A0 int max =3D ...;<br>=C2=A0=C2=A0=C2=A0=C2=A0=
if(whatever(max)) <br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 min =3D ...;<br=
><br>=C2=A0=C2=A0=C2=A0=C2=A0 return build_slider(???, ...);<br>=C2=A0=C2=
=A0 }<br><br>so, here, the ideal solution I want to be able to write is: <b=
r><br>=C2=A0=C2=A0=C2=A0=C2=A0 return build_slider([min,max] struct { <br>=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int get_min() { return min; } // like =
lambdas are, this should maybe be const by default ?<br>=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 int get_max() { return max; }<br>=C2=A0=C2=A0=C2=A0=C2=
=A0 }, ...);<br><br><br>But currently, it looks like <br><br>=C2=A0=C2=A0 s=
truct { <br>=C2=A0=C2=A0=C2=A0=C2=A0 int min, max;<br>=C2=A0=C2=A0=C2=A0=C2=
=A0 int get_min() const { return min; }<br>=C2=A0=C2=A0=C2=A0=C2=A0 int get=
_max() const { return max; }<br>=C2=A0=C2=A0 } info{min, max};<br>=C2=A0=C2=
=A0 <br>=C2=A0=C2=A0 return build_slider(info, ...);<br><br>which needs mor=
e tokens, requires more names to find, and overall just takes more time to =
read, write, and understand (now you have 2*2distinct elements named min &a=
mp; max!) etc etc.<br><br>Best,<br>Jean-Micha=C3=ABl<br><br>On Saturday, De=
cember 23, 2017 at 12:51:06 PM UTC+1, mihailn...@gmail.com wrote:<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"><div>Agreed with=C2=A0<=
span style=3D"display:inline!important;float:none;background-color:transpar=
ent;color:rgb(34,34,34);font-family:"Arial","Helvetica"=
,sans-serif;font-size:13px;font-style:normal;font-variant:normal;font-weigh=
t:400;letter-spacing:normal;text-align:left;text-decoration:none;text-inden=
t:0px;text-transform:none;white-space:normal;word-spacing:0px">Toby Allsopp=
above - it pops up from time to time (I have almost *identical* code as th=
e derived : base example, but in my case I was passing a lambda to an inter=
face, accepting a child of Collable interface and I needed a stub) but ther=
e are plenty of workarounds and as mr.=C2=A0 <span style=3D"display:inline!=
important;float:none;background-color:transparent;color:rgb(34,34,34);font-=
family:"Arial","Helvetica",sans-serif;font-size:13px;fo=
nt-style:normal;font-variant:normal;font-weight:400;letter-spacing:normal;t=
ext-align:left;text-decoration:none;text-indent:0px;text-transform:none;whi=
te-space:normal;word-spacing:0px">Allsopp said - hardly enabling technology=
..</span></span></div><div><span style=3D"display:inline!important;float:non=
e;background-color:transparent;color:rgb(34,34,34);font-family:"Arial&=
quot;,"Helvetica",sans-serif;font-size:13px;font-style:normal;fon=
t-variant:normal;font-weight:400;letter-spacing:normal;text-align:left;text=
-decoration:none;text-indent:0px;text-transform:none;white-space:normal;wor=
d-spacing:0px"><span style=3D"display:inline!important;float:none;backgroun=
d-color:transparent;color:rgb(34,34,34);font-family:"Arial","=
;Helvetica",sans-serif;font-size:13px;font-style:normal;font-variant:n=
ormal;font-weight:400;letter-spacing:normal;text-align:left;text-decoration=
:none;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0=
px"><br></span></span></div><div><span style=3D"display:inline!important;fl=
oat:none;background-color:transparent;color:rgb(34,34,34);font-family:"=
;Arial","Helvetica",sans-serif;font-size:13px;font-style:nor=
mal;font-variant:normal;font-weight:400;letter-spacing:normal;text-align:le=
ft;text-decoration:none;text-indent:0px;text-transform:none;white-space:nor=
mal;word-spacing:0px"><span style=3D"display:inline!important;float:none;ba=
ckground-color:transparent;color:rgb(34,34,34);font-family:"Arial"=
;,"Helvetica",sans-serif;font-size:13px;font-style:normal;font-va=
riant:normal;font-weight:400;letter-spacing:normal;text-align:left;text-dec=
oration:none;text-indent:0px;text-transform:none;white-space:normal;word-sp=
acing:0px"><br></span></span></div><div><span style=3D"display:inline!impor=
tant;float:none;background-color:transparent;color:rgb(34,34,34);font-famil=
y:"Arial","Helvetica",sans-serif;font-size:13px;font-st=
yle:normal;font-variant:normal;font-weight:400;letter-spacing:normal;text-a=
lign:left;text-decoration:none;text-indent:0px;text-transform:none;white-sp=
ace:normal;word-spacing:0px"><span style=3D"display:inline!important;float:=
none;background-color:transparent;color:rgb(34,34,34);font-family:"Ari=
al","Helvetica",sans-serif;font-size:13px;font-style:normal;=
font-variant:normal;font-weight:400;letter-spacing:normal;text-align:left;t=
ext-decoration:none;text-indent:0px;text-transform:none;white-space:normal;=
word-spacing:0px">But there is more, I think. </span></span></div><div><spa=
n style=3D"display:inline!important;float:none;background-color:transparent=
;color:rgb(34,34,34);font-family:"Arial","Helvetica",sa=
ns-serif;font-size:13px;font-style:normal;font-variant:normal;font-weight:4=
00;letter-spacing:normal;text-align:left;text-decoration:none;text-indent:0=
px;text-transform:none;white-space:normal;word-spacing:0px"><span style=3D"=
display:inline!important;float:none;background-color:transparent;color:rgb(=
34,34,34);font-family:"Arial","Helvetica",sans-serif;fo=
nt-size:13px;font-style:normal;font-variant:normal;font-weight:400;letter-s=
pacing:normal;text-align:left;text-decoration:none;text-indent:0px;text-tra=
nsform:none;white-space:normal;word-spacing:0px">First - universal captures=
are not the best practice in general, certainly not some sort of recommend=
ation.</span></span></div><div><span style=3D"display:inline!important;floa=
t:none;background-color:transparent;color:rgb(34,34,34);font-family:"A=
rial","Helvetica",sans-serif;font-size:13px;font-style:norma=
l;font-variant:normal;font-weight:400;letter-spacing:normal;text-align:left=
;text-decoration:none;text-indent:0px;text-transform:none;white-space:norma=
l;word-spacing:0px"><span style=3D"display:inline!important;float:none;back=
ground-color:transparent;color:rgb(34,34,34);font-family:"Arial",=
"Helvetica",sans-serif;font-size:13px;font-style:normal;font-vari=
ant:normal;font-weight:400;letter-spacing:normal;text-align:left;text-decor=
ation:none;text-indent:0px;text-transform:none;white-space:normal;word-spac=
ing:0px">Second - local classes, and this includes lambdas, are by definiti=
on <i>not</i> stimulating code reuse AND easily lead to code bloat - [](aut=
o a, auto b){ return a < b; } is worse then std::less<> almost in =
every way.</span></span></div><div><span style=3D"display:inline!important;=
float:none;background-color:transparent;color:rgb(34,34,34);font-family:&qu=
ot;Arial","Helvetica",sans-serif;font-size:13px;font-style:n=
ormal;font-variant:normal;font-weight:400;letter-spacing:normal;text-align:=
left;text-decoration:none;text-indent:0px;text-transform:none;white-space:n=
ormal;word-spacing:0px"><span style=3D"display:inline!important;float:none;=
background-color:transparent;color:rgb(34,34,34);font-family:"Arial&qu=
ot;,"Helvetica",sans-serif;font-size:13px;font-style:normal;font-=
variant:normal;font-weight:400;letter-spacing:normal;text-align:left;text-d=
ecoration:none;text-indent:0px;text-transform:none;white-space:normal;word-=
spacing:0px"><br></span></span></div><div><span style=3D"display:inline!imp=
ortant;float:none;background-color:transparent;color:rgb(34,34,34);font-fam=
ily:"Arial","Helvetica",sans-serif;font-size:13px;font-=
style:normal;font-variant:normal;font-weight:400;letter-spacing:normal;text=
-align:left;text-decoration:none;text-indent:0px;text-transform:none;white-=
space:normal;word-spacing:0px"><span style=3D"display:inline!important;floa=
t:none;background-color:transparent;color:rgb(34,34,34);font-family:"A=
rial","Helvetica",sans-serif;font-size:13px;font-style:norma=
l;font-variant:normal;font-weight:400;letter-spacing:normal;text-align:left=
;text-decoration:none;text-indent:0px;text-transform:none;white-space:norma=
l;word-spacing:0px">I don't think *any* form of local, anonymous classe=
s should be encouraged, especially now with structured bindings where we ca=
n use ugly (but non-local and reusable) constructs, like pair and tuple, an=
d make them pretty to use. =C2=A0</span></span></div><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"><div style=3D"background-color:rgb(255,2=
55,254);line-height:19px"></div></div></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/9dbc619c-55c3-4f3c-8412-613c03141126%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/9dbc619c-55c3-4f3c-8412-613c03141126=
%40isocpp.org</a>.<br />
------=_Part_13062_1844314417.1514116783956--
------=_Part_13061_2059528880.1514116783955--
.
Author: jeanmichael.celerier@gmail.com
Date: Sun, 24 Dec 2017 04:12:31 -0800 (PST)
Raw View
------=_Part_13028_29328720.1514117551648
Content-Type: multipart/alternative;
boundary="----=_Part_13029_918833787.1514117551649"
------=_Part_13029_918833787.1514117551649
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Here's a practical example of code that could be much simplified:=20
boost.graph's visitors.
For instance, depth-first search requires you to pass a structure with a=20
bunch of operations (see "visitor event points") though most of them are=20
optional:=20
http://www.boost.org/doc/libs/1_61_0/libs/graph/doc/depth_first_search.html=
=20
Here's a code example:=20
http://www.boost.org/doc/libs/1_61_0/libs/graph/example/dfs-example.cpp
With this proposal (and assuming that other lambda-niceties propagate to=20
it, such as auto parameters), it would become:=20
https://paste.ofcode.org/DysGbFTUjyg8Rg3yi8xi8K
which is, I think, much less intimidating for the one wanting to delve into=
=20
boost.graph.
Best,
Jean-Micha=C3=ABl
--=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/a6ea96bd-98a7-4af6-a391-c56db59a1b5c%40isocpp.or=
g.
------=_Part_13029_918833787.1514117551649
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Here's a practical example of code that could be much =
simplified: boost.graph's visitors.<br><br>For instance, depth-first se=
arch requires you to pass a structure with a bunch of operations (see "=
;visitor event points") though most of them are optional: <br>http://w=
ww.boost.org/doc/libs/1_61_0/libs/graph/doc/depth_first_search.html <br><br=
>Here's a code example: <br>http://www.boost.org/doc/libs/1_61_0/libs/g=
raph/example/dfs-example.cpp<br><br>With this proposal (and assuming that o=
ther lambda-niceties propagate to it, such as auto parameters), it would be=
come: <br><br>https://paste.ofcode.org/DysGbFTUjyg8Rg3yi8xi8K<br><br>which =
is, I think, much less intimidating for the one wanting to delve into boost=
..graph.<br><br>Best,<br>Jean-Micha=C3=ABl<br></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/a6ea96bd-98a7-4af6-a391-c56db59a1b5c%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/a6ea96bd-98a7-4af6-a391-c56db59a1b5c=
%40isocpp.org</a>.<br />
------=_Part_13029_918833787.1514117551649--
------=_Part_13028_29328720.1514117551648--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Sun, 24 Dec 2017 10:22:04 -0200
Raw View
On domingo, 24 de dezembro de 2017 09:59:43 -02 jeanmichael.celerier@gmail.com
wrote:
> std::less<void>::operator()<int &,int &>, COMDAT PROC
> mov eax, DWORD PTR __Left$[esp-4]
> mov ecx, DWORD PTR [eax]
> mov eax, DWORD PTR __Right$[esp-4]
> cmp ecx, DWORD PTR [eax]
> setl al
> ret 8
>
> versus
>
> ??$?RHH@<lambda_e0791130af6ca6ee892f7f57d6208fb5>@@QBE_NHH@Z, COMDAT PROC
> mov eax, DWORD PTR _x$[esp-4]
> cmp eax, DWORD PTR _y$[esp-4]
> setl al
> ret 8
>
> certainly because std::less<> has an operator()(const T&, const U&) and we
> could pass a comparator that works by value which could potentially grant
> an additional small speed gain for ints.
Please stop using 32-bit for code comparison. You'd see the difference more
clearly if you had used 64-bit.
The difference is one passes int by value, the other by reference.
It's also shown in the function signatures: one has a pair of int&, the other
has two H (int).
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
--
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/1608302.FR7qnZ4Jv4%40tjmaciei-mobl1.
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sun, 24 Dec 2017 07:05:20 -0800 (PST)
Raw View
------=_Part_12925_80054767.1514127920320
Content-Type: multipart/alternative;
boundary="----=_Part_12926_916439454.1514127920321"
------=_Part_12926_916439454.1514127920321
Content-Type: text/plain; charset="UTF-8"
On Sunday, December 24, 2017 at 7:12:31 AM UTC-5, jeanmichae...@gmail.com
wrote:
>
> Here's a practical example of code that could be much simplified:
> boost.graph's visitors.
>
> For instance, depth-first search requires you to pass a structure with a
> bunch of operations (see "visitor event points") though most of them are
> optional:
> http://www.boost.org/doc/libs/1_61_0/libs/graph/doc/depth_first_search.html
>
> Here's a code example:
> http://www.boost.org/doc/libs/1_61_0/libs/graph/example/dfs-example.cpp
>
> With this proposal (and assuming that other lambda-niceties propagate to
> it, such as auto parameters), it would become:
>
> https://paste.ofcode.org/DysGbFTUjyg8Rg3yi8xi8K
>
> which is, I think, much less intimidating for the one wanting to delve
> into boost.graph.
>
So you've taken this:
template < typename TimeMap > class dfs_time_visitor:public
default_dfs_visitor {
typedef typename property_traits < TimeMap >::value_type T;
public:
dfs_time_visitor(TimeMap dmap, TimeMap fmap, T & t)
: m_dtimemap(dmap), m_ftimemap(fmap), m_time(t) {
}
void discover_vertex(auto u, const auto & g) const
{
put(m_dtimemap, u, m_time++);
}
void finish_vertex(auto u, const auto & g) const
{
put(m_ftimemap, u, m_time++);
}
TimeMap m_dtimemap;
TimeMap m_ftimemap;
T & m_time;
};
And turned it into this:
typedef
iterator_property_map<std::vector<size_type>::iterator,
property_map<graph_t, vertex_index_t>::const_type>
time_pm_type;
time_pm_type dtime_pm(dtime.begin(), get(vertex_index, g));
time_pm_type ftime_pm(ftime.begin(), get(vertex_index, g));
size_type t = 0;
auto vis = [dtime_pm,ftime_pm,&t] struct : default_dfs_visitor {
void discover_vertex(auto u, const auto& g) const
{
put(dtime_pm, u, t++);
}
void finish_vertex(auto u, const auto& g) const
{
put(ftime_pm, u, t++);
}
};
Note that I have regularized the two examples. That is, I put the same kind
of spacing between function in both, and I used `auto` parameters in the
first one, since you're presuming you can use them in the second.
Even so, all you've really done is take the struct members and put them*
outside* of the struct. What good did that accomplish, exactly?
I just don't see the advantage here. Especially since you can put the
struct definition inside of the function already.
--
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/5064ca80-a30d-4f50-8058-9874bb53a815%40isocpp.org.
------=_Part_12926_916439454.1514127920321
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Sunday, December 24, 2017 at 7:12:31 AM UTC-5, =
jeanmichae...@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"ma=
rgin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">=
<div dir=3D"ltr">Here's a practical example of code that could be much =
simplified: boost.graph's visitors.<br><br>For instance, depth-first se=
arch requires you to pass a structure with a bunch of operations (see "=
;visitor event points") though most of them are optional: <br><a onmou=
sedown=3D"this.href=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.=
boost.org%2Fdoc%2Flibs%2F1_61_0%2Flibs%2Fgraph%2Fdoc%2Fdepth_first_search.h=
tml\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGdvtHhhyObZKI9cvJnc_H-O8WmJQ=
9;;return true;" onclick=3D"this.href=3D'http://www.google.com/url?q\x3=
dhttp%3A%2F%2Fwww.boost.org%2Fdoc%2Flibs%2F1_61_0%2Flibs%2Fgraph%2Fdoc%2Fde=
pth_first_search.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGdvtHhhyObZKI=
9cvJnc_H-O8WmJQ';return true;" href=3D"http://www.boost.org/doc/libs/1_=
61_0/libs/graph/doc/depth_first_search.html" target=3D"_blank" rel=3D"nofol=
low">http://www.boost.org/doc/libs/<wbr>1_61_0/libs/graph/doc/depth_<wbr>fi=
rst_search.html</a> <br><br>Here's a code example: <br><a onmousedown=
=3D"this.href=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.boost.=
org%2Fdoc%2Flibs%2F1_61_0%2Flibs%2Fgraph%2Fexample%2Fdfs-example.cpp\x26sa\=
x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGLQtNSEHNYbANg7JjIlVYlSLFGSg';return =
true;" onclick=3D"this.href=3D'http://www.google.com/url?q\x3dhttp%3A%2=
F%2Fwww.boost.org%2Fdoc%2Flibs%2F1_61_0%2Flibs%2Fgraph%2Fexample%2Fdfs-exam=
ple.cpp\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGLQtNSEHNYbANg7JjIlVYlSLFGS=
g';return true;" href=3D"http://www.boost.org/doc/libs/1_61_0/libs/grap=
h/example/dfs-example.cpp" target=3D"_blank" rel=3D"nofollow">http://www.bo=
ost.org/doc/libs/<wbr>1_61_0/libs/graph/example/dfs-<wbr>example.cpp</a><br=
><br>With this proposal (and assuming that other lambda-niceties propagate =
to it, such as auto parameters), it would become: <br><br><a onmousedown=3D=
"this.href=3D'https://www.google.com/url?q\x3dhttps%3A%2F%2Fpaste.ofcod=
e.org%2FDysGbFTUjyg8Rg3yi8xi8K\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGks2=
ws6kHBc94sP-unZf5dvXb3xQ';return true;" onclick=3D"this.href=3D'htt=
ps://www.google.com/url?q\x3dhttps%3A%2F%2Fpaste.ofcode.org%2FDysGbFTUjyg8R=
g3yi8xi8K\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGks2ws6kHBc94sP-unZf5dvXb=
3xQ';return true;" href=3D"https://paste.ofcode.org/DysGbFTUjyg8Rg3yi8x=
i8K" target=3D"_blank" rel=3D"nofollow">https://paste.ofcode.org/<wbr>DysGb=
FTUjyg8Rg3yi8xi8K</a><br><br>which is, I think, much less intimidating for =
the one wanting to delve into boost.graph.<br></div></blockquote><div><br><=
/div><div>So you've taken this:</div><div><br></div><div class=3D"prett=
yprint" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-wor=
d; background-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div =
class=3D"subprettyprint"><span class=3D"styled-by-prettify" style=3D"color:=
#008;">template</span><span class=3D"styled-by-prettify" style=3D"color: #=
000;"> </span><span class=3D"styled-by-prettify" style=3D"color: #660;"><=
;</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> </span><=
span class=3D"styled-by-prettify" style=3D"color: #008;">typename</span><sp=
an class=3D"styled-by-prettify" style=3D"color: #000;"> </span><span class=
=3D"styled-by-prettify" style=3D"color: #606;">TimeMap</span><span class=3D=
"styled-by-prettify" style=3D"color: #000;"> </span><span class=3D"styled-b=
y-prettify" style=3D"color: #660;">></span><span class=3D"styled-by-pret=
tify" style=3D"color: #000;"> </span><span class=3D"styled-by-prettify" sty=
le=3D"color: #008;">class</span><span class=3D"styled-by-prettify" style=3D=
"color: #000;"> dfs_time_visitor</span><span class=3D"styled-by-prettify" s=
tyle=3D"color: #660;">:</span><span class=3D"styled-by-prettify" style=3D"c=
olor: #008;">public</span><span class=3D"styled-by-prettify" style=3D"color=
: #000;"> default_dfs_visitor </span><span class=3D"styled-by-prettify" sty=
le=3D"color: #660;">{</span><span class=3D"styled-by-prettify" style=3D"col=
or: #000;"><br>=C2=A0 =C2=A0 </span><span class=3D"styled-by-prettify" styl=
e=3D"color: #008;">typedef</span><span class=3D"styled-by-prettify" style=
=3D"color: #000;"> </span><span class=3D"styled-by-prettify" style=3D"color=
: #008;">typename</span><span class=3D"styled-by-prettify" style=3D"color: =
#000;"> property_traits </span><span class=3D"styled-by-prettify" style=3D"=
color: #660;"><</span><span class=3D"styled-by-prettify" style=3D"color:=
#000;"> </span><span class=3D"styled-by-prettify" style=3D"color: #606;">T=
imeMap</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> </s=
pan><span class=3D"styled-by-prettify" style=3D"color: #660;">>::</span>=
<span class=3D"styled-by-prettify" style=3D"color: #000;">value_type T</spa=
n><span class=3D"styled-by-prettify" style=3D"color: #660;">;</span><span c=
lass=3D"styled-by-prettify" style=3D"color: #000;"><br></span><span class=
=3D"styled-by-prettify" style=3D"color: #008;">public</span><span class=3D"=
styled-by-prettify" style=3D"color: #660;">:</span><span class=3D"styled-by=
-prettify" style=3D"color: #000;"><br>=C2=A0 =C2=A0 dfs_time_visitor</span>=
<span class=3D"styled-by-prettify" style=3D"color: #660;">(</span><span cla=
ss=3D"styled-by-prettify" style=3D"color: #606;">TimeMap</span><span class=
=3D"styled-by-prettify" style=3D"color: #000;"> dmap</span><span class=3D"s=
tyled-by-prettify" style=3D"color: #660;">,</span><span class=3D"styled-by-=
prettify" style=3D"color: #000;"> </span><span class=3D"styled-by-prettify"=
style=3D"color: #606;">TimeMap</span><span class=3D"styled-by-prettify" st=
yle=3D"color: #000;"> fmap</span><span class=3D"styled-by-prettify" style=
=3D"color: #660;">,</span><span class=3D"styled-by-prettify" style=3D"color=
: #000;"> T </span><span class=3D"styled-by-prettify" style=3D"color: #660;=
">&</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> t<=
/span><span class=3D"styled-by-prettify" style=3D"color: #660;">)</span><sp=
an class=3D"styled-by-prettify" style=3D"color: #000;"><br>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 </span><span class=3D"styled-by-prettify" style=3D"color: #66=
0;">:</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> =C2=
=A0m_dtimemap</span><span class=3D"styled-by-prettify" style=3D"color: #660=
;">(</span><span class=3D"styled-by-prettify" style=3D"color: #000;">dmap</=
span><span class=3D"styled-by-prettify" style=3D"color: #660;">),</span><sp=
an class=3D"styled-by-prettify" style=3D"color: #000;"> m_ftimemap</span><s=
pan class=3D"styled-by-prettify" style=3D"color: #660;">(</span><span class=
=3D"styled-by-prettify" style=3D"color: #000;">fmap</span><span class=3D"st=
yled-by-prettify" style=3D"color: #660;">),</span><span class=3D"styled-by-=
prettify" style=3D"color: #000;"> m_time</span><span class=3D"styled-by-pre=
ttify" style=3D"color: #660;">(</span><span class=3D"styled-by-prettify" st=
yle=3D"color: #000;">t</span><span class=3D"styled-by-prettify" style=3D"co=
lor: #660;">)</span><span class=3D"styled-by-prettify" style=3D"color: #000=
;"> </span><span class=3D"styled-by-prettify" style=3D"color: #660;">{</spa=
n><span class=3D"styled-by-prettify" style=3D"color: #000;"><br>=C2=A0 =C2=
=A0 </span><span class=3D"styled-by-prettify" style=3D"color: #660;">}</spa=
n><span class=3D"styled-by-prettify" style=3D"color: #000;"><br><br>=C2=A0 =
=C2=A0 </span><span class=3D"styled-by-prettify" style=3D"color: #008;">voi=
d</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> discover=
_vertex</span><span class=3D"styled-by-prettify" style=3D"color: #660;">(</=
span><span class=3D"styled-by-prettify" style=3D"color: #008;">auto</span><=
span class=3D"styled-by-prettify" style=3D"color: #000;"> u</span><span cla=
ss=3D"styled-by-prettify" style=3D"color: #660;">,</span><span class=3D"sty=
led-by-prettify" style=3D"color: #000;"> </span><span class=3D"styled-by-pr=
ettify" style=3D"color: #008;">const</span><span class=3D"styled-by-prettif=
y" style=3D"color: #000;"> </span><span class=3D"styled-by-prettify" style=
=3D"color: #008;">auto</span><span class=3D"styled-by-prettify" style=3D"co=
lor: #000;"> </span><span class=3D"styled-by-prettify" style=3D"color: #660=
;">&</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> g=
</span><span class=3D"styled-by-prettify" style=3D"color: #660;">)</span><s=
pan class=3D"styled-by-prettify" style=3D"color: #000;"> </span><span class=
=3D"styled-by-prettify" style=3D"color: #008;">const</span><span class=3D"s=
tyled-by-prettify" style=3D"color: #000;"><br>=C2=A0 =C2=A0 </span><span cl=
ass=3D"styled-by-prettify" style=3D"color: #660;">{</span><span class=3D"st=
yled-by-prettify" style=3D"color: #000;"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 pu=
t</span><span class=3D"styled-by-prettify" style=3D"color: #660;">(</span><=
span class=3D"styled-by-prettify" style=3D"color: #000;">m_dtimemap</span><=
span class=3D"styled-by-prettify" style=3D"color: #660;">,</span><span clas=
s=3D"styled-by-prettify" style=3D"color: #000;"> u</span><span class=3D"sty=
led-by-prettify" style=3D"color: #660;">,</span><span class=3D"styled-by-pr=
ettify" style=3D"color: #000;"> m_time</span><span class=3D"styled-by-prett=
ify" style=3D"color: #660;">++);</span><span class=3D"styled-by-prettify" s=
tyle=3D"color: #000;"><br>=C2=A0 =C2=A0 </span><span class=3D"styled-by-pre=
ttify" style=3D"color: #660;">}</span><span class=3D"styled-by-prettify" st=
yle=3D"color: #000;"><br><br>=C2=A0 =C2=A0 </span><span class=3D"styled-by-=
prettify" style=3D"color: #008;">void</span><span class=3D"styled-by-pretti=
fy" style=3D"color: #000;"> finish_vertex</span><span class=3D"styled-by-pr=
ettify" style=3D"color: #660;">(</span><span class=3D"styled-by-prettify" s=
tyle=3D"color: #008;">auto</span><span class=3D"styled-by-prettify" style=
=3D"color: #000;"> u</span><span class=3D"styled-by-prettify" style=3D"colo=
r: #660;">,</span><span class=3D"styled-by-prettify" style=3D"color: #000;"=
> </span><span class=3D"styled-by-prettify" style=3D"color: #008;">const</s=
pan><span class=3D"styled-by-prettify" style=3D"color: #000;"> </span><span=
class=3D"styled-by-prettify" style=3D"color: #008;">auto</span><span class=
=3D"styled-by-prettify" style=3D"color: #000;"> </span><span class=3D"style=
d-by-prettify" style=3D"color: #660;">&</span><span class=3D"styled-by-=
prettify" style=3D"color: #000;"> g</span><span class=3D"styled-by-prettify=
" style=3D"color: #660;">)</span><span class=3D"styled-by-prettify" style=
=3D"color: #000;"> </span><span class=3D"styled-by-prettify" style=3D"color=
: #008;">const</span><span class=3D"styled-by-prettify" style=3D"color: #00=
0;"><br>=C2=A0 =C2=A0 </span><span class=3D"styled-by-prettify" style=3D"co=
lor: #660;">{</span><span class=3D"styled-by-prettify" style=3D"color: #000=
;"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 put</span><span class=3D"styled-by-prett=
ify" style=3D"color: #660;">(</span><span class=3D"styled-by-prettify" styl=
e=3D"color: #000;">m_ftimemap</span><span class=3D"styled-by-prettify" styl=
e=3D"color: #660;">,</span><span class=3D"styled-by-prettify" style=3D"colo=
r: #000;"> u</span><span class=3D"styled-by-prettify" style=3D"color: #660;=
">,</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> m_time=
</span><span class=3D"styled-by-prettify" style=3D"color: #660;">++);</span=
><span class=3D"styled-by-prettify" style=3D"color: #000;"><br>=C2=A0 =C2=
=A0 </span><span class=3D"styled-by-prettify" style=3D"color: #660;">}</spa=
n><span class=3D"styled-by-prettify" style=3D"color: #000;"><br>=C2=A0<br>=
=C2=A0 =C2=A0 </span><span class=3D"styled-by-prettify" style=3D"color: #60=
6;">TimeMap</span><span class=3D"styled-by-prettify" style=3D"color: #000;"=
> m_dtimemap</span><span class=3D"styled-by-prettify" style=3D"color: #660;=
">;</span><span class=3D"styled-by-prettify" style=3D"color: #000;"><br>=C2=
=A0 =C2=A0 </span><span class=3D"styled-by-prettify" style=3D"color: #606;"=
>TimeMap</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> m=
_ftimemap</span><span class=3D"styled-by-prettify" style=3D"color: #660;">;=
</span><span class=3D"styled-by-prettify" style=3D"color: #000;"><br>=C2=A0=
=C2=A0 T </span><span class=3D"styled-by-prettify" style=3D"color: #660;">=
&</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> m_ti=
me</span><span class=3D"styled-by-prettify" style=3D"color: #660;">;</span>=
<span class=3D"styled-by-prettify" style=3D"color: #000;"><br></span><span =
class=3D"styled-by-prettify" style=3D"color: #660;">};</span></div></code><=
/div><div><br></div><div>And turned it into this:</div><div><br></div><div =
class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); word-w=
rap: break-word; background-color: rgb(250, 250, 250);"><code class=3D"pret=
typrint"><div class=3D"subprettyprint"><span class=3D"styled-by-prettify" s=
tyle=3D"color: #008;">typedef</span><span class=3D"styled-by-prettify" styl=
e=3D"color: #000;"><br>iterator_property_map</span><span class=3D"styled-by=
-prettify" style=3D"color: #660;"><</span><span class=3D"styled-by-prett=
ify" style=3D"color: #000;">std</span><span class=3D"styled-by-prettify" st=
yle=3D"color: #660;">::</span><span class=3D"styled-by-prettify" style=3D"c=
olor: #000;">vector</span><span class=3D"styled-by-prettify" style=3D"color=
: #080;"><size_type></span><span class=3D"styled-by-prettify" style=
=3D"color: #660;">::</span><span class=3D"styled-by-prettify" style=3D"colo=
r: #000;">iterator</span><span class=3D"styled-by-prettify" style=3D"color:=
#660;">,</span><span class=3D"styled-by-prettify" style=3D"color: #000;"><=
br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 property_map</span><span class=3D"styled-by-=
prettify" style=3D"color: #660;"><</span><span class=3D"styled-by-pretti=
fy" style=3D"color: #000;">graph_t</span><span class=3D"styled-by-prettify"=
style=3D"color: #660;">,</span><span class=3D"styled-by-prettify" style=3D=
"color: #000;"> vertex_index_t</span><span class=3D"styled-by-prettify" sty=
le=3D"color: #660;">>::</span><span class=3D"styled-by-prettify" style=
=3D"color: #000;">const_type</span><span class=3D"styled-by-prettify" style=
=3D"color: #660;">></span><span class=3D"styled-by-prettify" style=3D"co=
lor: #000;"><br>time_pm_type</span><span class=3D"styled-by-prettify" style=
=3D"color: #660;">;</span><span class=3D"styled-by-prettify" style=3D"color=
: #000;"><br>time_pm_type dtime_pm</span><span class=3D"styled-by-prettify"=
style=3D"color: #660;">(</span><span class=3D"styled-by-prettify" style=3D=
"color: #000;">dtime</span><span class=3D"styled-by-prettify" style=3D"colo=
r: #660;">.</span><span class=3D"styled-by-prettify" style=3D"color: #008;"=
>begin</span><span class=3D"styled-by-prettify" style=3D"color: #660;">(),<=
/span><span class=3D"styled-by-prettify" style=3D"color: #000;"> </span><sp=
an class=3D"styled-by-prettify" style=3D"color: #008;">get</span><span clas=
s=3D"styled-by-prettify" style=3D"color: #660;">(</span><span class=3D"styl=
ed-by-prettify" style=3D"color: #000;">vertex_index</span><span class=3D"st=
yled-by-prettify" style=3D"color: #660;">,</span><span class=3D"styled-by-p=
rettify" style=3D"color: #000;"> g</span><span class=3D"styled-by-prettify"=
style=3D"color: #660;">));</span><span class=3D"styled-by-prettify" style=
=3D"color: #000;"><br>time_pm_type ftime_pm</span><span class=3D"styled-by-=
prettify" style=3D"color: #660;">(</span><span class=3D"styled-by-prettify"=
style=3D"color: #000;">ftime</span><span class=3D"styled-by-prettify" styl=
e=3D"color: #660;">.</span><span class=3D"styled-by-prettify" style=3D"colo=
r: #008;">begin</span><span class=3D"styled-by-prettify" style=3D"color: #6=
60;">(),</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> <=
/span><span class=3D"styled-by-prettify" style=3D"color: #008;">get</span><=
span class=3D"styled-by-prettify" style=3D"color: #660;">(</span><span clas=
s=3D"styled-by-prettify" style=3D"color: #000;">vertex_index</span><span cl=
ass=3D"styled-by-prettify" style=3D"color: #660;">,</span><span class=3D"st=
yled-by-prettify" style=3D"color: #000;"> g</span><span class=3D"styled-by-=
prettify" style=3D"color: #660;">));</span><span class=3D"styled-by-prettif=
y" style=3D"color: #000;"><br>size_type t </span><span class=3D"styled-by-p=
rettify" style=3D"color: #660;">=3D</span><span class=3D"styled-by-prettify=
" style=3D"color: #000;"> </span><span class=3D"styled-by-prettify" style=
=3D"color: #066;">0</span><span class=3D"styled-by-prettify" style=3D"color=
: #660;">;</span><span class=3D"styled-by-prettify" style=3D"color: #000;">=
<br><br></span><span class=3D"styled-by-prettify" style=3D"color: #008;">au=
to</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> vis </s=
pan><span class=3D"styled-by-prettify" style=3D"color: #660;">=3D</span><sp=
an class=3D"styled-by-prettify" style=3D"color: #000;"> </span><span class=
=3D"styled-by-prettify" style=3D"color: #660;">[</span><span class=3D"style=
d-by-prettify" style=3D"color: #000;">dtime_pm</span><span class=3D"styled-=
by-prettify" style=3D"color: #660;">,</span><span class=3D"styled-by-pretti=
fy" style=3D"color: #000;">ftime_pm</span><span class=3D"styled-by-prettify=
" style=3D"color: #660;">,&</span><span class=3D"styled-by-prettify" st=
yle=3D"color: #000;">t</span><span class=3D"styled-by-prettify" style=3D"co=
lor: #660;">]</span><span class=3D"styled-by-prettify" style=3D"color: #000=
;"> </span><span class=3D"styled-by-prettify" style=3D"color: #008;">struct=
</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> </span><s=
pan class=3D"styled-by-prettify" style=3D"color: #660;">:</span><span class=
=3D"styled-by-prettify" style=3D"color: #000;"> default_dfs_visitor </span>=
<span class=3D"styled-by-prettify" style=3D"color: #660;">{</span><span cla=
ss=3D"styled-by-prettify" style=3D"color: #000;"><br>=C2=A0 =C2=A0 </span><=
span class=3D"styled-by-prettify" style=3D"color: #008;">void</span><span c=
lass=3D"styled-by-prettify" style=3D"color: #000;"> discover_vertex</span><=
span class=3D"styled-by-prettify" style=3D"color: #660;">(</span><span clas=
s=3D"styled-by-prettify" style=3D"color: #008;">auto</span><span class=3D"s=
tyled-by-prettify" style=3D"color: #000;"> u</span><span class=3D"styled-by=
-prettify" style=3D"color: #660;">,</span><span class=3D"styled-by-prettify=
" style=3D"color: #000;"> </span><span class=3D"styled-by-prettify" style=
=3D"color: #008;">const</span><span class=3D"styled-by-prettify" style=3D"c=
olor: #000;"> </span><span class=3D"styled-by-prettify" style=3D"color: #00=
8;">auto</span><span class=3D"styled-by-prettify" style=3D"color: #660;">&a=
mp;</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> g</spa=
n><span class=3D"styled-by-prettify" style=3D"color: #660;">)</span><span c=
lass=3D"styled-by-prettify" style=3D"color: #000;"> </span><span class=3D"s=
tyled-by-prettify" style=3D"color: #008;">const</span><span class=3D"styled=
-by-prettify" style=3D"color: #000;"><br>=C2=A0 =C2=A0 </span><span class=
=3D"styled-by-prettify" style=3D"color: #660;">{</span><span class=3D"style=
d-by-prettify" style=3D"color: #000;"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 put</=
span><span class=3D"styled-by-prettify" style=3D"color: #660;">(</span><spa=
n class=3D"styled-by-prettify" style=3D"color: #000;">dtime_pm</span><span =
class=3D"styled-by-prettify" style=3D"color: #660;">,</span><span class=3D"=
styled-by-prettify" style=3D"color: #000;"> u</span><span class=3D"styled-b=
y-prettify" style=3D"color: #660;">,</span><span class=3D"styled-by-prettif=
y" style=3D"color: #000;"> t</span><span class=3D"styled-by-prettify" style=
=3D"color: #660;">++);</span><span class=3D"styled-by-prettify" style=3D"co=
lor: #000;"><br>=C2=A0 =C2=A0 </span><span class=3D"styled-by-prettify" sty=
le=3D"color: #660;">}</span><span class=3D"styled-by-prettify" style=3D"col=
or: #000;"><br>=C2=A0<br>=C2=A0 =C2=A0 </span><span class=3D"styled-by-pret=
tify" style=3D"color: #008;">void</span><span class=3D"styled-by-prettify" =
style=3D"color: #000;"> finish_vertex</span><span class=3D"styled-by-pretti=
fy" style=3D"color: #660;">(</span><span class=3D"styled-by-prettify" style=
=3D"color: #008;">auto</span><span class=3D"styled-by-prettify" style=3D"co=
lor: #000;"> u</span><span class=3D"styled-by-prettify" style=3D"color: #66=
0;">,</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> </sp=
an><span class=3D"styled-by-prettify" style=3D"color: #008;">const</span><s=
pan class=3D"styled-by-prettify" style=3D"color: #000;"> </span><span class=
=3D"styled-by-prettify" style=3D"color: #008;">auto</span><span class=3D"st=
yled-by-prettify" style=3D"color: #660;">&</span><span class=3D"styled-=
by-prettify" style=3D"color: #000;"> g</span><span class=3D"styled-by-prett=
ify" style=3D"color: #660;">)</span><span class=3D"styled-by-prettify" styl=
e=3D"color: #000;"> </span><span class=3D"styled-by-prettify" style=3D"colo=
r: #008;">const</span><span class=3D"styled-by-prettify" style=3D"color: #0=
00;"><br>=C2=A0 =C2=A0 </span><span class=3D"styled-by-prettify" style=3D"c=
olor: #660;">{</span><span class=3D"styled-by-prettify" style=3D"color: #00=
0;"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 put</span><span class=3D"styled-by-pret=
tify" style=3D"color: #660;">(</span><span class=3D"styled-by-prettify" sty=
le=3D"color: #000;">ftime_pm</span><span class=3D"styled-by-prettify" style=
=3D"color: #660;">,</span><span class=3D"styled-by-prettify" style=3D"color=
: #000;"> u</span><span class=3D"styled-by-prettify" style=3D"color: #660;"=
>,</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> t</span=
><span class=3D"styled-by-prettify" style=3D"color: #660;">++);</span><span=
class=3D"styled-by-prettify" style=3D"color: #000;"><br>=C2=A0 =C2=A0 </sp=
an><span class=3D"styled-by-prettify" style=3D"color: #660;">}</span><span =
class=3D"styled-by-prettify" style=3D"color: #000;"><br></span><span class=
=3D"styled-by-prettify" style=3D"color: #660;">};</span></div></code></div>=
<div><br></div><div>Note that I have regularized the two examples. That is,=
I put the same kind of spacing between function in both, and I used `auto`=
parameters in the first one, since you're presuming you can use them i=
n the second.</div><div><br></div><div>Even so, all you've really done =
is take the struct members and put them<i> outside</i> of the struct. What =
good did that accomplish, exactly?</div><div><br></div><div>I just don'=
t see the advantage here. Especially since you can put the struct definitio=
n inside of the function already.<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">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/5064ca80-a30d-4f50-8058-9874bb53a815%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/5064ca80-a30d-4f50-8058-9874bb53a815=
%40isocpp.org</a>.<br />
------=_Part_12926_916439454.1514127920321--
------=_Part_12925_80054767.1514127920320--
.
Author: mihailnajdenov@gmail.com
Date: Sun, 24 Dec 2017 07:08:07 -0800 (PST)
Raw View
------=_Part_13213_498525488.1514128087888
Content-Type: multipart/alternative;
boundary="----=_Part_13214_803101846.1514128087889"
------=_Part_13214_803101846.1514128087889
Content-Type: text/plain; charset="UTF-8"
Here is the reason why lambda is worse the less:
> ??$?RHH@<lambda_e0791130af6ca6ee892f7f57d6208fb5>@@QBE_NHH@Z
>
You are comparing one lambda vs one use of less<int, int>. The moment you
use two lambdas (which does the same, over the same types), another copy of
the code you posted will be created, where in less<int, int> the
instantiated function will be reused. That is why I said it leads to no
code reuse and bloat - both by definition essentially..
I also use lambdas, I also enjoy Qt5 connect, but they are not free, like
for example inline functions - they create real classes and real code EVERY
TIME with ZERO reuse.
The only saving grace is they have internal linkage and are *considerably*
less heavy then normal classes.
(I am no compiler author and I will gladly stand corrected if I am wrong on
any of the above statements)
Having said that I see no reason not to improve local classes in general.
For instance, they can't be template, but now polymorphic lambda this makes
much less sense:
void f()
{
/*
struct
{
template<class T>
void operator()(T){}
}d1; //< *** does not compile for legacy reasons
*/
auto d2 = [](auto){}; //< happy 14
auto d3 = []<class T>(T) {}; //< happy 20
}
Local template classes alone will also be vastly closer to your original
requirement
template<class... A>
struct
{
std::tuple<A...> context;
S(A... args) : context(std::move(args)...)
{}
auto operator()(int v) { auto [x] = context; x+v; }
auto operator()(float v) { auto [x] = context; x+v; }
auto operator()(const std::string& v) { auto [x] = context; v[x]; }
}my_struct{x};
std::visit(my_struct, a_variant);
And this will also eliminate the need of stand alone class in
the depth_first_search example
But as I said, one should strive to use named, reusable objects - even your
example about kitten_counter is not strong because the lambda has nothing
to do with kittens and can be refactored out as reusable accumulator.
--
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/7828d407-10a1-4a40-8db1-8fb6c19fef50%40isocpp.org.
------=_Part_13214_803101846.1514128087889
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Here is the reason why lambda is worse the less:</div=
><div>=C2=A0</div><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"><div><span style=3D"display: inline !important; float: none; backgroun=
d-color: transparent; color: rgb(34, 34, 34); font-family: courier new,mono=
space; font-size: 13px; font-style: normal; font-variant: normal; font-weig=
ht: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decorat=
ion: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-widt=
h: 0px; white-space: normal; word-spacing: 0px;">??$?RHH@<lambda_</span>=
<wbr style=3D"background-color: transparent; border-bottom-color: rgb(34, 3=
4, 34); border-bottom-style: none; border-bottom-width: 0px; border-image-o=
utset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-im=
age-source: none; border-image-width: 1; border-left-color: rgb(34, 34, 34)=
; border-left-style: none; border-left-width: 0px; border-right-color: rgb(=
34, 34, 34); border-right-style: none; border-right-width: 0px; border-top-=
color: rgb(34, 34, 34); border-top-style: none; border-top-width: 0px; colo=
r: rgb(34, 34, 34); font-family: courier new,monospace; font-size: 13px; fo=
nt-style: normal; font-variant: normal; font-weight: 400; letter-spacing: n=
ormal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top:=
0px; orphans: 2; padding-bottom: 0px; padding-left: 0px; padding-right: 0p=
x; padding-top: 0px; text-align: left; text-decoration: none; text-indent: =
0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: nor=
mal; word-spacing: 0px;"><span style=3D"display: inline !important; float: =
none; background-color: transparent; color: rgb(34, 34, 34); font-family: c=
ourier new,monospace; font-size: 13px; font-style: normal; font-variant: no=
rmal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: lef=
t; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-t=
ext-stroke-width: 0px; white-space: normal; word-spacing: 0px;">e0791130af6=
ca6ee892f7f57d6208f</span><wbr style=3D"background-color: transparent; bord=
er-bottom-color: rgb(34, 34, 34); border-bottom-style: none; border-bottom-=
width: 0px; border-image-outset: 0; border-image-repeat: stretch; border-im=
age-slice: 100%; border-image-source: none; border-image-width: 1; border-l=
eft-color: rgb(34, 34, 34); border-left-style: none; border-left-width: 0px=
; border-right-color: rgb(34, 34, 34); border-right-style: none; border-rig=
ht-width: 0px; border-top-color: rgb(34, 34, 34); border-top-style: none; b=
order-top-width: 0px; color: rgb(34, 34, 34); font-family: courier new,mono=
space; font-size: 13px; font-style: normal; font-variant: normal; font-weig=
ht: 400; letter-spacing: normal; margin-bottom: 0px; margin-left: 0px; marg=
in-right: 0px; margin-top: 0px; orphans: 2; padding-bottom: 0px; padding-le=
ft: 0px; padding-right: 0px; padding-top: 0px; text-align: left; text-decor=
ation: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-wi=
dth: 0px; white-space: normal; word-spacing: 0px;"><span style=3D"display: =
inline !important; float: none; background-color: transparent; color: rgb(3=
4, 34, 34); font-family: courier new,monospace; font-size: 13px; font-style=
: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; o=
rphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-=
transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-=
spacing: 0px;">b5>@@QBE_NHH@Z</span></div></div></blockquote><div>=C2=A0=
</div><div><br></div><div>You are comparing one lambda vs one use of less&l=
t;int, int>. The moment you use two lambdas (which does the same, over t=
he same types), another copy of the code you posted will be created, where =
in less<int, int> the instantiated function will be reused. That is w=
hy I said it leads to no code reuse and bloat - both by definition essentia=
lly..=C2=A0</div><div><br></div><div>I also use lambdas, I also enjoy Qt5 c=
onnect, but they are not free, like for example inline functions - they cre=
ate real classes and real code EVERY TIME with ZERO reuse. =C2=A0</div><div=
>The only saving grace is they have internal linkage and are <i>considerabl=
y</i> less heavy then normal classes.=C2=A0</div><div><br></div><div>(I am =
no compiler author and I will gladly stand corrected if I am wrong on any o=
f the above statements)</div><div><br></div><div><br></div><div><br></div><=
div>Having said that I see no reason not to improve local classes in genera=
l.</div><div><br></div><div>For instance, they can't be template, but n=
ow polymorphic lambda this makes much less sense:</div><div><br></div><div>=
<div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); w=
ord-wrap: break-word; background-color: rgb(250, 250, 250);"><code class=3D=
"prettyprint"><div class=3D"subprettyprint"><span class=3D"styled-by-pretti=
fy" style=3D"color: #008;">voi</span><font color=3D"#004000" face=3D"Arial"=
style=3D"background-color: transparent;"><span class=3D"styled-by-prettify=
" style=3D"color: #008;">d</span><span class=3D"styled-by-prettify" style=
=3D"color: #000;"> f</span><span class=3D"styled-by-prettify" style=3D"colo=
r: #660;">()</span><span class=3D"styled-by-prettify" style=3D"color: #000;=
"><br></span><span class=3D"styled-by-prettify" style=3D"color: #660;">{</s=
pan><span class=3D"styled-by-prettify" style=3D"color: #000;"><br></span><s=
pan class=3D"styled-by-prettify" style=3D"color: #800;">/*<br>=C2=A0 struct=
<br>=C2=A0 {<br>=C2=A0 =C2=A0 template<class T><br>=C2=A0 =C2=A0 voi=
d operator()(T){}<br>=C2=A0 }d1; //< *** </span><span style=3D"display: =
inline !important; float: none; background-color: transparent; color: rgb(1=
36, 0, 0); font-family: Arial; font-size: 13px; font-style: normal; font-va=
riant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-a=
lign: left; text-decoration: none; text-indent: 0px; text-transform: none; =
-webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"><s=
pan class=3D"styled-by-prettify" style=3D"color: #800;">does not compile fo=
r legacy reasons</span></span><span class=3D"styled-by-prettify" style=3D"c=
olor: #800;"><br><br>*/</span><span class=3D"styled-by-prettify" style=3D"c=
olor: #000;"><br>=C2=A0 </span><span class=3D"styled-by-prettify" style=3D"=
color: #008;">auto</span><span class=3D"styled-by-prettify" style=3D"color:=
#000;"> d2 </span><span class=3D"styled-by-prettify" style=3D"color: #660;=
">=3D</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> </sp=
an><span class=3D"styled-by-prettify" style=3D"color: #660;">[](</span><spa=
n class=3D"styled-by-prettify" style=3D"color: #008;">auto</span><span clas=
s=3D"styled-by-prettify" style=3D"color: #660;">){};</span><span class=3D"s=
tyled-by-prettify" style=3D"color: #000;"> </span><span class=3D"styled-by-=
prettify" style=3D"color: #800;">//< happy 14</span><span class=3D"style=
d-by-prettify" style=3D"color: #000;"><br>=C2=A0 </span><span class=3D"styl=
ed-by-prettify" style=3D"color: #008;">auto</span><span class=3D"styled-by-=
prettify" style=3D"color: #000;"> d3 </span><span class=3D"styled-by-pretti=
fy" style=3D"color: #660;">=3D</span><span class=3D"styled-by-prettify" sty=
le=3D"color: #000;"> </span><span class=3D"styled-by-prettify" style=3D"col=
or: #660;">[]<</span><span class=3D"styled-by-prettify" style=3D"color: =
#008;">class</span><span class=3D"styled-by-prettify" style=3D"color: #000;=
"> T</span><span class=3D"styled-by-prettify" style=3D"color: #660;">>(<=
/span><span class=3D"styled-by-prettify" style=3D"color: #000;">T</span><sp=
an class=3D"styled-by-prettify" style=3D"color: #660;">)</span><span class=
=3D"styled-by-prettify" style=3D"color: #000;"> </span><span class=3D"style=
d-by-prettify" style=3D"color: #660;">{};</span><span class=3D"styled-by-pr=
ettify" style=3D"color: #000;"> </span><span class=3D"styled-by-prettify" s=
tyle=3D"color: #800;">//< happy 20</span><span class=3D"styled-by-pretti=
fy" style=3D"color: #000;"><br></span><span class=3D"styled-by-prettify" st=
yle=3D"color: #660;">}</span><span class=3D"styled-by-prettify" style=3D"co=
lor: #000;"><br></span></font></div></code></div><br></div><div><br></div><=
div>Local template classes alone will also be vastly closer to your origina=
l requirement</div><div><font color=3D"#b06400" style=3D"background-color: =
rgb(250, 250, 250);"><br></font></div><div><font color=3D"#006000" style=3D=
"background-color: rgb(250, 250, 250);"><div class=3D"prettyprint" style=3D=
"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; background-co=
lor: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"subpret=
typrint"><font color=3D"#006000" face=3D"Arial">=C2=A0 template<class...=
A><br>=C2=A0 struct <br>=C2=A0 {<br>=C2=A0=C2=A0=C2=A0 std::tuple<A.=
...> context;<br><br></font></div><div class=3D"subprettyprint"><font col=
or=3D"#006000" face=3D"Arial">=C2=A0=C2=A0=C2=A0 S(A... args) : context(std=
::move(args)...)<br>=C2=A0=C2=A0=C2=A0 {}<br><br></font></div><div class=3D=
"subprettyprint"><font color=3D"#006000" face=3D"Arial">=C2=A0=C2=A0=C2=A0 =
auto operator()(int v) { auto [x] =3D context; x+v; }<br>=C2=A0=C2=A0=C2=A0=
auto operator()(float v) { auto [x] =3D context; x+v; }<br>=C2=A0=C2=A0=C2=
=A0 auto operator()(const std::string& v) { auto [x] =3D context; v[x];=
}<br>=C2=A0 }my_struct{x};<br><br></font></div><div class=3D"subprettyprin=
t"><font color=3D"#006000" face=3D"Arial">=C2=A0 std::visit(my_struct, a_va=
riant);</font></div></code></div><br></font></div><div>And this will also e=
liminate the need of stand alone class in the=C2=A0depth_first_search examp=
le</div><div><br></div><div><br></div><div>But as I said, one should strive=
to use named, reusable objects - even your example about <span style=3D"di=
splay: inline !important; float: none; background-color: transparent; color=
: rgb(34, 34, 34); font-family: "Arial","Helvetica",san=
s-serif; font-size: 13px; font-style: normal; font-variant: normal; font-we=
ight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decor=
ation: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-wi=
dth: 0px; white-space: normal; word-spacing: 0px;">kitten_counter is not st=
rong because the lambda has nothing to do with <span style=3D"display: inli=
ne !important; float: none; background-color: transparent; color: rgb(34, 3=
4, 34); font-family: "Arial","Helvetica",sans-serif; fo=
nt-size: 13px; font-style: normal; font-variant: normal; font-weight: 400; =
letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none=
; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; w=
hite-space: normal; word-spacing: 0px;">kittens and can be refactored out a=
s reusable accumulator</span></span>.=C2=A0</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">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/7828d407-10a1-4a40-8db1-8fb6c19fef50%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/7828d407-10a1-4a40-8db1-8fb6c19fef50=
%40isocpp.org</a>.<br />
------=_Part_13214_803101846.1514128087889--
------=_Part_13213_498525488.1514128087888--
.
Author: doom.ooseventh@gmail.com
Date: Sun, 24 Dec 2017 07:27:00 -0800 (PST)
Raw View
------=_Part_13303_411749064.1514129220692
Content-Type: multipart/alternative;
boundary="----=_Part_13304_1875730955.1514129220694"
------=_Part_13304_1875730955.1514129220694
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
> Even so, all you've really done is take the struct members and put them*=
=20
outside* of the struct. What good did that accomplish, exactly?
No, notice that in the existing Boost example, the members were *already*=
=20
outside of the struct because they are also being used by further code in=
=20
the main. Two are being copied in the struct and one is referenced:=20
time_pm_type dtime_pm(dtime.begin(), get(vertex_index, g));=20
time_pm_type ftime_pm(ftime.begin(), get(vertex_index, g));=20
size_type t =3D 0;=20
dfs_time_visitor < time_pm_type >vis(dtime_pm, ftime_pm, t);=20
depth_first_search(g, visitor(vis));
> Especially since you can put the struct definition inside of the function=
=20
already.
Yes, but you have to write a constructor and have the members inside (and=
=20
also, today, templates don't work).
The best we could do today would be =20
time_pm_type dtime_pm(dtime.begin(), get(vertex_index, g));
time_pm_type ftime_pm(ftime.begin(), get(vertex_index, g));
size_type t =3D 0;
struct dfs_time_visitor: public default_dfs_visitor {
=20
typedef typename property_traits < time_pm_type >::value_type T;
=20
dfs_time_visitor(time_pm_type dmap, time_pm_type fmap, T & t)
: m_dtimemap(dmap), m_ftimemap(fmap), m_time(t) { }
void discover_vertex(std::size_t u, const graph_t & g) const
{ put(m_dtimemap, u, m_time++); }
void finish_vertex(std::size_t u, const graph_t & g) const
{ put(m_ftimemap, u, m_time++); }
=20
time_pm_type m_dtimemap;
time_pm_type m_ftimemap;
std::size_t& m_time;
} vis{dtime_pm, ftime_pm, t};
=20
depth_first_search(g, visitor(vis));
Notice how a constructor is sadly necessary in this case, and the space=20
taken by the arguments.
Le dimanche 24 d=C3=A9cembre 2017 16:05:20 UTC+1, Nicol Bolas a =C3=A9crit =
:
>
>
>
> On Sunday, December 24, 2017 at 7:12:31 AM UTC-5, jeanmichae...@gmail.com=
=20
> wrote:
>>
>> Here's a practical example of code that could be much simplified:=20
>> boost.graph's visitors.
>>
>> For instance, depth-first search requires you to pass a structure with a=
=20
>> bunch of operations (see "visitor event points") though most of them are=
=20
>> optional:=20
>>
>> http://www.boost.org/doc/libs/1_61_0/libs/graph/doc/depth_first_search.h=
tml=20
>>
>> Here's a code example:=20
>> http://www.boost.org/doc/libs/1_61_0/libs/graph/example/dfs-example.cpp
>>
>> With this proposal (and assuming that other lambda-niceties propagate to=
=20
>> it, such as auto parameters), it would become:=20
>>
>> https://paste.ofcode.org/DysGbFTUjyg8Rg3yi8xi8K
>>
>> which is, I think, much less intimidating for the one wanting to delve=
=20
>> into boost.graph.
>>
>
> So you've taken this:
>
> template < typename TimeMap > class dfs_time_visitor:public=20
> default_dfs_visitor {
> typedef typename property_traits < TimeMap >::value_type T;
> public:
> dfs_time_visitor(TimeMap dmap, TimeMap fmap, T & t)
> : m_dtimemap(dmap), m_ftimemap(fmap), m_time(t) {
> }
>
> void discover_vertex(auto u, const auto & g) const
> {
> put(m_dtimemap, u, m_time++);
> }
>
> void finish_vertex(auto u, const auto & g) const
> {
> put(m_ftimemap, u, m_time++);
> }
> =20
> TimeMap m_dtimemap;
> TimeMap m_ftimemap;
> T & m_time;
> };
>
> And turned it into this:
>
> typedef
> iterator_property_map<std::vector<size_type>::iterator,
> property_map<graph_t, vertex_index_t>::const_type>
> time_pm_type;
> time_pm_type dtime_pm(dtime.begin(), get(vertex_index, g));
> time_pm_type ftime_pm(ftime.begin(), get(vertex_index, g));
> size_type t =3D 0;
>
> auto vis =3D [dtime_pm,ftime_pm,&t] struct : default_dfs_visitor {
> void discover_vertex(auto u, const auto& g) const
> {
> put(dtime_pm, u, t++);
> }
> =20
> void finish_vertex(auto u, const auto& g) const
> {
> put(ftime_pm, u, t++);
> }
> };
>
> Note that I have regularized the two examples. That is, I put the same=20
> kind of spacing between function in both, and I used `auto` parameters in=
=20
> the first one, since you're presuming you can use them in the second.
>
> Even so, all you've really done is take the struct members and put them*=
=20
> outside* of the struct. What good did that accomplish, exactly?
>
> I just don't see the advantage here. Especially since you can put the=20
> struct definition inside of the function already.
>
--=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/53fb741e-b149-4604-b0df-b151f40cbd3d%40isocpp.or=
g.
------=_Part_13304_1875730955.1514129220694
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">> Even so, all you've really done is take the struc=
t members and put them<i> outside</i> of the struct. What good did that acc=
omplish, exactly?<br><br>No, notice that in the existing Boost example, the=
members were *already* outside of the struct because they are also being u=
sed by further code in the main. Two are being copied in the struct and one=
is referenced: <br><div style=3D"background-color: rgb(250, 250, 250); bor=
der-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; over=
flow-wrap: break-word;" class=3D"prettyprint"><code class=3D"prettyprint"><=
div class=3D"subprettyprint"><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">time_pm_type dtime_pm</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">dtime</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">.</span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>begin</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(),<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">get</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">vertex_index</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> g</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">));</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> <br>time_pm_type ftime_pm</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">ftime</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">.</span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">begin</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">(),</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #008;" class=3D"styled-by-prettify">get</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">vertex_index</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> g</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">));</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> <br>size_type t </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"sty=
led-by-prettify">0</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
<br><br>dfs_time_visitor </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify"><</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> time_pm_type </span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">></span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">vis</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">dtime_pm<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> ftime_pm</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> t</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> <br>depth_first_search</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify">g</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> visitor</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">vis</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)=
);</span></div></code></div><br><br>> Especially since you can put the s=
truct definition inside of the function already.<br><br>Yes, but you have t=
o write a constructor and have the members inside (and also, today, templat=
es don't work).<br>The best we could do today would be =C2=A0
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"></span><div style=
=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187);=
border-style: solid; border-width: 1px; overflow-wrap: break-word;" class=
=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"subprettyprint">=
<span style=3D"color: #000;" class=3D"styled-by-prettify">=C2=A0time_pm_typ=
e dtime_pm</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">dtime</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">begin</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(),</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">get</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">vertex_index</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> g</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
));</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=
=A0time_pm_type ftime_pm</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">ftime</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
..</span><span style=3D"color: #008;" class=3D"styled-by-prettify">begin</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">(),</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">get</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify">vertex_index</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> g</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">));</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br>=C2=A0size_type t </span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-prett=
ify">0</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>=C2=
=A0</span><span style=3D"color: #008;" class=3D"styled-by-prettify">struct<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> dfs_time_v=
isitor</span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
style=3D"color: #008;" class=3D"styled-by-prettify">public</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> default_dfs_visitor </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0<br>=C2=A0 </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">typedef</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">typename</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> property_traits </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> time_pm_type </span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">>::</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">value_type T</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br>=C2=A0 <br>=C2=A0 dfs_time_vi=
sitor</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">time_pm_type d=
map</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> time_pm_type fm=
ap</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> T </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">&</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> t</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0</span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> m_dtimemap</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify">dmap</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">),</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> m_ftimemap</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">fm=
ap</span><span style=3D"color: #660;" class=3D"styled-by-prettify">),</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> m_time</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">t</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">void</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> discover_vertex</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">std</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">size_t u</span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">const</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> graph_t </span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">&</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> g</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">const</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> put</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">m_dtimemap</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> u</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> m_time</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
++);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">void</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> finish_vertex</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">std</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">size_t u</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">const</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> graph_t </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>&</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> g</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">const</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> put</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">m_ftimemap</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> u</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> m_time=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">++);</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br>=C2=A0<br>=C2=A0 time_pm_type =
m_dtimemap</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=
=A0 time_pm_type m_ftimemap</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br>=C2=A0 std</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">size_t</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
&</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> m_ti=
me</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> vis</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">dtime_pm</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> ftime_pm</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> t</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br>=C2=A0<br><br>=C2=A0depth_first_search</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">g</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> visitor</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">vis</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">));</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span></di=
v></code></div><br>Notice how a constructor is sadly necessary in this case=
, and the space taken by the arguments.<br><br>Le dimanche 24 d=C3=A9cembre=
2017 16:05:20 UTC+1, Nicol Bolas a =C3=A9crit=C2=A0:<blockquote class=3D"g=
mail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc sol=
id;padding-left: 1ex;"><div dir=3D"ltr"><br><br>On Sunday, December 24, 201=
7 at 7:12:31 AM UTC-5, <a>jeanmichae...@gmail.com</a> 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">Here's a practical example of=
code that could be much simplified: boost.graph's visitors.<br><br>For=
instance, depth-first search requires you to pass a structure with a bunch=
of operations (see "visitor event points") though most of them a=
re optional: <br><a href=3D"http://www.boost.org/doc/libs/1_61_0/libs/graph=
/doc/depth_first_search.html" rel=3D"nofollow" target=3D"_blank" onmousedow=
n=3D"this.href=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.boost=
..org%2Fdoc%2Flibs%2F1_61_0%2Flibs%2Fgraph%2Fdoc%2Fdepth_first_search.html\x=
26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGdvtHhhyObZKI9cvJnc_H-O8WmJQ';re=
turn true;" onclick=3D"this.href=3D'http://www.google.com/url?q\x3dhttp=
%3A%2F%2Fwww.boost.org%2Fdoc%2Flibs%2F1_61_0%2Flibs%2Fgraph%2Fdoc%2Fdepth_f=
irst_search.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGdvtHhhyObZKI9cvJn=
c_H-O8WmJQ';return true;">http://www.boost.org/doc/libs/<wbr>1_61_0/lib=
s/graph/doc/depth_<wbr>first_search.html</a> <br><br>Here's a code exam=
ple: <br><a href=3D"http://www.boost.org/doc/libs/1_61_0/libs/graph/example=
/dfs-example.cpp" rel=3D"nofollow" target=3D"_blank" onmousedown=3D"this.hr=
ef=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.boost.org%2Fdoc%2=
Flibs%2F1_61_0%2Flibs%2Fgraph%2Fexample%2Fdfs-example.cpp\x26sa\x3dD\x26snt=
z\x3d1\x26usg\x3dAFQjCNGLQtNSEHNYbANg7JjIlVYlSLFGSg';return true;" oncl=
ick=3D"this.href=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.boo=
st.org%2Fdoc%2Flibs%2F1_61_0%2Flibs%2Fgraph%2Fexample%2Fdfs-example.cpp\x26=
sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGLQtNSEHNYbANg7JjIlVYlSLFGSg';retu=
rn true;">http://www.boost.org/doc/libs/<wbr>1_61_0/libs/graph/example/dfs-=
<wbr>example.cpp</a><br><br>With this proposal (and assuming that other lam=
bda-niceties propagate to it, such as auto parameters), it would become: <b=
r><br><a href=3D"https://paste.ofcode.org/DysGbFTUjyg8Rg3yi8xi8K" rel=3D"no=
follow" target=3D"_blank" onmousedown=3D"this.href=3D'https://www.googl=
e.com/url?q\x3dhttps%3A%2F%2Fpaste.ofcode.org%2FDysGbFTUjyg8Rg3yi8xi8K\x26s=
a\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGks2ws6kHBc94sP-unZf5dvXb3xQ';retur=
n true;" onclick=3D"this.href=3D'https://www.google.com/url?q\x3dhttps%=
3A%2F%2Fpaste.ofcode.org%2FDysGbFTUjyg8Rg3yi8xi8K\x26sa\x3dD\x26sntz\x3d1\x=
26usg\x3dAFQjCNGks2ws6kHBc94sP-unZf5dvXb3xQ';return true;">https://past=
e.ofcode.org/<wbr>DysGbFTUjyg8Rg3yi8xi8K</a><br><br>which is, I think, much=
less intimidating for the one wanting to delve into boost.graph.<br></div>=
</blockquote><div><br></div><div>So you've taken this:</div><div><br></=
div><div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;ba=
ckground-color:rgb(250,250,250)"><code><div><span style=3D"color:#008">temp=
late</span><span style=3D"color:#000"> </span><span style=3D"color:#660">&l=
t;</span><span style=3D"color:#000"> </span><span style=3D"color:#008">type=
name</span><span style=3D"color:#000"> </span><span style=3D"color:#606">Ti=
meMap</span><span style=3D"color:#000"> </span><span style=3D"color:#660">&=
gt;</span><span style=3D"color:#000"> </span><span style=3D"color:#008">cla=
ss</span><span style=3D"color:#000"> dfs_time_visitor</span><span style=3D"=
color:#660">:</span><span style=3D"color:#008">public</span><span style=3D"=
color:#000"> default_dfs_visitor </span><span style=3D"color:#660">{</span>=
<span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#0=
08">typedef</span><span style=3D"color:#000"> </span><span style=3D"color:#=
008">typename</span><span style=3D"color:#000"> property_traits </span><spa=
n style=3D"color:#660"><</span><span style=3D"color:#000"> </span><span =
style=3D"color:#606">TimeMap</span><span style=3D"color:#000"> </span><span=
style=3D"color:#660">>::</span><span style=3D"color:#000">value_type T<=
/span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br></s=
pan><span style=3D"color:#008">public</span><span style=3D"color:#660">:</s=
pan><span style=3D"color:#000"><br>=C2=A0 =C2=A0 dfs_time_visitor</span><sp=
an style=3D"color:#660">(</span><span style=3D"color:#606">TimeMap</span><s=
pan style=3D"color:#000"> dmap</span><span style=3D"color:#660">,</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#606">TimeMap</span><s=
pan style=3D"color:#000"> fmap</span><span style=3D"color:#660">,</span><sp=
an style=3D"color:#000"> T </span><span style=3D"color:#660">&</span><s=
pan style=3D"color:#000"> t</span><span style=3D"color:#660">)</span><span =
style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"=
color:#660">:</span><span style=3D"color:#000"> =C2=A0m_dtimemap</span><spa=
n style=3D"color:#660">(</span><span style=3D"color:#000">dmap</span><span =
style=3D"color:#660">),</span><span style=3D"color:#000"> m_ftimemap</span>=
<span style=3D"color:#660">(</span><span style=3D"color:#000">fmap</span><s=
pan style=3D"color:#660">),</span><span style=3D"color:#000"> m_time</span>=
<span style=3D"color:#660">(</span><span style=3D"color:#000">t</span><span=
style=3D"color:#660">)</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </spa=
n><span style=3D"color:#660">}</span><span style=3D"color:#000"><br><br>=C2=
=A0 =C2=A0 </span><span style=3D"color:#008">void</span><span style=3D"colo=
r:#000"> discover_vertex</span><span style=3D"color:#660">(</span><span sty=
le=3D"color:#008">auto</span><span style=3D"color:#000"> u</span><span styl=
e=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"=
color:#008">const</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#008">auto</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#660">&</span><span style=3D"color:#000"> g</span><span style=3D"col=
or:#660">)</span><span style=3D"color:#000"> </span><span style=3D"color:#0=
08">const</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span s=
tyle=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 put</span><span style=3D"color:#660">(</span><span style=3D"c=
olor:#000">m_dtimemap</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> u</span><span style=3D"color:#660">,</span><span style=3D"=
color:#000"> m_time</span><span style=3D"color:#660">++);</span><span style=
=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span=
><span style=3D"color:#000"><br><br>=C2=A0 =C2=A0 </span><span style=3D"col=
or:#008">void</span><span style=3D"color:#000"> finish_vertex</span><span s=
tyle=3D"color:#660">(</span><span style=3D"color:#008">auto</span><span sty=
le=3D"color:#000"> u</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">const</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">auto</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">&</span><span style=
=3D"color:#000"> g</span><span style=3D"color:#660">)</span><span style=3D"=
color:#000"> </span><span style=3D"color:#008">const</span><span style=3D"c=
olor:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">{</span><spa=
n style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 put</span><span styl=
e=3D"color:#660">(</span><span style=3D"color:#000">m_ftimemap</span><span =
style=3D"color:#660">,</span><span style=3D"color:#000"> u</span><span styl=
e=3D"color:#660">,</span><span style=3D"color:#000"> m_time</span><span sty=
le=3D"color:#660">++);</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 <=
/span><span style=3D"color:#660">}</span><span style=3D"color:#000"><br>=C2=
=A0<br>=C2=A0 =C2=A0 </span><span style=3D"color:#606">TimeMap</span><span =
style=3D"color:#000"> m_dtimemap</span><span style=3D"color:#660">;</span><=
span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#60=
6">TimeMap</span><span style=3D"color:#000"> m_ftimemap</span><span style=
=3D"color:#660">;</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 T </sp=
an><span style=3D"color:#660">&</span><span style=3D"color:#000"> m_tim=
e</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br><=
/span><span style=3D"color:#660">};</span></div></code></div><div><br></div=
><div>And turned it into this:</div><div><br></div><div style=3D"border:1px=
solid rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,250,2=
50)"><code><div><span style=3D"color:#008">typedef</span><span style=3D"col=
or:#000"><br>iterator_property_map</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#000">std</span><span style=3D"color:#660">::</spa=
n><span style=3D"color:#000">vec<wbr>tor</span><span style=3D"color:#080">&=
lt;size_type></span><span style=3D"color:#660">::</span><span style=3D"c=
olor:#000">iterator</span><span style=3D"color:#660">,</span><span style=3D=
"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 property_map</span><span style=
=3D"color:#660"><</span><span style=3D"color:#000">graph_t</span><span s=
tyle=3D"color:#660">,</span><span style=3D"color:#000"> vertex_index_t</spa=
n><span style=3D"color:#660">>::</span><span style=3D"color:#000">const_=
type</span><span style=3D"color:#660">></span><span style=3D"color:#000"=
><br>time_pm_type</span><span style=3D"color:#660">;</span><span style=3D"c=
olor:#000"><br>time_pm_type dtime_pm</span><span style=3D"color:#660">(</sp=
an><span style=3D"color:#000">dtime</span><span style=3D"color:#660">.</spa=
n><span style=3D"color:#008">begin</span><span style=3D"color:#660">(),</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#008">get</span>=
<span style=3D"color:#660">(</span><span style=3D"color:#000">vertex_index<=
/span><span style=3D"color:#660">,</span><span style=3D"color:#000"> g</spa=
n><span style=3D"color:#660">));</span><span style=3D"color:#000"><br>time_=
pm_type ftime_pm</span><span style=3D"color:#660">(</span><span style=3D"co=
lor:#000">ftime</span><span style=3D"color:#660">.</span><span style=3D"col=
or:#008">begin</span><span style=3D"color:#660">(),</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#008">get</span><span style=3D"color=
:#660">(</span><span style=3D"color:#000">vertex_index</span><span style=3D=
"color:#660">,</span><span style=3D"color:#000"> g</span><span style=3D"col=
or:#660">));</span><span style=3D"color:#000"><br>size_type t </span><span =
style=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#066">0</span><span style=3D"color:#660">;</span><span style=3D=
"color:#000"><br><br></span><span style=3D"color:#008">auto</span><span sty=
le=3D"color:#000"> vis </span><span style=3D"color:#660">=3D</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#660">[</span><span style=
=3D"color:#000">dtime_pm</span><span style=3D"color:#660">,</span><span sty=
le=3D"color:#000">ftime_pm</span><span style=3D"color:#660">,&</span><s=
pan style=3D"color:#000">t</span><span style=3D"color:#660">]</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#008">struct</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#660">:</span><span style=
=3D"color:#000"> default_dfs_visitor </span><span style=3D"color:#660">{</s=
pan><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"colo=
r:#008">void</span><span style=3D"color:#000"> discover_vertex</span><span =
style=3D"color:#660">(</span><span style=3D"color:#008">auto</span><span st=
yle=3D"color:#000"> u</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">const</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">auto</span><span style=
=3D"color:#660">&</span><span style=3D"color:#000"> g</span><span style=
=3D"color:#660">)</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#008">const</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span>=
<span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 put</span><span style=3D"color:#660">(</span><span sty=
le=3D"color:#000">dtime_pm</span><span style=3D"color:#660">,</span><span s=
tyle=3D"color:#000"> u</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> t</span><span style=3D"color:#660">++);</span><span style=
=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span=
><span style=3D"color:#000"><br>=C2=A0<br>=C2=A0 =C2=A0 </span><span style=
=3D"color:#008">void</span><span style=3D"color:#000"> finish_vertex</span>=
<span style=3D"color:#660">(</span><span style=3D"color:#008">auto</span><s=
pan style=3D"color:#000"> u</span><span style=3D"color:#660">,</span><span =
style=3D"color:#000"> </span><span style=3D"color:#008">const</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#008">auto</span><span sty=
le=3D"color:#660">&</span><span style=3D"color:#000"> g</span><span sty=
le=3D"color:#660">)</span><span style=3D"color:#000"> </span><span style=3D=
"color:#008">const</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </spa=
n><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 put</span><span style=3D"color:#660">(</span><span sty=
le=3D"color:#000">ftime_pm</span><span style=3D"color:#660">,</span><span s=
tyle=3D"color:#000"> u</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> t</span><span style=3D"color:#660">++);</span><span style=
=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span=
><span style=3D"color:#000"><br></span><span style=3D"color:#660">};</span>=
</div></code></div><div><br></div><div>Note that I have regularized the two=
examples. That is, I put the same kind of spacing between function in both=
, and I used `auto` parameters in the first one, since you're presuming=
you can use them in the second.</div><div><br></div><div>Even so, all you&=
#39;ve really done is take the struct members and put them<i> outside</i> o=
f the struct. What good did that accomplish, exactly?</div><div><br></div><=
div>I just don't see the advantage here. Especially since you can put t=
he struct definition inside of the function already.<br></div></div></block=
quote></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/53fb741e-b149-4604-b0df-b151f40cbd3d%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/53fb741e-b149-4604-b0df-b151f40cbd3d=
%40isocpp.org</a>.<br />
------=_Part_13304_1875730955.1514129220694--
------=_Part_13303_411749064.1514129220692--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sun, 24 Dec 2017 07:37:32 -0800 (PST)
Raw View
------=_Part_13460_1972004378.1514129852713
Content-Type: multipart/alternative;
boundary="----=_Part_13461_1126673443.1514129852714"
------=_Part_13461_1126673443.1514129852714
Content-Type: text/plain; charset="UTF-8"
On Sunday, December 24, 2017 at 10:27:00 AM UTC-5, doom.oo...@gmail.com
wrote:
>
> > Even so, all you've really done is take the struct members and put them*
> outside* of the struct. What good did that accomplish, exactly?
>
> No, notice that in the existing Boost example, the members were *already*
> outside of the struct because they are also being used by further code in
> the main. Two are being copied in the struct and one is referenced:
> time_pm_type dtime_pm(dtime.begin(), get(vertex_index, g));
> time_pm_type ftime_pm(ftime.begin(), get(vertex_index, g));
> size_type t = 0;
>
> dfs_time_visitor < time_pm_type >vis(dtime_pm, ftime_pm, t);
> depth_first_search(g, visitor(vis));
>
>
> > Especially since you can put the struct definition inside of the
> function already.
>
> Yes, but you have to write a constructor and have the members inside (and
> also, today, templates don't work).
> The best we could do today would be
>
No, we can do much better today:
struct dfs_time_visitor: public default_dfs_visitor {
typedef typename property_traits < time_pm_type >::value_type T;
void discover_vertex(std::size_t u, const graph_t & g) const
{ put(m_dtimemap, u, m_time++); }
void finish_vertex(std::size_t u, const graph_t & g) const
{ put(m_ftimemap, u, m_time++); }
time_pm_type m_dtimemap;
time_pm_type m_ftimemap;
std::size_t& m_time;
};
dfs_time_visitor vis{{}, {dtime.begin(), get(vertex_index, g)},
{ftime.begin(), get(vertex_index, g)},
0};
depth_first_search(g, visitor(vis));
auto &[dtime_pm, ftime_pm, t] = vis;
There is no constructor; it uses aggregate initialization to get filled in
(C++17 lets classes with base classes be aggregates). Note how we don't
have to repeat the variable declarations; we just use structured binding to
gain access to the members.
Should we get template in-function classes? Sure; if lambdas can do it, why
not real struct definitions? But we don't need member capturing. Structured
binding allows us to reverse the process; declaring members in the class
and then referencing them with new names out of it.
--
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/ba6835ff-8f92-4380-ad85-2f8b87b2665f%40isocpp.org.
------=_Part_13461_1126673443.1514129852714
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Sunday, December 24, 2017 at 10:27:00 AM UTC-5,=
doom.oo...@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"marg=
in: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><d=
iv dir=3D"ltr">> Even so, all you've really done is take the struct =
members and put them<i> outside</i> of the struct. What good did that accom=
plish, exactly?<br><br>No, notice that in the existing Boost example, the m=
embers were *already* outside of the struct because they are also being use=
d by further code in the main. Two are being copied in the struct and one i=
s referenced: <br><div style=3D"background-color:rgb(250,250,250);border-co=
lor:rgb(187,187,187);border-style:solid;border-width:1px"><code><div><span =
style=3D"color:#000">time_pm_type dtime_pm</span><span style=3D"color:#660"=
>(</span><span style=3D"color:#000">dtime</span><span style=3D"color:#660">=
..</span><span style=3D"color:#008">begin</span><span style=3D"color:#660">(=
),</span><span style=3D"color:#000"> </span><span style=3D"color:#008">get<=
/span><span style=3D"color:#660">(</span><span style=3D"color:#000">vertex_=
index</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> =
g</span><span style=3D"color:#660">));</span><span style=3D"color:#000"> <b=
r>time_pm_type ftime_pm</span><span style=3D"color:#660">(</span><span styl=
e=3D"color:#000">ftime</span><span style=3D"color:#660">.</span><span style=
=3D"color:#008">begin</span><span style=3D"color:#660">(),</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#008">get</span><span style=
=3D"color:#660">(</span><span style=3D"color:#000">vertex_index</span><span=
style=3D"color:#660">,</span><span style=3D"color:#000"> g</span><span sty=
le=3D"color:#660">));</span><span style=3D"color:#000"> <br>size_type t </s=
pan><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </span=
><span style=3D"color:#066">0</span><span style=3D"color:#660">;</span><spa=
n style=3D"color:#000"> <br><br>dfs_time_visitor </span><span style=3D"colo=
r:#660"><</span><span style=3D"color:#000"> time_pm_type </span><span st=
yle=3D"color:#660">></span><span style=3D"color:#000">vis</span><span st=
yle=3D"color:#660">(</span><span style=3D"color:#000">dtime_pm</span><span =
style=3D"color:#660">,</span><span style=3D"color:#000"> ftime_pm</span><sp=
an style=3D"color:#660">,</span><span style=3D"color:#000"> t</span><span s=
tyle=3D"color:#660">);</span><span style=3D"color:#000"> <br>depth_first_se=
arch</span><span style=3D"color:#660">(</span><span style=3D"color:#000">g<=
/span><span style=3D"color:#660">,</span><span style=3D"color:#000"> visito=
r</span><span style=3D"color:#660">(</span><span style=3D"color:#000">vis</=
span><span style=3D"color:#660">));</span></div></code></div><br><br>> E=
specially since you can put the struct definition inside of the function al=
ready.<br><br>Yes, but you have to write a constructor and have the members=
inside (and also, today, templates don't work).<br>The best we could d=
o today would be</div></blockquote><div><br></div><div>No, we can do much b=
etter today:</div><div><br></div><div class=3D"prettyprint" style=3D"border=
: 1px solid rgb(187, 187, 187); word-wrap: break-word; background-color: rg=
b(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"subprettyprint=
"><span class=3D"styled-by-prettify" style=3D"color: #008;">struct</span><s=
pan class=3D"styled-by-prettify" style=3D"color: #000;"> dfs_time_visitor</=
span><span class=3D"styled-by-prettify" style=3D"color: #660;">:</span><spa=
n class=3D"styled-by-prettify" style=3D"color: #000;"> </span><span class=
=3D"styled-by-prettify" style=3D"color: #008;">public</span><span class=3D"=
styled-by-prettify" style=3D"color: #000;"> default_dfs_visitor </span><spa=
n class=3D"styled-by-prettify" style=3D"color: #660;">{</span><span class=
=3D"styled-by-prettify" style=3D"color: #000;"><br>=C2=A0</span><span class=
=3D"styled-by-prettify" style=3D"color: #008;">typedef</span><span class=3D=
"styled-by-prettify" style=3D"color: #000;"> </span><span class=3D"styled-b=
y-prettify" style=3D"color: #008;">typename</span><span class=3D"styled-by-=
prettify" style=3D"color: #000;"> property_traits </span><span class=3D"sty=
led-by-prettify" style=3D"color: #660;"><</span><span class=3D"styled-by=
-prettify" style=3D"color: #000;"> time_pm_type </span><span class=3D"style=
d-by-prettify" style=3D"color: #660;">>::</span><span class=3D"styled-by=
-prettify" style=3D"color: #000;">value_type T</span><span class=3D"styled-=
by-prettify" style=3D"color: #660;">;</span><span class=3D"styled-by-pretti=
fy" style=3D"color: #000;"><br><br>=C2=A0</span><span class=3D"styled-by-pr=
ettify" style=3D"color: #008;">void</span><span class=3D"styled-by-prettify=
" style=3D"color: #000;"> discover_vertex</span><span class=3D"styled-by-pr=
ettify" style=3D"color: #660;">(</span><span class=3D"styled-by-prettify" s=
tyle=3D"color: #000;">std</span><span class=3D"styled-by-prettify" style=3D=
"color: #660;">::</span><span class=3D"styled-by-prettify" style=3D"color: =
#000;">size_t u</span><span class=3D"styled-by-prettify" style=3D"color: #6=
60;">,</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> </s=
pan><span class=3D"styled-by-prettify" style=3D"color: #008;">const</span><=
span class=3D"styled-by-prettify" style=3D"color: #000;"> graph_t </span><s=
pan class=3D"styled-by-prettify" style=3D"color: #660;">&</span><span c=
lass=3D"styled-by-prettify" style=3D"color: #000;"> g</span><span class=3D"=
styled-by-prettify" style=3D"color: #660;">)</span><span class=3D"styled-by=
-prettify" style=3D"color: #000;"> </span><span class=3D"styled-by-prettify=
" style=3D"color: #008;">const</span><span class=3D"styled-by-prettify" sty=
le=3D"color: #000;"><br>=C2=A0</span><span class=3D"styled-by-prettify" sty=
le=3D"color: #660;">{</span><span class=3D"styled-by-prettify" style=3D"col=
or: #000;"> put</span><span class=3D"styled-by-prettify" style=3D"color: #6=
60;">(</span><span class=3D"styled-by-prettify" style=3D"color: #000;">m_dt=
imemap</span><span class=3D"styled-by-prettify" style=3D"color: #660;">,</s=
pan><span class=3D"styled-by-prettify" style=3D"color: #000;"> u</span><spa=
n class=3D"styled-by-prettify" style=3D"color: #660;">,</span><span class=
=3D"styled-by-prettify" style=3D"color: #000;"> m_time</span><span class=3D=
"styled-by-prettify" style=3D"color: #660;">++);</span><span class=3D"style=
d-by-prettify" style=3D"color: #000;"> </span><span class=3D"styled-by-pret=
tify" style=3D"color: #660;">}</span><span class=3D"styled-by-prettify" sty=
le=3D"color: #000;"><br>=C2=A0<br>=C2=A0</span><span class=3D"styled-by-pre=
ttify" style=3D"color: #008;">void</span><span class=3D"styled-by-prettify"=
style=3D"color: #000;"> finish_vertex</span><span class=3D"styled-by-prett=
ify" style=3D"color: #660;">(</span><span class=3D"styled-by-prettify" styl=
e=3D"color: #000;">std</span><span class=3D"styled-by-prettify" style=3D"co=
lor: #660;">::</span><span class=3D"styled-by-prettify" style=3D"color: #00=
0;">size_t u</span><span class=3D"styled-by-prettify" style=3D"color: #660;=
">,</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> </span=
><span class=3D"styled-by-prettify" style=3D"color: #008;">const</span><spa=
n class=3D"styled-by-prettify" style=3D"color: #000;"> graph_t </span><span=
class=3D"styled-by-prettify" style=3D"color: #660;">&</span><span clas=
s=3D"styled-by-prettify" style=3D"color: #000;"> g</span><span class=3D"sty=
led-by-prettify" style=3D"color: #660;">)</span><span class=3D"styled-by-pr=
ettify" style=3D"color: #000;"> </span><span class=3D"styled-by-prettify" s=
tyle=3D"color: #008;">const</span><span class=3D"styled-by-prettify" style=
=3D"color: #000;"><br>=C2=A0</span><span class=3D"styled-by-prettify" style=
=3D"color: #660;">{</span><span class=3D"styled-by-prettify" style=3D"color=
: #000;"> put</span><span class=3D"styled-by-prettify" style=3D"color: #660=
;">(</span><span class=3D"styled-by-prettify" style=3D"color: #000;">m_ftim=
emap</span><span class=3D"styled-by-prettify" style=3D"color: #660;">,</spa=
n><span class=3D"styled-by-prettify" style=3D"color: #000;"> u</span><span =
class=3D"styled-by-prettify" style=3D"color: #660;">,</span><span class=3D"=
styled-by-prettify" style=3D"color: #000;"> m_time</span><span class=3D"sty=
led-by-prettify" style=3D"color: #660;">++);</span><span class=3D"styled-by=
-prettify" style=3D"color: #000;"> </span><span class=3D"styled-by-prettify=
" style=3D"color: #660;">}</span><span class=3D"styled-by-prettify" style=
=3D"color: #000;"><br><br>=C2=A0time_pm_type m_dtimemap</span><span class=
=3D"styled-by-prettify" style=3D"color: #660;">;</span><span class=3D"style=
d-by-prettify" style=3D"color: #000;"><br>=C2=A0time_pm_type m_ftimemap</sp=
an><span class=3D"styled-by-prettify" style=3D"color: #660;">;</span><span =
class=3D"styled-by-prettify" style=3D"color: #000;"><br>=C2=A0std</span><sp=
an class=3D"styled-by-prettify" style=3D"color: #660;">::</span><span class=
=3D"styled-by-prettify" style=3D"color: #000;">size_t</span><span class=3D"=
styled-by-prettify" style=3D"color: #660;">&</span><span class=3D"style=
d-by-prettify" style=3D"color: #000;"> m_time</span><span class=3D"styled-b=
y-prettify" style=3D"color: #660;">;</span><span class=3D"styled-by-prettif=
y" style=3D"color: #000;"><br></span><span class=3D"styled-by-prettify" sty=
le=3D"color: #660;">};</span><span class=3D"styled-by-prettify" style=3D"co=
lor: #000;"><br><br>dfs_time_visitor vis</span><span class=3D"styled-by-pre=
ttify" style=3D"color: #660;">{{},</span><span class=3D"styled-by-prettify"=
style=3D"color: #000;"> </span><span class=3D"styled-by-prettify" style=3D=
"color: #660;">{</span><span class=3D"styled-by-prettify" style=3D"color: #=
000;">dtime</span><span class=3D"styled-by-prettify" style=3D"color: #660;"=
>.</span><span class=3D"styled-by-prettify" style=3D"color: #008;">begin</s=
pan><span class=3D"styled-by-prettify" style=3D"color: #660;">(),</span><sp=
an class=3D"styled-by-prettify" style=3D"color: #000;"> </span><span class=
=3D"styled-by-prettify" style=3D"color: #008;">get</span><span class=3D"sty=
led-by-prettify" style=3D"color: #660;">(</span><span class=3D"styled-by-pr=
ettify" style=3D"color: #000;">vertex_index</span><span class=3D"styled-by-=
prettify" style=3D"color: #660;">,</span><span class=3D"styled-by-prettify"=
style=3D"color: #000;"> g</span><span class=3D"styled-by-prettify" style=
=3D"color: #660;">)},</span><span class=3D"styled-by-prettify" style=3D"col=
or: #000;"><br>=C2=A0</span><span class=3D"styled-by-prettify" style=3D"col=
or: #660;">{</span><span class=3D"styled-by-prettify" style=3D"color: #000;=
">ftime</span><span class=3D"styled-by-prettify" style=3D"color: #660;">.</=
span><span class=3D"styled-by-prettify" style=3D"color: #008;">begin</span>=
<span class=3D"styled-by-prettify" style=3D"color: #660;">(),</span><span c=
lass=3D"styled-by-prettify" style=3D"color: #000;"> </span><span class=3D"s=
tyled-by-prettify" style=3D"color: #008;">get</span><span class=3D"styled-b=
y-prettify" style=3D"color: #660;">(</span><span class=3D"styled-by-prettif=
y" style=3D"color: #000;">vertex_index</span><span class=3D"styled-by-prett=
ify" style=3D"color: #660;">,</span><span class=3D"styled-by-prettify" styl=
e=3D"color: #000;"> g</span><span class=3D"styled-by-prettify" style=3D"col=
or: #660;">)},</span><span class=3D"styled-by-prettify" style=3D"color: #00=
0;"><br>=C2=A0</span><span class=3D"styled-by-prettify" style=3D"color: #06=
6;">0</span><span class=3D"styled-by-prettify" style=3D"color: #660;">};</s=
pan><span class=3D"styled-by-prettify" style=3D"color: #000;"><br>=C2=A0<br=
>depth_first_search</span><span class=3D"styled-by-prettify" style=3D"color=
: #660;">(</span><span class=3D"styled-by-prettify" style=3D"color: #000;">=
g</span><span class=3D"styled-by-prettify" style=3D"color: #660;">,</span><=
span class=3D"styled-by-prettify" style=3D"color: #000;"> visitor</span><sp=
an class=3D"styled-by-prettify" style=3D"color: #660;">(</span><span class=
=3D"styled-by-prettify" style=3D"color: #000;">vis</span><span class=3D"sty=
led-by-prettify" style=3D"color: #660;">));</span><span class=3D"styled-by-=
prettify" style=3D"color: #000;"><br></span><span class=3D"styled-by-pretti=
fy" style=3D"color: #008;">auto</span><span class=3D"styled-by-prettify" st=
yle=3D"color: #000;"> </span><span class=3D"styled-by-prettify" style=3D"co=
lor: #660;">&[</span><span class=3D"styled-by-prettify" style=3D"color:=
#000;">dtime_pm</span><span class=3D"styled-by-prettify" style=3D"color: #=
660;">,</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> ft=
ime_pm</span><span class=3D"styled-by-prettify" style=3D"color: #660;">,</s=
pan><span class=3D"styled-by-prettify" style=3D"color: #000;"> t</span><spa=
n class=3D"styled-by-prettify" style=3D"color: #660;">]</span><span class=
=3D"styled-by-prettify" style=3D"color: #000;"> </span><span class=3D"style=
d-by-prettify" style=3D"color: #660;">=3D</span><span class=3D"styled-by-pr=
ettify" style=3D"color: #000;"> vis</span><span class=3D"styled-by-prettify=
" style=3D"color: #660;">;</span></div></code></div><div><br></div><div>The=
re is no constructor; it uses aggregate initialization to get filled in (C+=
+17 lets classes with base classes be aggregates). Note how we don't ha=
ve to repeat the variable declarations; we just use structured binding to g=
ain access to the members.</div><div><br></div><div>Should we get template =
in-function classes? Sure; if lambdas can do it, why not real struct defini=
tions? But we don't need member capturing. Structured binding allows us=
to reverse the process; declaring members in the class and then referencin=
g them with new names out of it.<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">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/ba6835ff-8f92-4380-ad85-2f8b87b2665f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/ba6835ff-8f92-4380-ad85-2f8b87b2665f=
%40isocpp.org</a>.<br />
------=_Part_13461_1126673443.1514129852714--
------=_Part_13460_1972004378.1514129852713--
.
Author: jeanmichael.celerier@gmail.com
Date: Sun, 24 Dec 2017 07:43:20 -0800 (PST)
Raw View
------=_Part_13386_1013921804.1514130200619
Content-Type: multipart/alternative;
boundary="----=_Part_13387_1687009490.1514130200619"
------=_Part_13387_1687009490.1514130200619
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
> another copy of the code you posted will be created, where in less<int,=
=20
int> the instantiated function will be reused. That is why I said it leads=
=20
to no code reuse and bloat - both by definition essentially..=20
I was under the impression that either MSVC's /OPT:ICF or GCC's -fipa-icf=
=20
would be able to catch this but it seems that it's not the case as of=20
today. Oh well, time to fill out bug reports :p=20
> Local template classes alone will also be vastly closer to your original=
=20
requirement
Indeed, and I am all for making local classes them on-par with non-local=20
ones.
Best,
Jean-Micha=C3=ABl
On Sunday, December 24, 2017 at 4:08:08 PM UTC+1, mihailn...@gmail.com=20
wrote:
>
> Here is the reason why lambda is worse the less:
> =20
>
>> ??$?RHH@<lambda_e0791130af6ca6ee892f7f57d6208fb5>@@QBE_NHH@Z
>>
> =20
>
> You are comparing one lambda vs one use of less<int, int>. The moment you=
=20
> use two lambdas (which does the same, over the same types), another copy =
of=20
> the code you posted will be created, where in less<int, int> the=20
> instantiated function will be reused. That is why I said it leads to no=
=20
> code reuse and bloat - both by definition essentially..=20
>
> I also use lambdas, I also enjoy Qt5 connect, but they are not free, like=
=20
> for example inline functions - they create real classes and real code EVE=
RY=20
> TIME with ZERO reuse. =20
> The only saving grace is they have internal linkage and are *considerably=
*=20
> less heavy then normal classes.=20
>
> (I am no compiler author and I will gladly stand corrected if I am wrong=
=20
> on any of the above statements)
>
>
>
> Having said that I see no reason not to improve local classes in general.
>
> For instance, they can't be template, but now polymorphic lambda this=20
> makes much less sense:
>
> void f()
> {
> /*
> struct=20
> {
> template<class T>
> void operator()(T){}
> }d1; //< *** does not compile for legacy reasons
>
> */
> auto d2 =3D [](auto){}; //< happy 14
> auto d3 =3D []<class T>(T) {}; //< happy 20
> }
>
>
> Local template classes alone will also be vastly closer to your original=
=20
> requirement
>
> template<class... A>
> struct=20
> {
> std::tuple<A...> context;
>
> S(A... args) : context(std::move(args)...)
> {}
>
> auto operator()(int v) { auto [x] =3D context; x+v; }
> auto operator()(float v) { auto [x] =3D context; x+v; }
> auto operator()(const std::string& v) { auto [x] =3D context; v[x]; }
> }my_struct{x};
>
> std::visit(my_struct, a_variant);
>
> And this will also eliminate the need of stand alone class in=20
> the depth_first_search example
>
>
> But as I said, one should strive to use named, reusable objects - even=20
> your example about kitten_counter is not strong because the lambda has=20
> nothing to do with kittens and can be refactored out as reusable=20
> accumulator.=20
>
>
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/f5473117-939e-45c1-bdaf-3f5510aa9063%40isocpp.or=
g.
------=_Part_13387_1687009490.1514130200619
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">> another copy of the code you posted will be created, =
where in=20
less<int, int> the instantiated function will be reused. That is=20
why I said it leads to no code reuse and bloat - both by definition=20
essentially.. <br><br>I was under the impression that either MSVC's /OP=
T:ICF or GCC's -fipa-icf would be able to catch this but it seems that =
it's not the case as of today. Oh well, time to fill out bug reports :p=
<br><br>> Local template classes alone will also be vastly closer to yo=
ur original requirement<br><br>Indeed, and I am all for making local classe=
s them on-par with non-local ones.<br><br>Best,<br>Jean-Micha=C3=ABl<br><br=
>On Sunday, December 24, 2017 at 4:08:08 PM UTC+1, mihailn...@gmail.com wro=
te:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;=
border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div>Here =
is the reason why lambda is worse the less:</div><div>=C2=A0</div><blockquo=
te class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><span style=3D"display=
:inline!important;float:none;background-color:transparent;color:rgb(34,34,3=
4);font-family:courier new,monospace;font-size:13px;font-style:normal;font-=
variant:normal;font-weight:400;letter-spacing:normal;text-align:left;text-d=
ecoration:none;text-indent:0px;text-transform:none;white-space:normal;word-=
spacing:0px">??$?RHH@<lambda_</span><span style=3D"display:inline!import=
ant;float:none;background-color:transparent;color:rgb(34,34,34);font-family=
:courier new,monospace;font-size:13px;font-style:normal;font-variant:normal=
;font-weight:400;letter-spacing:normal;text-align:left;text-decoration:none=
;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">e=
0791130af6ca6<wbr>ee892f7f57d6208f</span><span style=3D"display:inline!impo=
rtant;float:none;background-color:transparent;color:rgb(34,34,34);font-fami=
ly:courier new,monospace;font-size:13px;font-style:normal;font-variant:norm=
al;font-weight:400;letter-spacing:normal;text-align:left;text-decoration:no=
ne;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"=
>b5>@@QBE_NHH@Z</span></div></div></blockquote><div>=C2=A0</div><div><br=
></div><div>You are comparing one lambda vs one use of less<int, int>=
.. The moment you use two lambdas (which does the same, over the same types)=
, another copy of the code you posted will be created, where in less<int=
, int> the instantiated function will be reused. That is why I said it l=
eads to no code reuse and bloat - both by definition essentially..=C2=A0</d=
iv><div><br></div><div>I also use lambdas, I also enjoy Qt5 connect, but th=
ey are not free, like for example inline functions - they create real class=
es and real code EVERY TIME with ZERO reuse. =C2=A0</div><div>The only savi=
ng grace is they have internal linkage and are <i>considerably</i> less hea=
vy then normal classes.=C2=A0</div><div><br></div><div>(I am no compiler au=
thor and I will gladly stand corrected if I am wrong on any of the above st=
atements)</div><div><br></div><div><br></div><div><br></div><div>Having sai=
d that I see no reason not to improve local classes in general.</div><div><=
br></div><div>For instance, they can't be template, but now polymorphic=
lambda this makes much less sense:</div><div><br></div><div><div style=3D"=
border:1px solid rgb(187,187,187);word-wrap:break-word;background-color:rgb=
(250,250,250)"><code><div><span style=3D"color:#008">voi</span><font style=
=3D"background-color:transparent" color=3D"#004000" face=3D"Arial"><span st=
yle=3D"color:#008">d</span><span style=3D"color:#000"> f</span><span style=
=3D"color:#660">()</span><span style=3D"color:#000"><br></span><span style=
=3D"color:#660">{</span><span style=3D"color:#000"><br></span><span style=
=3D"color:#800">/*<br>=C2=A0 struct <br>=C2=A0 {<br>=C2=A0 =C2=A0 template&=
lt;class T><br>=C2=A0 =C2=A0 void operator()(T){}<br>=C2=A0 }d1; //< =
*** </span><span style=3D"display:inline!important;float:none;background-co=
lor:transparent;color:rgb(136,0,0);font-family:Arial;font-size:13px;font-st=
yle:normal;font-variant:normal;font-weight:400;letter-spacing:normal;text-a=
lign:left;text-decoration:none;text-indent:0px;text-transform:none;white-sp=
ace:normal;word-spacing:0px"><span style=3D"color:#800">does not compile fo=
r legacy reasons</span></span><span style=3D"color:#800"><br><br>*/</span><=
span style=3D"color:#000"><br>=C2=A0 </span><span style=3D"color:#008">auto=
</span><span style=3D"color:#000"> d2 </span><span style=3D"color:#660">=3D=
</span><span style=3D"color:#000"> </span><span style=3D"color:#660">[](</s=
pan><span style=3D"color:#008">auto</span><span style=3D"color:#660">){};</=
span><span style=3D"color:#000"> </span><span style=3D"color:#800">//< h=
appy 14</span><span style=3D"color:#000"><br>=C2=A0 </span><span style=3D"c=
olor:#008">auto</span><span style=3D"color:#000"> d3 </span><span style=3D"=
color:#660">=3D</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#660">[]<</span><span style=3D"color:#008">class</span><span style=3D=
"color:#000"> T</span><span style=3D"color:#660">>(</span><span style=3D=
"color:#000">T</span><span style=3D"color:#660">)</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#660">{};</span><span style=3D"color:#=
000"> </span><span style=3D"color:#800">//< happy 20</span><span style=
=3D"color:#000"><br></span><span style=3D"color:#660">}</span><span style=
=3D"color:#000"><br></span></font></div></code></div><br></div><div><br></d=
iv><div>Local template classes alone will also be vastly closer to your ori=
ginal requirement</div><div><font style=3D"background-color:rgb(250,250,250=
)" color=3D"#b06400"><br></font></div><div><font style=3D"background-color:=
rgb(250,250,250)" color=3D"#006000"><div style=3D"border:1px solid rgb(187,=
187,187);word-wrap:break-word;background-color:rgb(250,250,250)"><code><div=
><font color=3D"#006000" face=3D"Arial">=C2=A0 template<class... A><b=
r>=C2=A0 struct <br>=C2=A0 {<br>=C2=A0=C2=A0=C2=A0 std::tuple<A...> c=
ontext;<br><br></font></div><div><font color=3D"#006000" face=3D"Arial">=C2=
=A0=C2=A0=C2=A0 S(A... args) : context(std::move(args)...)<br>=C2=A0=C2=A0=
=C2=A0 {}<br><br></font></div><div><font color=3D"#006000" face=3D"Arial">=
=C2=A0=C2=A0=C2=A0 auto operator()(int v) { auto [x] =3D context; x+v; }<br=
>=C2=A0=C2=A0=C2=A0 auto operator()(float v) { auto [x] =3D context; x+v; }=
<br>=C2=A0=C2=A0=C2=A0 auto operator()(const std::string& v) { auto [x]=
=3D context; v[x]; }<br>=C2=A0 }my_struct{x};<br><br></font></div><div><fo=
nt color=3D"#006000" face=3D"Arial">=C2=A0 std::visit(my_struct, a_variant)=
;</font></div></code></div><br></font></div><div>And this will also elimina=
te the need of stand alone class in the=C2=A0depth_first_search example</di=
v><div><br></div><div><br></div><div>But as I said, one should strive to us=
e named, reusable objects - even your example about <span style=3D"display:=
inline!important;float:none;background-color:transparent;color:rgb(34,34,34=
);font-family:"Arial","Helvetica",sans-serif;font-size:=
13px;font-style:normal;font-variant:normal;font-weight:400;letter-spacing:n=
ormal;text-align:left;text-decoration:none;text-indent:0px;text-transform:n=
one;white-space:normal;word-spacing:0px">kitten_counter is not strong becau=
se the lambda has nothing to do with <span style=3D"display:inline!importan=
t;float:none;background-color:transparent;color:rgb(34,34,34);font-family:&=
quot;Arial","Helvetica",sans-serif;font-size:13px;font-style=
:normal;font-variant:normal;font-weight:400;letter-spacing:normal;text-alig=
n:left;text-decoration:none;text-indent:0px;text-transform:none;white-space=
:normal;word-spacing:0px">kittens and can be refactored out as reusable acc=
umulator</span></span>.=C2=A0</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/f5473117-939e-45c1-bdaf-3f5510aa9063%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/f5473117-939e-45c1-bdaf-3f5510aa9063=
%40isocpp.org</a>.<br />
------=_Part_13387_1687009490.1514130200619--
------=_Part_13386_1013921804.1514130200619--
.
Author: jeanmichael.celerier@gmail.com
Date: Sun, 24 Dec 2017 08:02:09 -0800 (PST)
Raw View
------=_Part_13247_658636741.1514131329807
Content-Type: multipart/alternative;
boundary="----=_Part_13248_677889162.1514131329807"
------=_Part_13248_677889162.1514131329807
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
> There is no constructor; it uses aggregate initialization to get filled=
=20
in (C++17 lets classes with base classes be aggregates). Note how we don't=
=20
have to repeat the variable declarations; we just use structured binding to=
=20
gain access to the members.
I don't think that your code compiles: 0 cannot bind to a reference afaik.=
=20
Sure, you could transform it in a value in this case, but there are plenty=
=20
of cases where you *really* want to capture a reference in your local=20
class, and do so in the less error-prone way: that is, the one where you=20
have to type the least characters.
Besides, here the time_maps objects have a "relatively" simple=20
initialization. What when it gets hairier ? Do we want to have 5-lines-long=
=20
intialization calls ? Even for lambdas, I generally find
{
int a =3D ... long expression ...;
int b =3D ... other long expression ...;
[a,b] { ... };
}
to be much clearer than=20
[a=3D... long expression ...
,b=3D... long expression ...] { ... };
Think for instance to when a few lambdas like this have to be passed to a=
=20
function call: now the call itself is longer than your average function.
> Should we get template in-function classes? Sure; if lambdas can do it,=
=20
why not real struct definitions? But we don't need member capturing.=20
Structured binding allows us to reverse the process; declaring members in=
=20
the class and then referencing them with new names out of it.
So why aren't lambda-captures being deprecated then ? :^p There is not much=
=20
conceptual difference between
void foo() {=20
int x =3D some_big_expr();
bar([&x] (auto y) { ... x +=3D y; ... });=20
return x;
}
and by the logic of your example:=20
void foo() {=20
struct {=20
int x;=20
void operator()(auto y) const { ... x +=3D y; ... }
} my_fun{some_big_expr()};
bar(my_fun);
auto& [x] =3D my_fun;=20
return x;
}
=20
Best,
Jean-Micha=C3=ABl
On Sunday, December 24, 2017 at 4:37:32 PM UTC+1, Nicol Bolas wrote:
>
>
>
> On Sunday, December 24, 2017 at 10:27:00 AM UTC-5, doom.oo...@gmail.com=
=20
> wrote:
>>
>> > Even so, all you've really done is take the struct members and put the=
m*=20
>> outside* of the struct. What good did that accomplish, exactly?
>>
>> No, notice that in the existing Boost example, the members were *already=
*=20
>> outside of the struct because they are also being used by further code i=
n=20
>> the main. Two are being copied in the struct and one is referenced:=20
>> time_pm_type dtime_pm(dtime.begin(), get(vertex_index, g));=20
>> time_pm_type ftime_pm(ftime.begin(), get(vertex_index, g));=20
>> size_type t =3D 0;=20
>>
>> dfs_time_visitor < time_pm_type >vis(dtime_pm, ftime_pm, t);=20
>> depth_first_search(g, visitor(vis));
>>
>>
>> > Especially since you can put the struct definition inside of the=20
>> function already.
>>
>> Yes, but you have to write a constructor and have the members inside (an=
d=20
>> also, today, templates don't work).
>> The best we could do today would be
>>
>
> No, we can do much better today:
>
> struct dfs_time_visitor: public default_dfs_visitor {
> typedef typename property_traits < time_pm_type >::value_type T;
>
> void discover_vertex(std::size_t u, const graph_t & g) const
> { put(m_dtimemap, u, m_time++); }
> =20
> void finish_vertex(std::size_t u, const graph_t & g) const
> { put(m_ftimemap, u, m_time++); }
>
> time_pm_type m_dtimemap;
> time_pm_type m_ftimemap;
> std::size_t& m_time;
> };
>
> dfs_time_visitor vis{{}, {dtime.begin(), get(vertex_index, g)},
> {ftime.begin(), get(vertex_index, g)},
> 0};
> =20
> depth_first_search(g, visitor(vis));
> auto &[dtime_pm, ftime_pm, t] =3D vis;
>
> There is no constructor; it uses aggregate initialization to get filled i=
n=20
> (C++17 lets classes with base classes be aggregates). Note how we don't=
=20
> have to repeat the variable declarations; we just use structured binding =
to=20
> gain access to the members.
>
> Should we get template in-function classes? Sure; if lambdas can do it,=
=20
> why not real struct definitions? But we don't need member capturing.=20
> Structured binding allows us to reverse the process; declaring members in=
=20
> the class and then referencing them with new names out of it.
>
--=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/bfc56bbb-53d6-40e6-8c36-401230fe4cf2%40isocpp.or=
g.
------=_Part_13248_677889162.1514131329807
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><code><div><span style=3D"color:#660"><br></span></div></c=
ode><div>> There
is no constructor; it uses aggregate initialization to get filled in=20
(C++17 lets classes with base classes be aggregates). Note how we don't=
=20
have to repeat the variable declarations; we just use structured binding
to gain access to the members.</div><div><br>I don't think that your c=
ode compiles: 0 cannot bind to a reference afaik. Sure, you could transform=
it in a value in this case, but there are plenty of cases where you *reall=
y* want to capture a reference in your local class, and do so in the less e=
rror-prone way: that is, the one where you have to type the least character=
s.</div><div><br></div><div>Besides, here the time_maps objects have a &quo=
t;relatively" simple initialization. What when it gets hairier ? Do we=
want to have 5-lines-long intialization calls ? Even for lambdas, I genera=
lly find<br></div><div><br></div><div>=C2=A0 {<br></div><div>=C2=A0=C2=A0=
=C2=A0 int a =3D ... long expression ...;</div><div>=C2=A0=C2=A0=C2=A0 int =
b =3D ... other long expression ...;<br></div><div>=C2=A0=C2=A0=C2=A0 [a,b]=
{ ... };</div><div>=C2=A0 }</div><div><br></div><div>to be much clearer th=
an <br></div><div><br></div><div>=C2=A0=C2=A0=C2=A0 [a=3D... long expressio=
n ...</div><div>=C2=A0=C2=A0=C2=A0 ,b=3D... long expression ...] { ... };<b=
r></div><div><br></div><div>Think for instance to when a few lambdas like t=
his have to be passed to a function call: now the call itself is longer tha=
n your average function.</div><div><br></div><div>> Should we get=20
template in-function classes? Sure; if lambdas can do it, why not real=20
struct definitions? But we don't need member capturing. Structured=20
binding allows us to reverse the process; declaring members in the class
and then referencing them with new names out of it.</div><div><br></div><d=
iv>So why aren't lambda-captures being deprecated then ? :^p There is n=
ot much conceptual difference between</div><div><br></div><div>=C2=A0=C2=A0=
=C2=A0 void foo() { <br></div><div>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int x =3D=
some_big_expr();</div><div><br></div><div>=C2=A0=C2=A0 =C2=A0=C2=A0 bar([&=
amp;x] (auto y) { ... x +=3D y; ... }); <br></div><div><br></div><div>=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 return x;</div><div>=C2=A0=C2=A0=C2=A0 }<br></d=
iv><div><br></div><div>and by the logic of your example: <br></div><div><di=
v><br></div>=C2=A0 void foo() { </div><div>=C2=A0 =C2=A0 =C2=A0 struct { <b=
r></div><div>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 int x; <br></div><div>=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 void operator()(auto y) const { =
.... x +=3D y; ... }<br></div><div>=C2=A0=C2=A0 =C2=A0=C2=A0 } my_fun{some_b=
ig_expr()};</div><div><br></div><div>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 bar(my_=
fun);</div><div><br></div><div>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 auto& [x]=
=3D my_fun; <br></div><div>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return x;</div><=
div>=C2=A0 }<br></div><div>=C2=A0=C2=A0=C2=A0 <br></div><div>Best,</div><di=
v>Jean-Micha=C3=ABl<br></div><br>On Sunday, December 24, 2017 at 4:37:32 PM=
UTC+1, Nicol Bolas 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"><br><br>On Sunday, December 24, 2017 at 10:27:00 AM UTC-5, <a>=
doom.oo...@gmail.com</a> 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">> Even so, all you've really done is take the struct me=
mbers and put them<i> outside</i> of the struct. What good did that accompl=
ish, exactly?<br><br>No, notice that in the existing Boost example, the mem=
bers were *already* outside of the struct because they are also being used =
by further code in the main. Two are being copied in the struct and one is =
referenced: <br><div style=3D"background-color:rgb(250,250,250);border-colo=
r:rgb(187,187,187);border-style:solid;border-width:1px"><code><div><span st=
yle=3D"color:#000">time_pm_type dtime_pm</span><span style=3D"color:#660">(=
</span><span style=3D"color:#000">dtime</span><span style=3D"color:#660">.<=
/span><span style=3D"color:#008">begin</span><span style=3D"color:#660">(),=
</span><span style=3D"color:#000"> </span><span style=3D"color:#008">get</s=
pan><span style=3D"color:#660">(</span><span style=3D"color:#000">vertex_in=
dex</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> g<=
/span><span style=3D"color:#660">));</span><span style=3D"color:#000"> <br>=
time_pm_type ftime_pm</span><span style=3D"color:#660">(</span><span style=
=3D"color:#000">ftime</span><span style=3D"color:#660">.</span><span style=
=3D"color:#008">begin</span><span style=3D"color:#660">(),</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#008">get</span><span style=
=3D"color:#660">(</span><span style=3D"color:#000">vertex_index</span><span=
style=3D"color:#660">,</span><span style=3D"color:#000"> g</span><span sty=
le=3D"color:#660">));</span><span style=3D"color:#000"> <br>size_type t </s=
pan><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </span=
><span style=3D"color:#066">0</span><span style=3D"color:#660">;</span><spa=
n style=3D"color:#000"> <br><br>dfs_time_visitor </span><span style=3D"colo=
r:#660"><</span><span style=3D"color:#000"> time_pm_type </span><span st=
yle=3D"color:#660">></span><span style=3D"color:#000">vis</span><span st=
yle=3D"color:#660">(</span><span style=3D"color:#000">dtime_pm</span><span =
style=3D"color:#660">,</span><span style=3D"color:#000"> ftime_pm</span><sp=
an style=3D"color:#660">,</span><span style=3D"color:#000"> t</span><span s=
tyle=3D"color:#660">);</span><span style=3D"color:#000"> <br>depth_first_se=
arch</span><span style=3D"color:#660">(</span><span style=3D"color:#000">g<=
/span><span style=3D"color:#660">,</span><span style=3D"color:#000"> visito=
r</span><span style=3D"color:#660">(</span><span style=3D"color:#000">vis</=
span><span style=3D"color:#660">));</span></div></code></div><br><br>> E=
specially since you can put the struct definition inside of the function al=
ready.<br><br>Yes, but you have to write a constructor and have the members=
inside (and also, today, templates don't work).<br>The best we could d=
o today would be</div></blockquote><div><br></div><div>No, we can do much b=
etter today:</div><div><br></div><div style=3D"border:1px solid rgb(187,187=
,187);word-wrap:break-word;background-color:rgb(250,250,250)"><code><div><s=
pan style=3D"color:#008">struct</span><span style=3D"color:#000"> dfs_time_=
visitor</span><span style=3D"color:#660">:</span><span style=3D"color:#000"=
> </span><span style=3D"color:#008">public</span><span style=3D"color:#000"=
> default_dfs_visitor </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"><br>=C2=A0</span><span style=3D"color:#008">typedef</span><=
span style=3D"color:#000"> </span><span style=3D"color:#008">typename</span=
><span style=3D"color:#000"> property_traits </span><span style=3D"color:#6=
60"><</span><span style=3D"color:#000"> time_pm_type </span><span style=
=3D"color:#660">>::</span><span style=3D"color:#000">value_type T</span>=
<span style=3D"color:#660">;</span><span style=3D"color:#000"><br><br>=C2=
=A0</span><span style=3D"color:#008">void</span><span style=3D"color:#000">=
discover_vertex</span><span style=3D"color:#660">(</span><span style=3D"co=
lor:#000">std</span><span style=3D"color:#660">::</span><span style=3D"colo=
r:#000">size_t u</span><span style=3D"color:#660">,</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#008">const</span><span style=3D"col=
or:#000"> graph_t </span><span style=3D"color:#660">&</span><span style=
=3D"color:#000"> g</span><span style=3D"color:#660">)</span><span style=3D"=
color:#000"> </span><span style=3D"color:#008">const</span><span style=3D"c=
olor:#000"><br>=C2=A0</span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"> put</span><span style=3D"color:#660">(</span><span style=
=3D"color:#000">m_dtimemap</span><span style=3D"color:#660">,</span><span s=
tyle=3D"color:#000"> u</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> m_time</span><span style=3D"color:#660">++);</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#660">}</span><span style=
=3D"color:#000"><br>=C2=A0<br>=C2=A0</span><span style=3D"color:#008">void<=
/span><span style=3D"color:#000"> finish_vertex</span><span style=3D"color:=
#660">(</span><span style=3D"color:#000">std</span><span style=3D"color:#66=
0">::</span><span style=3D"color:#000">size_t u</span><span style=3D"color:=
#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:#008"=
>const</span><span style=3D"color:#000"> graph_t </span><span style=3D"colo=
r:#660">&</span><span style=3D"color:#000"> g</span><span style=3D"colo=
r:#660">)</span><span style=3D"color:#000"> </span><span style=3D"color:#00=
8">const</span><span style=3D"color:#000"><br>=C2=A0</span><span style=3D"c=
olor:#660">{</span><span style=3D"color:#000"> put</span><span style=3D"col=
or:#660">(</span><span style=3D"color:#000">m_ftimemap</span><span style=3D=
"color:#660">,</span><span style=3D"color:#000"> u</span><span style=3D"col=
or:#660">,</span><span style=3D"color:#000"> m_time</span><span style=3D"co=
lor:#660">++);</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#660">}</span><span style=3D"color:#000"><br><br>=C2=A0time_pm_type m_dti=
memap</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><=
br>=C2=A0time_pm_type m_ftimemap</span><span style=3D"color:#660">;</span><=
span style=3D"color:#000"><br>=C2=A0std</span><span style=3D"color:#660">::=
</span><span style=3D"color:#000">size_t</span><span style=3D"color:#660">&=
amp;</span><span style=3D"color:#000"> m_time</span><span style=3D"color:#6=
60">;</span><span style=3D"color:#000"><br></span><span style=3D"color:#660=
">};</span><span style=3D"color:#000"><br><br>dfs_time_visitor vis</span><s=
pan style=3D"color:#660">{{},</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#660">{</span><span style=3D"color:#000">dtime</span><span=
style=3D"color:#660">.</span><span style=3D"color:#008">begin</span><span =
style=3D"color:#660">(),</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#008">get</span><span style=3D"color:#660">(</span><span style=
=3D"color:#000">vertex_index</span><span style=3D"color:#660">,</span><span=
style=3D"color:#000"> g</span><span style=3D"color:#660">)},</span><span s=
tyle=3D"color:#000"><br>=C2=A0</span><span style=3D"color:#660">{</span><sp=
an style=3D"color:#000">ftime</span><span style=3D"color:#660">.</span><spa=
n style=3D"color:#008">begin</span><span style=3D"color:#660">(),</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#008">get</span><span =
style=3D"color:#660">(</span><span style=3D"color:#000">vertex_index</span>=
<span style=3D"color:#660">,</span><span style=3D"color:#000"> g</span><spa=
n style=3D"color:#660">)},</span><span style=3D"color:#000"><br>=C2=A0</spa=
n><span style=3D"color:#066">0</span><span style=3D"color:#660">};</span><s=
pan style=3D"color:#000"><br>=C2=A0<br>depth_first_search</span><span style=
=3D"color:#660">(</span><span style=3D"color:#000">g</span><span style=3D"c=
olor:#660">,</span><span style=3D"color:#000"> visitor</span><span style=3D=
"color:#660">(</span><span style=3D"color:#000">vis</span><span style=3D"co=
lor:#660">));</span><span style=3D"color:#000"><br></span><span style=3D"co=
lor:#008">auto</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#660">&[</span><span style=3D"color:#000">dtime_pm</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> ftime_pm</span><span st=
yle=3D"color:#660">,</span><span style=3D"color:#000"> t</span><span style=
=3D"color:#660">]</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#660">=3D</span><span style=3D"color:#000"> vis</span><span style=3D"c=
olor:#660">;</span></div></code></div><div><br></div><div>There is no const=
ructor; it uses aggregate initialization to get filled in (C++17 lets class=
es with base classes be aggregates). Note how we don't have to repeat t=
he variable declarations; we just use structured binding to gain access to =
the members.</div><div><br></div><div>Should we get template in-function cl=
asses? Sure; if lambdas can do it, why not real struct definitions? But we =
don't need member capturing. Structured binding allows us to reverse th=
e process; declaring members in the class and then referencing them with ne=
w names out of it.<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/bfc56bbb-53d6-40e6-8c36-401230fe4cf2%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/bfc56bbb-53d6-40e6-8c36-401230fe4cf2=
%40isocpp.org</a>.<br />
------=_Part_13248_677889162.1514131329807--
------=_Part_13247_658636741.1514131329807--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sun, 24 Dec 2017 08:26:21 -0800 (PST)
Raw View
------=_Part_13670_2132879375.1514132781596
Content-Type: multipart/alternative;
boundary="----=_Part_13671_1069042548.1514132781597"
------=_Part_13671_1069042548.1514132781597
Content-Type: text/plain; charset="UTF-8"
On Sunday, December 24, 2017 at 11:02:09 AM UTC-5, jeanmichae...@gmail.com
wrote:
>
>
> > There is no constructor; it uses aggregate initialization to get filled
> in (C++17 lets classes with base classes be aggregates). Note how we don't
> have to repeat the variable declarations; we just use structured binding to
> gain access to the members.
>
> I don't think that your code compiles: 0 cannot bind to a reference afaik.
> Sure, you could transform it in a value in this case, but there are plenty
> of cases where you *really* want to capture a reference in your local class,
>
That would only be for cases where the reference was passed into or
otherwise given to the function creating the local class.
and do so in the less error-prone way: that is, the one where you have to
> type the least characters.
>
> Besides, here the time_maps objects have a "relatively" simple
> initialization. What when it gets hairier ?
>
If the initialization is that hairy, then maybe this should be its own
function, or a named class that lives outside of it, or some other
abstraction.
Think for instance to when a few lambdas like this have to be passed to a
> function call: now the call itself is longer than your average function.
>
> > Should we get template in-function classes? Sure; if lambdas can do it,
> why not real struct definitions? But we don't need member capturing.
> Structured binding allows us to reverse the process; declaring members in
> the class and then referencing them with new names out of it.
>
> So why aren't lambda-captures being deprecated then ? :^p
>
First, captures aren't always for returning values. Second, your example
demonstrates the point: the code size reduction is at least a factor of 2.
That's not the case for what you want. The more functions you put in the
same object, the longer those functions are, the less costly the
boilerplate is relative to that. No matter how many functions you put into
it, there's still only one constructor (if you need a constructor at all).
Lambdas make code much shorter. What you want makes long code slightly less
long. And while I'm sure you can contrive some examples of a small number
of functions with a large number of captures or somesuch, overall, it's
just not that big of a difference.
--
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/0dfd22e9-1217-4a54-b5e7-f76c854b8829%40isocpp.org.
------=_Part_13671_1069042548.1514132781597
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Sunday, December 24, 2017 at 11:02:09 AM UTC-5, jeanmic=
hae...@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0=
;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div di=
r=3D"ltr"><code><div><span style=3D"color:#660"><br></span></div></code><di=
v>> There
is no constructor; it uses aggregate initialization to get filled in=20
(C++17 lets classes with base classes be aggregates). Note how we don't=
=20
have to repeat the variable declarations; we just use structured binding
to gain access to the members.</div><div><br>I don't think that your c=
ode compiles: 0 cannot bind to a reference afaik. Sure, you could transform=
it in a value in this case, but there are plenty of cases where you *reall=
y* want to capture a reference in your local class,</div></div></blockquote=
><div><br></div><div>That would only be for cases where the reference was p=
assed into or otherwise given to the function creating the local class.</di=
v><div><br></div><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"><div>and do so in the less error-prone way: that is, the one where you =
have to type the least characters.</div><div><br></div><div>Besides, here t=
he time_maps objects have a "relatively" simple initialization. W=
hat when it gets hairier ?</div></div></blockquote><div><br></div><div>If t=
he initialization is that hairy, then maybe this should be its own function=
, or a named class that lives outside of it, or some other abstraction.</di=
v><div><br></div><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"><div>Think for instance to when a few lambdas like this have to be pass=
ed to a function call: now the call itself is longer than your average func=
tion.</div><div><br></div><div>> Should we get=20
template in-function classes? Sure; if lambdas can do it, why not real=20
struct definitions? But we don't need member capturing. Structured=20
binding allows us to reverse the process; declaring members in the class
and then referencing them with new names out of it.</div><div><br></div><d=
iv>So why aren't lambda-captures being deprecated then ? :^p</div></div=
></blockquote><div><br></div><div>First, captures aren't always for ret=
urning values. Second, your example demonstrates the point: the code size r=
eduction is at least a factor of 2.</div><div><br></div><div>That's not=
the case for what you want. The more functions you put in the same object,=
the longer those functions are, the less costly the boilerplate is relativ=
e to that. No matter how many functions you put into it, there's still =
only one constructor (if you need a constructor at all).</div><div><br></di=
v><div>Lambdas make code much shorter. What you want makes long code slight=
ly less long. And while I'm sure you can contrive some examples of a sm=
all number of functions with a large number of captures or somesuch, overal=
l, it's just not that big of a difference.</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">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/0dfd22e9-1217-4a54-b5e7-f76c854b8829%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/0dfd22e9-1217-4a54-b5e7-f76c854b8829=
%40isocpp.org</a>.<br />
------=_Part_13671_1069042548.1514132781597--
------=_Part_13670_2132879375.1514132781596--
.
Author: mihailnajdenov@gmail.com
Date: Sun, 24 Dec 2017 08:29:07 -0800 (PST)
Raw View
------=_Part_13250_910514017.1514132947503
Content-Type: multipart/alternative;
boundary="----=_Part_13251_2100997423.1514132947503"
------=_Part_13251_2100997423.1514132947503
Content-Type: text/plain; charset="UTF-8"
On Sunday, December 24, 2017 at 5:43:20 PM UTC+2, jeanmichae...@gmail.com
wrote:
>
> > another copy of the code you posted will be created, where in less<int,
> int> the instantiated function will be reused. That is why I said it leads
> to no code reuse and bloat - both by definition essentially..
>
> I was under the impression that either MSVC's /OPT:ICF or GCC's -fipa-icf
> would be able to catch this but it seems that it's not the case as of
> today. Oh well, time to fill out bug reports :p
>
>>
>>
Have to disagree with that logic.
First you are taxingthe compiler - much larger compile times (this is no
trivial optimization),
Second you are taxing the user (in the case of a lib) - "make sure to
compile with this flag"
Third, your cade is more error prone without code reuse - on one occasion
you will get [](auto a, auto b) { a > b } wrong.
Fourth, I think you overestimate what the compiler can do (what is allowed
to do)
--
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/a1376608-a18c-46fd-a8b2-ecb893f4e2e7%40isocpp.org.
------=_Part_13251_2100997423.1514132947503
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Sunday, December 24, 2017 at 5:43:20 PM UTC+2, =
jeanmichae...@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"ma=
rgin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">=
<div dir=3D"ltr">> another copy of the code you posted will be created, =
where in=20
less<int, int> the instantiated function will be reused. That is=20
why I said it leads to no code reuse and bloat - both by definition=20
essentially.. <br><br>I was under the impression that either MSVC's /OP=
T:ICF or GCC's -fipa-icf would be able to catch this but it seems that =
it's not the case as of today. Oh well, time to fill out bug reports :p=
=C2=A0<br><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"><div><br=
></div></div></blockquote></div></blockquote><div><br></div><div>Have to di=
sagree with that logic. </div><div>First you are taxingthe compiler - much =
larger compile times (this is no trivial optimization), </div><div>Second y=
ou are taxing the user (in the case of a lib) - "make sure to compile =
with this flag" </div><div>Third, your cade is more error prone withou=
t code reuse - on one occasion you will get [](auto a, auto b) { a > b }=
wrong. </div><div>Fourth, I think you overestimate what the compiler can d=
o (what is allowed to do)</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/a1376608-a18c-46fd-a8b2-ecb893f4e2e7%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/a1376608-a18c-46fd-a8b2-ecb893f4e2e7=
%40isocpp.org</a>.<br />
------=_Part_13251_2100997423.1514132947503--
------=_Part_13250_910514017.1514132947503--
.