Topic: Type-safe inline object definition.
Author: Sarfaraz Nawaz <nawazzz@gmail.com>
Date: Sun, 24 Dec 2017 04:22:28 -0800 (PST)
Raw View
------=_Part_12916_309413318.1514118148191
Content-Type: multipart/alternative;
boundary="----=_Part_12917_1338617494.1514118148192"
------=_Part_12917_1338617494.1514118148192
Content-Type: text/plain; charset="UTF-8"
C++11 introduced the keyword *auto *which demonstrates a very simple
concept or *idea*... and that is, if you have a value, then you can create
an object out of it whose type will be inferred by the compiler.
auto x = 10; //x is inferred to be int
auto y = "Hello"s; //y is inferred to be std::string
auto z = true; //z is inferred to be bool
That is simple, isn't it? But can we extend this simple idea to create
objects of complex/composite types with many attributes/components? How
about creating an object with 3 components, *name *and *age*, and let the
compiler infer (and *define*) a suitable type to represent the object?
//define object
auto person = {
auto const name = "Rafi"s;
auto age = 55;
};
//access members
std::cout << person.name << ", " //person.name is std::string
<< person.age << "\n"; //person.age is int
From this, the compiler instantiates a class template *std::object<>*
describing *person* in such a way that programmers could *introspect* its
members, their types and names. Here is an example,
template<typename ... Ms>
void print(std::object<Ms...> const & obj) {
//access member-values as: obj.get<Ms>() ...
//access member-names as: obj.name<Ms>() ... OR Ms::name() ....
//access member-types as: typename Ms::type ...
((std::cout << Ms::name() << " = " << obj.get<Ms>() << " [" << *nicefy*
(typeid(Ms::type)) << "]\n") , .... ); //using C++17 fold-expression
//which prints
//
// name = Rafi [std::string]
// age = 55 [int]
//Or stdlib itself could provide utility like:
std::iterate(obj, [](auto const & attr) { std::cout << attr.name() << "
= " << attr.value() << " [" << *nicefy*(attr.type()) << "]\n"; });
}
We could omit *auto* and write instead (if that's not *too *weird to look
at):
auto person = {
const name = "Rafi"s,
&age = value,
const & expertise = "Playback Singing"s
};
*Previous Works As Libraries*:
- CSON <https://github.com/snawaz/cson> designed by me (only POC) but
that *requires *users to define the *labels *first to be used in the
object definition.
#include <cson/cson.h++>
//define the labels first
CSON_LABEL(name);
CSON_LABEL(age);
auto x = cson(name = "Rafi", age = 55, work = "Singing"); //define object
- IOD <https://github.com/matt-42/iod> designed by *Matthieu Garrigues*.
It's much more feature-rich library.
In both these libraries, the users has to define the labels/keys to be used
in the object definition. That makes them cumbersome 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/d4d3f4dc-18fe-48bd-bff0-ecf25b7c7742%40isocpp.org.
------=_Part_12917_1338617494.1514118148192
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><div>C++11 introduced the keyword=C2=A0<b>auto </b>whi=
ch demonstrates a very simple concept or <i>idea</i>... and that is, if you=
have a value, then you can create an object out of it whose type will be i=
nferred by the compiler.<br></div><div><br></div><div class=3D"prettyprint"=
style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187,=
187); border-style: solid; border-width: 1px; word-wrap: break-word;"><cod=
e class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color:=
#008;" class=3D"styled-by-prettify">auto</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> x </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-pr=
ettify">10</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =C2=A0 =
=C2=A0 =C2=A0 =C2=A0</span><span style=3D"color: #800;" class=3D"styled-by-=
prettify">//x is inferred to be int</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">auto</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> y </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #080;" class=3D"styled-by-prettify">"Hell=
o"</span><span style=3D"color: #000;" class=3D"styled-by-prettify">s</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> =C2=A0</span><span s=
tyle=3D"color: #800;" class=3D"styled-by-prettify">//y is inferred to be st=
d::string</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> z </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">true</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> =C2=A0 =C2=A0 =C2=A0</span><span style=3D"color: #=
800;" class=3D"styled-by-prettify">//z is inferred to be bool</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span></div></c=
ode></div><div><br></div><div>That is simple, isn't it? But can we exte=
nd this simple idea to create objects of complex/composite types with many =
attributes/components? How about creating an object with 3 components, <b>n=
ame </b>and<b>=C2=A0</b><b>age</b>, and let the compiler infer (and <i>defi=
ne</i>) a suitable type to represent the object?<br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0</div><div><div class=3D"prettyprint" style=3D"background-color: rgb(=
250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; bord=
er-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div cla=
ss=3D"subprettyprint"><span style=3D"color: #800;" class=3D"styled-by-prett=
ify">//define object</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">auto</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> p=
erson </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an 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><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">const</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> name </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: #080;" class=3D"style=
d-by-prettify">"Rafi"</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">s</span><font color=3D"#666600"><span style=3D"color: =
#660;" class=3D"styled-by-prettify">;</span></font><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0</span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> age </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"style=
d-by-prettify">55</span><font color=3D"#666600"><span style=3D"color: #660;=
" class=3D"styled-by-prettify">;</span></font><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">};</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br><br></span><span style=3D"color: #800;" class=3D"styled=
-by-prettify">//access members</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br>std</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">cout </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy"><<</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> person</span><span style=3D"color: #660;" class=3D"styled-by-prettify">.=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">name </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify"><<</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #080;" class=3D"styled-by-prettify">", "</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> =C2=A0 =C2=A0</span><=
span style=3D"color: #800;" class=3D"styled-by-prettify">//person.name is s=
td::string</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify"><<</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> person</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">age </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify"><<</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><font color=3D"#666600"><span style=3D"color: #080;" class=
=3D"styled-by-prettify">"\n"</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> =C2=A0 =C2=A0</span><span style=3D"color: #800;" class=
=3D"styled-by-prettify">//person.age is int =C2=A0 </span></font><font colo=
r=3D"#666600"></font></div></code></div><br></div><div><br></div><div><div>=
From this, the compiler instantiates a class template=C2=A0<b>std::object&l=
t;></b> describing <i>person</i>=C2=A0in such a way that programmers cou=
ld <i>introspect</i> its members, their types and names. Here is an example=
,<br></div><div><br></div><div><br></div><div class=3D"prettyprint" style=
=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187);=
border-style: solid; border-width: 1px; word-wrap: break-word;"><code clas=
s=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008;=
" class=3D"styled-by-prettify">template</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify"><</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">typename</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">...</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">M=
s</span><span style=3D"color: #660;" class=3D"styled-by-prettify">></spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">void</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">print</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">std</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">::</span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">object</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify"><</span><span style=3D"color: #606;" class=3D"styled-by-prettify">=
Ms</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">const</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">&</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> obj</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-b=
y-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #800;" class=3D"styled-by=
-prettify">//access member-values as: obj.get<Ms>() ...</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span=
><span style=3D"color: #800;" class=3D"styled-by-prettify">//access member-=
names as: obj.name<Ms>() ... =C2=A0OR Ms::name() ....</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><=
span style=3D"color: #800;" class=3D"styled-by-prettify">//access member-ty=
pes as: typename Ms::type ...</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br>=C2=A0<br>=C2=A0 =C2=A0 </span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">((</span><span 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"color: #000;" class=3D"styl=
ed-by-prettify">cout </span><span style=3D"color: #660;" class=3D"styled-by=
-prettify"><<</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">=
Ms</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">name</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: #080;" cl=
ass=3D"styled-by-prettify">" =3D "</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify"><<</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> obj</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">.</span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">get</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
"><</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Ms</=
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 styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #080;" class=3D"styled-by-prettify">" =C2=A0["</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify"><<</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><i><span style=3D"color: #000=
;" class=3D"styled-by-prettify">nicefy</span></i><span style=3D"color: #660=
;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">typeid</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">(</span><span style=3D"color: #606;" class=3D"styled-by=
-prettify">Ms</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">type<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">))</span><s=
pan 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=
: #080;" class=3D"styled-by-prettify">"]\n"</span><span style=3D"=
color: #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">,</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: #660;" class=3D"styled-by-prettify">);</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #800;" class=3D"styled-by-prettify">//using C++17 fold-expres=
sion</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 =C2=A0<br>=C2=A0 =C2=A0 </span><span style=3D"color: #800;" class=3D=
"styled-by-prettify">//which prints</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #80=
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: #80=
0;" class=3D"styled-by-prettify">// =C2=A0 =C2=A0name =3D Rafi [std::string=
]</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=
=A0 =C2=A0 </span><span style=3D"color: #800;" class=3D"styled-by-prettify"=
>// =C2=A0 =C2=A0age =3D 55 [int]</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br><br>=C2=A0 =C2=A0 </span><span style=3D"color: =
#800;" class=3D"styled-by-prettify">//Or stdlib itself could provide utilit=
y like:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>=C2=A0 <br>=C2=A0 =C2=A0 std</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify">iterate</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">o=
bj</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">[](</span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> attr</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span=
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">cout </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify"><<</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> attr</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">name</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify"><&=
lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #080;" class=3D"styled-by-prettify">" =3D "=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify"><<</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> attr</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">value</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: #660;" class=3D"s=
tyled-by-prettify"><<</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #080;" class=3D"styled-by-pr=
ettify">" ["</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y"><<</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><i><span style=3D"color: #000;" class=3D"styled-by-prettify">nicef=
y</span></i><span style=3D"color: #660;" class=3D"styled-by-prettify">(</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">attr</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">type</span><span style=3D"co=
lor: #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"><<</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #080;" class=3D"style=
d-by-prettify">"]\n"</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><=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span></div=
></code></div><div><br></div></div><div><br></div><div>We could omit <b>aut=
o</b>=C2=A0and write instead (if that's not <i>too </i>weird to look at=
):<br><br></div><div><div class=3D"prettyprint" style=3D"background-color: =
rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; =
border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div=
class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">auto</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> person </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>=3D</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 =C2=A0</span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">const</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> name </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #08=
0;" class=3D"styled-by-prettify">"Rafi"</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">s</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><font color=3D"#666600"><span =
style=3D"color: #660;" class=3D"styled-by-prettify">&</span></font><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">age </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> value</span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br>=C2=A0 =C2=A0</span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">const</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"styl=
ed-by-prettify"> expertise </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #080;" class=3D"styled-by-prettify"=
>"Playback Singing"</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">s<br></span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br></span></div></code></div><span class=3D"styled-by-prettify" styl=
e=3D"font-family: monospace; background-color: rgb(250, 250, 250); color: r=
gb(102, 102, 0);"><br></span><span class=3D"styled-by-prettify" style=3D"ba=
ckground-color: rgb(250, 250, 250); color: rgb(0, 0, 0);"><br><b style=3D""=
><font size=3D"4" style=3D"" face=3D"arial, sans-serif">Previous Works As L=
ibraries</font></b><font size=3D"4" style=3D"font-family: monospace;">:</fo=
nt></span></div><div><span class=3D"styled-by-prettify" style=3D"font-famil=
y: monospace; background-color: rgb(250, 250, 250); color: rgb(0, 0, 0);"><=
br></span></div><div><ul><li><a href=3D"https://github.com/snawaz/cson">CSO=
N</a>=C2=A0designed by me (only POC) but that <i>requires </i>users to defi=
ne the <b>labels </b>first to be used in the object definition.<br><br><div=
class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); borde=
r-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-w=
rap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"=
><span style=3D"color: #800;" class=3D"styled-by-prettify">#include</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">cson</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">/</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">cson</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">.</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">h</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">++></span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br><br></span><span style=3D"color: #800;" class=3D"styled-by-prettify">//d=
efine the labels first</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br>CSON_LABEL</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">name</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>CSO=
N_LABEL</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">age</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> x </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> cson</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">name </span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #080;" class=3D"styled-by-prettify">"=
Rafi"</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> age </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #066;" class=3D"styled-by-prettify">55</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> work </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #080;" class=3D"styled-by-=
prettify">"Singing"</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify=
">//define object</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br><br></span></div></code></div></li></ul></div><div><ul><li><a hr=
ef=3D"https://github.com/matt-42/iod">IOD</a>=C2=A0designed by <b>Matthieu =
Garrigues</b>. It's much more feature-rich library.=C2=A0</li></ul></di=
v><div><span class=3D"styled-by-prettify" style=3D"font-family: monospace; =
background-color: rgb(250, 250, 250); color: rgb(0, 0, 0);"><br></span></di=
v><div><span class=3D"styled-by-prettify" style=3D"font-family: monospace; =
background-color: rgb(250, 250, 250); color: rgb(0, 0, 0);">In both these l=
ibraries, the users has to define the labels/keys to be used in the object =
definition. That makes them cumbersome to use.</span></div><div><span class=
=3D"styled-by-prettify" style=3D"font-family: monospace; background-color: =
rgb(250, 250, 250); color: rgb(0, 0, 0);"><br></span></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/d4d3f4dc-18fe-48bd-bff0-ecf25b7c7742%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/d4d3f4dc-18fe-48bd-bff0-ecf25b7c7742=
%40isocpp.org</a>.<br />
------=_Part_12917_1338617494.1514118148192--
------=_Part_12916_309413318.1514118148191--
.
Author: Nicolas Lesser <blitzrakete@gmail.com>
Date: Sun, 24 Dec 2017 06:29:27 -0800 (PST)
Raw View
------=_Part_13360_458051083.1514125767355
Content-Type: multipart/alternative;
boundary="----=_Part_13361_638518300.1514125767356"
------=_Part_13361_638518300.1514125767356
Content-Type: text/plain; charset="UTF-8"
On Sunday, December 24, 2017 at 1:22:28 PM UTC+1, Sarfaraz Nawaz wrote:
>
>
> C++11 introduced the keyword *auto *which demonstrates a very simple
> concept or *idea*... and that is, if you have a value, then you can
> create an object out of it whose type will be inferred by the compiler.
>
> auto x = 10; //x is inferred to be int
> auto y = "Hello"s; //y is inferred to be std::string
> auto z = true; //z is inferred to be bool
>
>
> That is simple, isn't it? But can we extend this simple idea to create
> objects of complex/composite types with many attributes/components? How
> about creating an object with 3 components, *name *and *age*, and let the
> compiler infer (and *define*) a suitable type to represent the object?
>
> //define object
> auto person = {
> auto const name = "Rafi"s;
> auto age = 55;
> };
>
> //access members
> std::cout << person.name << ", " //person.name is std::string
> << person.age << "\n"; //person.age is int
>
We already have this:
struct {
std::string const name = "Rafi";
int age = 55;
} person;
Although `auto` is not possible in classes because that would complicate
implementations by a lot apparently (I heard this somewhere, forgot where).
>
> From this, the compiler instantiates a class template *std::object<>*
> describing *person* in such a way that programmers could *introspect* its
> members, their types and names. Here is an example,
>
>
> template<typename ... Ms>
> void print(std::object<Ms...> const & obj) {
> //access member-values as: obj.get<Ms>() ...
> //access member-names as: obj.name<Ms>() ... OR Ms::name() ....
> //access member-types as: typename Ms::type ...
>
> ((std::cout << Ms::name() << " = " << obj.get<Ms>() << " [" <<
> *nicefy*(typeid(Ms::type)) << "]\n") , .... ); //using C++17
> fold-expression
>
> //which prints
> //
> // name = Rafi [std::string]
> // age = 55 [int]
>
> //Or stdlib itself could provide utility like:
>
> std::iterate(obj, [](auto const & attr) { std::cout << attr.name() << "
> = " << attr.value() << " [" << *nicefy*(attr.type()) << "]\n"; });
> }
>
>
>
This will probably be possible using reflection, and thus your proposal
will probably conflict with the one from the working group. Two possible
ways to access the types from your new type above is not the best idea IMO.
> We could omit *auto* and write instead (if that's not *too *weird to look
> at):
>
> auto person = {
> const name = "Rafi"s,
> &age = value,
> const & expertise = "Playback Singing"s
> };
>
>
> *Previous Works As Libraries*:
>
>
> - CSON <https://github.com/snawaz/cson> designed by me (only POC) but
> that *requires *users to define the *labels *first to be used in the
> object definition.
>
> #include <cson/cson.h++>
>
> //define the labels first
> CSON_LABEL(name);
> CSON_LABEL(age);
>
> auto x = cson(name = "Rafi", age = 55, work = "Singing"); //define
> object
>
>
>
> - IOD <https://github.com/matt-42/iod> designed by *Matthieu Garrigues*.
> It's much more feature-rich library.
>
>
> In both these libraries, the users has to define the labels/keys to be
> used in the object definition. That makes them cumbersome 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/f63fd4e9-1f36-489d-9e04-5571fb668eb0%40isocpp.org.
------=_Part_13361_638518300.1514125767356
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Sunday, December 24, 2017 at 1:22:28 PM UTC+1, =
Sarfaraz Nawaz wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr"><br><div>C++11 introduced the keyword=C2=A0<b>auto </b>which demon=
strates a very simple concept or <i>idea</i>... and that is, if you have a =
value, then you can create an object out of it whose type will be inferred =
by the compiler.<br></div><div><br></div><div style=3D"background-color:rgb=
(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-width=
:1px;word-wrap:break-word"><code><div><span style=3D"color:#008">auto</span=
><span style=3D"color:#000"> x </span><span style=3D"color:#660">=3D</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#066">10</span><spa=
n style=3D"color:#660">;</span><span style=3D"color:#000"> =C2=A0 =C2=A0 =
=C2=A0 =C2=A0</span><span style=3D"color:#800">//x is inferred to be int</s=
pan><span style=3D"color:#000"><br></span><span style=3D"color:#008">auto</=
span><span style=3D"color:#000"> y </span><span style=3D"color:#660">=3D</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#080">"Hel=
lo"</span><span style=3D"color:#000">s</span><span style=3D"color:#660=
">;</span><span style=3D"color:#000"> =C2=A0</span><span style=3D"color:#80=
0">//y is inferred to be std::string</span><span style=3D"color:#000"><br><=
/span><span style=3D"color:#008">auto</span><span style=3D"color:#000"> z <=
/span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#008">true</span><span style=3D"color:#660">;</span=
><span style=3D"color:#000"> =C2=A0 =C2=A0 =C2=A0</span><span style=3D"colo=
r:#800">//z is inferred to be bool</span><span style=3D"color:#000"><br><br=
></span></div></code></div><div><br></div><div>That is simple, isn't it=
? But can we extend this simple idea to create objects of complex/composite=
types with many attributes/components? How about creating an object with 3=
components, <b>name </b>and<b>=C2=A0</b><b>age</b>, and let the compiler i=
nfer (and <i>define</i>) a suitable type to represent the object?<br>=C2=A0=
=C2=A0 =C2=A0 =C2=A0</div><div><div style=3D"background-color:rgb(250,250,=
250);border-color:rgb(187,187,187);border-style:solid;border-width:1px;word=
-wrap:break-word"><code><div><span style=3D"color:#800">//define object</sp=
an><span style=3D"color:#000"><br></span><span style=3D"color:#008">auto</s=
pan><span style=3D"color:#000"> person </span><span style=3D"color:#660">=
=3D</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{</=
span><span style=3D"color:#000"><br>=C2=A0 =C2=A0</span><span style=3D"colo=
r:#008">auto</span><span style=3D"color:#000"> </span><span style=3D"color:=
#008">const</span><span style=3D"color:#000"> name </span><span style=3D"co=
lor:#660">=3D</span><span style=3D"color:#000"> </span><span style=3D"color=
:#080">"Rafi"</span><span style=3D"color:#000">s</span><font colo=
r=3D"#666600"><span style=3D"color:#660">;</span></font><span style=3D"colo=
r:#000"><br>=C2=A0 =C2=A0</span><span style=3D"color:#008">auto</span><span=
style=3D"color:#000"> age </span><span style=3D"color:#660">=3D</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#066">55</span><font co=
lor=3D"#666600"><span style=3D"color:#660">;</span></font><span style=3D"co=
lor:#000"><br></span><span style=3D"color:#660">};</span><span style=3D"col=
or:#000"><br><br></span><span style=3D"color:#800">//access members</span><=
span style=3D"color:#000"><br>std</span><span style=3D"color:#660">::</span=
><span style=3D"color:#000">cout </span><span style=3D"color:#660"><<=
</span><span style=3D"color:#000"> person</span><span style=3D"color:#660">=
..</span><span style=3D"color:#000">name </span><span style=3D"color:#660">&=
lt;<</span><span style=3D"color:#000"> </span><span style=3D"color:#080"=
>", "</span><span style=3D"color:#000"> =C2=A0 =C2=A0</span><span=
style=3D"color:#800">//<a href=3D"http://person.name" target=3D"_blank" re=
l=3D"nofollow" onmousedown=3D"this.href=3D'http://www.google.com/url?q\=
x3dhttp%3A%2F%2Fperson.name\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHBTtT9z=
mH36kTrVVvjy8uLlVTivw';return true;" onclick=3D"this.href=3D'http:/=
/www.google.com/url?q\x3dhttp%3A%2F%2Fperson.name\x26sa\x3dD\x26sntz\x3d1\x=
26usg\x3dAFQjCNHBTtT9zmH36kTrVVvjy8uLlVTivw';return true;">person.name<=
/a> is std::string</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#660"><<</span><span st=
yle=3D"color:#000"> person</span><span style=3D"color:#660">.</span><span s=
tyle=3D"color:#000">age </span><span style=3D"color:#660"><<</span><s=
pan style=3D"color:#000"> </span><font color=3D"#666600"><span style=3D"col=
or:#080">"\n"</span><span style=3D"color:#660">;</span><span styl=
e=3D"color:#000"> =C2=A0 =C2=A0</span><span style=3D"color:#800">//person.a=
ge is int=C2=A0=C2=A0</span></font></div></code></div></div></div></blockqu=
ote><div><br></div><div>We already have this:</div><div><br></div><div>=C2=
=A0<span style=3D"background-color: rgb(255, 255, 254); font-family: "=
Fira Mono"; font-size: 14px; white-space: pre; color: rgb(0, 0, 255);"=
>struct</span><span style=3D"background-color: rgb(255, 255, 254); color: r=
gb(0, 0, 0); font-family: "Fira Mono"; font-size: 14px; white-spa=
ce: pre;"> {</span><br></div><div style=3D"color: rgb(0, 0, 0); background-=
color: rgb(255, 255, 254); font-family: "Fira Mono"; font-size: 1=
4px; line-height: 19px; white-space: pre;"><div> std::string <span style=
=3D"color: #0000ff;">const</span> name =3D <span style=3D"color: #a31515;">=
"Rafi"</span>;</div><div> <span style=3D"color: #0000ff;">int</=
span> age =3D <span style=3D"color: #09885a;">55</span>;</div><div>} person=
;</div><div><br></div><div>Although `auto` is not possible in classes becau=
se that would complicate implementations by a lot apparently (I heard this =
somewhere, forgot where).</div><div> </div></div><blockquote class=3D"gmail=
_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;p=
adding-left: 1ex;"><div dir=3D"ltr"><div><br></div><div><div>From this, the=
compiler instantiates a class template=C2=A0<b>std::object<></b> des=
cribing <i>person</i>=C2=A0in such a way that programmers could <i>introspe=
ct</i> its members, their types and names. Here is an example,<br></div><di=
v><br></div><div><br></div><div style=3D"background-color:rgb(250,250,250);=
border-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap=
:break-word"><code><div><span style=3D"color:#008">template</span><span sty=
le=3D"color:#660"><</span><span style=3D"color:#008">typename</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660">...</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#606">Ms</span><span style=
=3D"color:#660">></span><span style=3D"color:#000"><br></span><span styl=
e=3D"color:#008">void</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">print</span><span style=3D"color:#660">(</span><span style=
=3D"color:#000">std</span><span style=3D"color:#660">::</span><span style=
=3D"color:#008">object</span><span style=3D"color:#660"><</span><span st=
yle=3D"color:#606">Ms</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:#660">&</span><span st=
yle=3D"color:#000"> obj</span><span style=3D"color:#660">)</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=3D"=
color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#800">//access me=
mber-values as: obj.get<Ms>() ...</span><span style=3D"color:#000"><b=
r>=C2=A0 =C2=A0 </span><span style=3D"color:#800">//access member-names as:=
<a href=3D"http://obj.name" target=3D"_blank" rel=3D"nofollow" onmousedown=
=3D"this.href=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fobj.name\x=
26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFpv8d9mXHoGQwNekPnQjdRP_-laQ';re=
turn true;" onclick=3D"this.href=3D'http://www.google.com/url?q\x3dhttp=
%3A%2F%2Fobj.name\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFpv8d9mXHoGQwNekP=
nQjdRP_-laQ';return true;">obj.name</a><Ms>() ... =C2=A0OR Ms::na=
me() ....</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span s=
tyle=3D"color:#800">//access member-types as: typename Ms::type ...</span><=
span style=3D"color:#000"><br>=C2=A0<br>=C2=A0 =C2=A0 </span><span style=3D=
"color:#660">((</span><span style=3D"color:#000">std</span><span style=3D"c=
olor:#660">::</span><span style=3D"color:#000">cout </span><span style=3D"c=
olor:#660"><<</span><span style=3D"color:#000"> </span><span style=3D=
"color:#606">Ms</span><span style=3D"color:#660">::</span><span style=3D"co=
lor:#000">name</span><span style=3D"color:#660">()</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#660"><<</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#080">" =3D "</span><span=
style=3D"color:#000"> </span><span style=3D"color:#660"><<</span><sp=
an style=3D"color:#000"> obj</span><span style=3D"color:#660">.</span><span=
style=3D"color:#008">get</span><span style=3D"color:#660"><</span><span=
style=3D"color:#606">Ms</span><span style=3D"color:#660">>()</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660"><<</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#080">" =C2=A0[&=
quot;</span><span style=3D"color:#000"> </span><span style=3D"color:#660">&=
lt;<</span><span style=3D"color:#000"> </span><i><span style=3D"color:#0=
00">nicefy</span></i><span style=3D"color:#660">(</span><span style=3D"colo=
r:#008">typeid</span><span style=3D"color:#660">(</span><span style=3D"colo=
r:#606">Ms</span><span style=3D"color:#660">::</span><span style=3D"color:#=
000">type</span><span style=3D"color:#660">))</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#660"><<</span><span style=3D"color:=
#000"> </span><span style=3D"color:#080">"]\n"</span><span style=
=3D"color:#660">)</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:=
#660">....</span><span style=3D"color:#000"> </span><span style=3D"color:#6=
60">);</span><span style=3D"color:#000"> </span><span style=3D"color:#800">=
//using C++17 fold-expression</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0<br>=C2=A0 =C2=A0 </span><span style=3D"color:#800">//which prints</s=
pan><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"colo=
r:#800">//</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span =
style=3D"color:#800">// =C2=A0 =C2=A0name =3D Rafi [std::string]</span><spa=
n style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#800">=
// =C2=A0 =C2=A0age =3D 55 [int]</span><span style=3D"color:#000"><br><br>=
=C2=A0 =C2=A0 </span><span style=3D"color:#800">//Or stdlib itself could pr=
ovide utility like:</span><span style=3D"color:#000"><br>=C2=A0 <br>=C2=A0 =
=C2=A0 std</span><span style=3D"color:#660">::</span><span style=3D"color:#=
000">iterate</span><span style=3D"color:#660">(</span><span style=3D"color:=
#000">obj</span><span style=3D"color:#660">,</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#660">[](</span><span style=3D"color:#008">=
auto</span><span style=3D"color:#000"> </span><span style=3D"color:#008">co=
nst</span><span style=3D"color:#000"> </span><span style=3D"color:#660">&am=
p;</span><span style=3D"color:#000"> attr</span><span style=3D"color:#660">=
)</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{</sp=
an><span style=3D"color:#000"> std</span><span style=3D"color:#660">::</spa=
n><span style=3D"color:#000">cout </span><span style=3D"color:#660"><<=
;</span><span style=3D"color:#000"> attr</span><span style=3D"color:#660">.=
</span><span style=3D"color:#000">name</span><span style=3D"color:#660">()<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#660"><<=
;</span><span style=3D"color:#000"> </span><span style=3D"color:#080">"=
; =3D "</span><span style=3D"color:#000"> </span><span style=3D"color:=
#660"><<</span><span style=3D"color:#000"> attr</span><span style=3D"=
color:#660">.</span><span style=3D"color:#000">value</span><span style=3D"c=
olor:#660">()</span><span style=3D"color:#000"> </span><span style=3D"color=
:#660"><<</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#080">" ["</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#660"><<</span><span style=3D"color:#000"> </span><i><span=
style=3D"color:#000">nicefy</span></i><span style=3D"color:#660">(</span><=
span style=3D"color:#000">attr</span><span style=3D"color:#660">.</span><sp=
an style=3D"color:#000">type</span><span style=3D"color:#660">())</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#660"><<</span><=
span style=3D"color:#000"> </span><span style=3D"color:#080">"]\n"=
;</span><span style=3D"color:#660">;</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660">});</span><span style=3D"color:#000"><br></sp=
an><span style=3D"color:#660">}</span><span style=3D"color:#000"><br><br></=
span></div></code></div><div><br></div></div></div></blockquote><div><br></=
div><div>This will probably be possible using reflection, and thus your pro=
posal will probably conflict with the one from the working group. Two possi=
ble ways to access the types from your new type above is not the best idea =
IMO.</div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margi=
n: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><di=
v dir=3D"ltr"><div><div></div></div><div>We could omit <b>auto</b>=C2=A0and=
write instead (if that's not <i>too </i>weird to look at):<br><br></di=
v><div><div style=3D"background-color:rgb(250,250,250);border-color:rgb(187=
,187,187);border-style:solid;border-width:1px;word-wrap:break-word"><code><=
div><span style=3D"color:#008">auto</span><span style=3D"color:#000"> perso=
n </span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> <=
/span><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=
=A0 =C2=A0</span><span style=3D"color:#008">const</span><span style=3D"colo=
r:#000"> name </span><span style=3D"color:#660">=3D</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#080">"Rafi"</span><span s=
tyle=3D"color:#000">s</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"><br>=C2=A0 =C2=A0</span><font color=3D"#666600"><span style=
=3D"color:#660">&</span></font><span style=3D"color:#000">age </span><s=
pan style=3D"color:#660">=3D</span><span style=3D"color:#000"> value</span>=
<span style=3D"color:#660">,</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0</span><span style=3D"color:#008">const</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#660">&</span><span style=3D"color:#00=
0"> expertise </span><span style=3D"color:#660">=3D</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#080">"Playback Singing"</=
span><span style=3D"color:#000">s<br></span><span style=3D"color:#660">};</=
span><span style=3D"color:#000"><br></span></div></code></div><span style=
=3D"font-family:monospace;background-color:rgb(250,250,250);color:rgb(102,1=
02,0)"><br></span><span style=3D"background-color:rgb(250,250,250);color:rg=
b(0,0,0)"><br><b><font size=3D"4" face=3D"arial, sans-serif">Previous Works=
As Libraries</font></b><font size=3D"4" style=3D"font-family:monospace">:<=
/font></span></div><div><span style=3D"font-family:monospace;background-col=
or:rgb(250,250,250);color:rgb(0,0,0)"><br></span></div><div><ul><li><a href=
=3D"https://github.com/snawaz/cson" target=3D"_blank" rel=3D"nofollow" onmo=
usedown=3D"this.href=3D'https://www.google.com/url?q\x3dhttps%3A%2F%2Fg=
ithub.com%2Fsnawaz%2Fcson\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEa6qpnGng=
R_q02OOt5Dth70bp8uQ';return true;" onclick=3D"this.href=3D'https://=
www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fsnawaz%2Fcson\x26sa\x3dD=
\x26sntz\x3d1\x26usg\x3dAFQjCNEa6qpnGngR_q02OOt5Dth70bp8uQ';return true=
;">CSON</a>=C2=A0designed by me (only POC) but that <i>requires </i>users t=
o define the <b>labels </b>first to be used in the object definition.<br><b=
r><div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,=
187);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><=
span style=3D"color:#800">#include</span><span style=3D"color:#000"> </span=
><span style=3D"color:#660"><</span><span style=3D"color:#000">cson</spa=
n><span style=3D"color:#660">/</span><span style=3D"color:#000">cson</span>=
<span style=3D"color:#660">.</span><span style=3D"color:#000">h</span><span=
style=3D"color:#660">++></span><span style=3D"color:#000"><br><br></spa=
n><span style=3D"color:#800">//define the labels first</span><span style=3D=
"color:#000"><br>CSON_LABEL</span><span style=3D"color:#660">(</span><span =
style=3D"color:#000">name</span><span style=3D"color:#660">);</span><span s=
tyle=3D"color:#000"><br>CSON_LABEL</span><span style=3D"color:#660">(</span=
><span style=3D"color:#000">age</span><span style=3D"color:#660">);</span><=
span style=3D"color:#000"><br><br></span><span style=3D"color:#008">auto</s=
pan><span style=3D"color:#000"> x </span><span style=3D"color:#660">=3D</sp=
an><span style=3D"color:#000"> cson</span><span style=3D"color:#660">(</spa=
n><span style=3D"color:#000">name </span><span style=3D"color:#660">=3D</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#080">"Rafi=
"</span><span style=3D"color:#660">,</span><span style=3D"color:#000">=
age </span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"=
> </span><span style=3D"color:#066">55</span><span style=3D"color:#660">,</=
span><span style=3D"color:#000"> work </span><span style=3D"color:#660">=3D=
</span><span style=3D"color:#000"> </span><span style=3D"color:#080">"=
Singing"</span><span style=3D"color:#660">);</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#800">//define object</span><span styl=
e=3D"color:#000"><br><br></span></div></code></div></li></ul></div><div><ul=
><li><a href=3D"https://github.com/matt-42/iod" target=3D"_blank" rel=3D"no=
follow" onmousedown=3D"this.href=3D'https://www.google.com/url?q\x3dhtt=
ps%3A%2F%2Fgithub.com%2Fmatt-42%2Fiod\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQ=
jCNFm4efd-yTl3hmy9Harxc496CMGdA';return true;" onclick=3D"this.href=3D&=
#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmatt-42%2Fio=
d\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFm4efd-yTl3hmy9Harxc496CMGdA'=
;return true;">IOD</a>=C2=A0designed by <b>Matthieu Garrigues</b>. It's=
much more feature-rich library.=C2=A0</li></ul></div><div><span style=3D"f=
ont-family:monospace;background-color:rgb(250,250,250);color:rgb(0,0,0)"><b=
r></span></div><div><span style=3D"font-family:monospace;background-color:r=
gb(250,250,250);color:rgb(0,0,0)">In both these libraries, the users has to=
define the labels/keys to be used in the object definition. That makes the=
m cumbersome to use.</span></div><div><span style=3D"font-family:monospace;=
background-color:rgb(250,250,250);color:rgb(0,0,0)"><br></span></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/f63fd4e9-1f36-489d-9e04-5571fb668eb0%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/f63fd4e9-1f36-489d-9e04-5571fb668eb0=
%40isocpp.org</a>.<br />
------=_Part_13361_638518300.1514125767356--
------=_Part_13360_458051083.1514125767355--
.
Author: Laurent LA RIZZA <the.ultimate.koala@gmail.com>
Date: Sun, 24 Dec 2017 15:16:14 -0800 (PST)
Raw View
------=_Part_14016_288935318.1514157374929
Content-Type: multipart/alternative;
boundary="----=_Part_14017_1859370235.1514157374929"
------=_Part_14017_1859370235.1514157374929
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Le dimanche 24 d=C3=A9cembre 2017 15:29:27 UTC+1, Nicolas Lesser a =C3=A9cr=
it :
>
> struct {
> std::string const name =3D "Rafi";
> int age =3D 55;
> } person;
>
> Although `auto` is not possible in classes because that would complicate=
=20
> implementations by a lot apparently (I heard this somewhere, forgot where=
).
>
> Close enough, maybe :
#define AUTO(d, i) decltype(i) d =3D i
struct {
AUTO(const name, "Rafi"s);
AUTO(age, 55);
} person;
--=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/92a68b32-4be9-4fb9-b0f6-b071503ed698%40isocpp.or=
g.
------=_Part_14017_1859370235.1514157374929
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>Le dimanche 24 d=C3=A9cembre 2017 15:29:27 UTC+1, =
Nicolas Lesser a =C3=A9crit=C2=A0:<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></div><div>=C2=A0<span style=3D"background-colo=
r:rgb(255,255,254);font-family:"Fira Mono";font-size:14px;white-s=
pace:pre;color:rgb(0,0,255)">struct</span><span style=3D"background-color:r=
gb(255,255,254);color:rgb(0,0,0);font-family:"Fira Mono";font-siz=
e:14px;white-space:pre"> {</span><br></div><div style=3D"color:rgb(0,0,0);b=
ackground-color:rgb(255,255,254);font-family:"Fira Mono";font-siz=
e:14px;line-height:19px;white-space:pre"><div> std::string <span style=3D=
"color:#0000ff">const</span> name =3D <span style=3D"color:#a31515">"R=
afi"</span>;</div><div> <span style=3D"color:#0000ff">int</span> age=
=3D <span style=3D"color:#09885a">55</span>;</div><div>} person;</div><div=
><br></div><div>Although `auto` is not possible in classes because that wou=
ld complicate implementations by a lot apparently (I heard this somewhere, =
forgot where).</div></div><br></div></blockquote><div>Close enough, maybe :=
</div><div><br></div><div style=3D"margin-left: 40px;">#define AUTO(d, i) d=
ecltype(i) d =3D i</div><div><br></div><div style=3D"margin-left: 40px;">st=
ruct {<br>=C2=A0=C2=A0 AUTO(const name, "Rafi"s);<br>=C2=A0=C2=A0=
AUTO(age, 55);<br>} person;</div><div><br></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/92a68b32-4be9-4fb9-b0f6-b071503ed698%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/92a68b32-4be9-4fb9-b0f6-b071503ed698=
%40isocpp.org</a>.<br />
------=_Part_14017_1859370235.1514157374929--
------=_Part_14016_288935318.1514157374929--
.
Author: =?UTF-8?Q?Jos=C3=A9_Rodrigo?= <rodrigojose690@gmail.com>
Date: Mon, 25 Dec 2017 11:18:26 -0200
Raw View
--94eb2c06d07068cd6005612a001d
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Why not allow this instead?
auto person =3D struct { string name =3D "Bill"; short age =3D 25; };
Em 24/12/2017 9:16 PM, "Laurent LA RIZZA" <the.ultimate.koala@gmail.com>
escreveu:
>
>
> Le dimanche 24 d=C3=A9cembre 2017 15:29:27 UTC+1, Nicolas Lesser a =C3=A9=
crit :
>>
>> struct {
>> std::string const name =3D "Rafi";
>> int age =3D 55;
>> } person;
>>
>> Although `auto` is not possible in classes because that would complicate
>> implementations by a lot apparently (I heard this somewhere, forgot wher=
e).
>>
>> Close enough, maybe :
>
> #define AUTO(d, i) decltype(i) d =3D i
>
> struct {
> AUTO(const name, "Rafi"s);
> AUTO(age, 55);
> } person;
>
>
> --
> 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/92a68b32-4be9-4fb9-
> b0f6-b071503ed698%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/92a68b32-4b=
e9-4fb9-b0f6-b071503ed698%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoot=
er>
> .
>
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/CAJe%2Baq_cqTKEVAwjBJR_Nvaw%2Bj24uSjsWGzC5J%2BMY=
VUCfzCzbQ%40mail.gmail.com.
--94eb2c06d07068cd6005612a001d
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"auto">Why not allow this instead?<div dir=3D"auto"><br></div><d=
iv dir=3D"auto"><br></div><div dir=3D"auto">auto person =3D struct { string=
name =3D "Bill"; short age =3D 25; };</div></div><div class=3D"g=
mail_extra"><br><div class=3D"gmail_quote">Em 24/12/2017 9:16 PM, "Lau=
rent LA RIZZA" <<a href=3D"mailto:the.ultimate.koala@gmail.com">the=
..ultimate.koala@gmail.com</a>> escreveu:<br type=3D"attribution"><blockq=
uote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc =
solid;padding-left:1ex"><div dir=3D"ltr"><br><br>Le dimanche 24 d=C3=A9cemb=
re 2017 15:29:27 UTC+1, Nicolas Lesser a =C3=A9crit=C2=A0:<blockquote class=
=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc s=
olid;padding-left:1ex"><div dir=3D"ltr"><div></div><div>=C2=A0<span style=
=3D"background-color:rgb(255,255,254);font-family:"Fira Mono";fon=
t-size:14px;white-space:pre-wrap;color:rgb(0,0,255)">struct</span><span sty=
le=3D"background-color:rgb(255,255,254);color:rgb(0,0,0);font-family:"=
Fira Mono";font-size:14px;white-space:pre-wrap"> {</span><br></div><di=
v style=3D"color:rgb(0,0,0);background-color:rgb(255,255,254);font-family:&=
quot;Fira Mono";font-size:14px;line-height:19px;white-space:pre-wrap">=
<div> std::string <span style=3D"color:#0000ff">const</span> name =3D <sp=
an style=3D"color:#a31515">"Rafi"</span>;</div><div> <span styl=
e=3D"color:#0000ff">int</span> age =3D <span style=3D"color:#09885a">55</sp=
an>;</div><div>} person;</div><div><br></div><div>Although `auto` is not po=
ssible in classes because that would complicate implementations by a lot ap=
parently (I heard this somewhere, forgot where).</div></div><br></div></blo=
ckquote><div>Close enough, maybe :</div><div><br></div><div style=3D"margin=
-left:40px">#define AUTO(d, i) decltype(i) d =3D i</div><div><br></div><div=
style=3D"margin-left:40px">struct {<br>=C2=A0=C2=A0 AUTO(const name, "=
;Rafi"s);<br>=C2=A0=C2=A0 AUTO(age, 55);<br>} person;</div><div><br></=
div><div><br></div></div>
<p></p>
-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank">std-proposals+unsubscribe@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/92a68b32-4be9-4fb9-b0f6-b071503ed698%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/92a6=
8b32-4be9-4fb9-<wbr>b0f6-b071503ed698%40isocpp.org</a><wbr>.<br>
</blockquote></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAJe%2Baq_cqTKEVAwjBJR_Nvaw%2Bj24uSjs=
WGzC5J%2BMYVUCfzCzbQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoote=
r">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAJe%2Baq_c=
qTKEVAwjBJR_Nvaw%2Bj24uSjsWGzC5J%2BMYVUCfzCzbQ%40mail.gmail.com</a>.<br />
--94eb2c06d07068cd6005612a001d--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Mon, 25 Dec 2017 15:24:41 +0200
Raw View
On 24 December 2017 at 16:29, Nicolas Lesser <blitzrakete@gmail.com> wrote:
> Although `auto` is not possible in classes because that would complicate
> implementations by a lot apparently (I heard this somewhere, forgot where).
See http://open-std.org/JTC1/SC22/WG21/docs/papers/2014/n3897.html
--
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/CAFk2RUZX2aDhExEB7Q80QtW%2BEBBnBn1fhwqqS%3DY5zbCME_0SyQ%40mail.gmail.com.
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Mon, 25 Dec 2017 07:17:45 -0800 (PST)
Raw View
------=_Part_15827_989658814.1514215065517
Content-Type: multipart/alternative;
boundary="----=_Part_15828_1634514873.1514215065517"
------=_Part_15828_1634514873.1514215065517
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On Monday, December 25, 2017 at 8:18:30 AM UTC-5, Jos=C3=A9 Rodrigo wrote:
>
> Why not allow this instead?
>
> auto person =3D struct { string name =3D "Bill"; short age =3D 25; };
>
I'm not a big fan of C/C++'s ability to have a giant, multi-line type=20
declaration followed by a tiny, near-invisible variable name, but at the=20
very least we already have the grammar to do this.
Compared to *actual* problems that the language has, the difference between=
=20
that and putting `person` at the end of that struct declaration is=20
exceedingly trivial.
>
--=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/98fc1fac-12c8-4806-bc4d-aeeb4df0d1d4%40isocpp.or=
g.
------=_Part_15828_1634514873.1514215065517
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Monday, December 25, 2017 at 8:18:30 AM UTC-5, Jos=C3=
=A9 Rodrigo wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;marg=
in-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"=
auto">Why not allow this instead?<div dir=3D"auto"><br></div><div dir=3D"au=
to">auto person =3D struct { string name =3D "Bill"; short age =
=3D 25; };</div></div></blockquote><div><br></div><div>I'm not a big fa=
n of C/C++'s ability to have a giant, multi-line type declaration follo=
wed by a tiny, near-invisible variable name, but at the very least we alrea=
dy have the grammar to do this.</div><div><br></div><div>Compared to <i>act=
ual</i> problems that the language has, the difference between that and put=
ting `person` at the end of that struct declaration is exceedingly trivial.=
<br></div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left:=
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div><div class=3D"g=
mail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;bo=
rder-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div>
</blockquote></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/98fc1fac-12c8-4806-bc4d-aeeb4df0d1d4%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/98fc1fac-12c8-4806-bc4d-aeeb4df0d1d4=
%40isocpp.org</a>.<br />
------=_Part_15828_1634514873.1514215065517--
------=_Part_15827_989658814.1514215065517--
.
Author: Jan Wilmans <janwilmans@gmail.com>
Date: Mon, 25 Dec 2017 16:48:58 +0100
Raw View
--001a11448c12c6158a05612c1aa3
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
what would be the benefit over giving the struct a name?
On Dec 25, 2017 14:18, "Jos=C3=A9 Rodrigo" <rodrigojose690@gmail.com> wrote=
:
> Why not allow this instead?
>
>
> auto person =3D struct { string name =3D "Bill"; short age =3D 25; };
>
> Em 24/12/2017 9:16 PM, "Laurent LA RIZZA" <the.ultimate.koala@gmail.com>
> escreveu:
>
>>
>>
>> Le dimanche 24 d=C3=A9cembre 2017 15:29:27 UTC+1, Nicolas Lesser a =C3=
=A9crit :
>>>
>>> struct {
>>> std::string const name =3D "Rafi";
>>> int age =3D 55;
>>> } person;
>>>
>>> Although `auto` is not possible in classes because that would complicat=
e
>>> implementations by a lot apparently (I heard this somewhere, forgot whe=
re).
>>>
>>> Close enough, maybe :
>>
>> #define AUTO(d, i) decltype(i) d =3D i
>>
>> struct {
>> AUTO(const name, "Rafi"s);
>> AUTO(age, 55);
>> } person;
>>
>>
>> --
>> You received this message because you are subscribed to the Google Group=
s
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n
>> 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/is
>> ocpp.org/d/msgid/std-proposals/92a68b32-4be9-4fb9-b0f6-
>> b071503ed698%40isocpp.org
>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/92a68b32-4=
be9-4fb9-b0f6-b071503ed698%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoo=
ter>
>> .
>>
> --
> 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/CAJe%2Baq_cqTKEVAwjBJR_Nvaw%
> 2Bj24uSjsWGzC5J%2BMYVUCfzCzbQ%40mail.gmail.com
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAJe%2Baq_c=
qTKEVAwjBJR_Nvaw%2Bj24uSjsWGzC5J%2BMYVUCfzCzbQ%40mail.gmail.com?utm_medium=
=3Demail&utm_source=3Dfooter>
> .
>
--=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/CADtNNhh-iaX5Arg%2B0ZfwAgsy-pqdvWHHY-ejDZ%2B5rTW=
LiKKiWQ%40mail.gmail.com.
--001a11448c12c6158a05612c1aa3
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"auto">what would be the benefit over giving the struct a name?<=
/div><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On Dec 25, 2=
017 14:18, "Jos=C3=A9 Rodrigo" <<a href=3D"mailto:rodrigojose6=
90@gmail.com">rodrigojose690@gmail.com</a>> wrote:<br type=3D"attributio=
n"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left=
:1px #ccc solid;padding-left:1ex"><div dir=3D"auto">Why not allow this inst=
ead?<div dir=3D"auto"><br></div><div dir=3D"auto"><br></div><div dir=3D"aut=
o">auto person =3D struct { string name =3D "Bill"; short age =3D=
25; };</div></div><div class=3D"gmail_extra"><br><div class=3D"gmail_quote=
">Em 24/12/2017 9:16 PM, "Laurent LA RIZZA" <<a href=3D"mailto=
:the.ultimate.koala@gmail.com" target=3D"_blank">the.ultimate.koala@gmail.c=
om</a>> escreveu:<br type=3D"attribution"><blockquote class=3D"gmail_quo=
te" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"=
><div dir=3D"ltr"><br><br>Le dimanche 24 d=C3=A9cembre 2017 15:29:27 UTC+1,=
Nicolas Lesser a =C3=A9crit=C2=A0:<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></div><div>=C2=A0<span style=3D"background-color:rgb=
(255,255,254);font-family:"Fira Mono";font-size:14px;white-space:=
pre-wrap;color:rgb(0,0,255)">struct</span><span style=3D"background-color:r=
gb(255,255,254);color:rgb(0,0,0);font-family:"Fira Mono";font-siz=
e:14px;white-space:pre-wrap"> {</span><br></div><div style=3D"color:rgb(0,0=
,0);background-color:rgb(255,255,254);font-family:"Fira Mono";fon=
t-size:14px;line-height:19px;white-space:pre-wrap"><div> std::string <spa=
n style=3D"color:#0000ff">const</span> name =3D <span style=3D"color:#a3151=
5">"Rafi"</span>;</div><div> <span style=3D"color:#0000ff">int<=
/span> age =3D <span style=3D"color:#09885a">55</span>;</div><div>} person;=
</div><div><br></div><div>Although `auto` is not possible in classes becaus=
e that would complicate implementations by a lot apparently (I heard this s=
omewhere, forgot where).</div></div><br></div></blockquote><div>Close enoug=
h, maybe :</div><div><br></div><div style=3D"margin-left:40px">#define AUTO=
(d, i) decltype(i) d =3D i</div><div><br></div><div style=3D"margin-left:40=
px">struct {<br>=C2=A0=C2=A0 AUTO(const name, "Rafi"s);<br>=C2=A0=
=C2=A0 AUTO(age, 55);<br>} person;</div><div><br></div><div><br></div></div=
>
<p></p>
-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank">std-proposals+unsubscribe@isoc<wbr>pp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/92a68b32-4be9-4fb9-b0f6-b071503ed698%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/is<wbr>ocpp.org/d/msgid/std-proposals<wbr>/92a6=
8b32-4be9-4fb9-b0f6-<wbr>b071503ed698%40isocpp.org</a>.<br>
</blockquote></div></div>
<p></p>
-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank">std-proposals+unsubscribe@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAJe%2Baq_cqTKEVAwjBJR_Nvaw%2Bj24uSjs=
WGzC5J%2BMYVUCfzCzbQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Df=
ooter" target=3D"_blank">https://groups.google.com/a/<wbr>isocpp.org/d/msgi=
d/std-<wbr>proposals/CAJe%2Baq_<wbr>cqTKEVAwjBJR_Nvaw%<wbr>2Bj24uSjsWGzC5J%=
2BMYVUCfzCzbQ%<wbr>40mail.gmail.com</a>.<br>
</blockquote></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CADtNNhh-iaX5Arg%2B0ZfwAgsy-pqdvWHHY-=
ejDZ%2B5rTWLiKKiWQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CADtNNhh-iaX5=
Arg%2B0ZfwAgsy-pqdvWHHY-ejDZ%2B5rTWLiKKiWQ%40mail.gmail.com</a>.<br />
--001a11448c12c6158a05612c1aa3--
.
Author: Cleiton Santoia <cleitonsantoia@gmail.com>
Date: Tue, 9 Jan 2018 09:53:10 -0800 (PST)
Raw View
------=_Part_5879_1888585083.1515520390330
Content-Type: multipart/alternative;
boundary="----=_Part_5880_727630054.1515520390330"
------=_Part_5880_727630054.1515520390330
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
I=C2=B4ll give my 2 cents:
Lambdas already do something like that, consider the following:
int x =3D 10;
int y =3D 20;
std::string u =3D "test";
=20
auto l =3D [x, &y, z =3D u + " expression" ](){}
IDK for sure, but I presume that piece of code will probably be converted=
=20
to :
int x =3D 10;
int y =3D 20;
std::string u =3D "test";
class _some_compiler_gen_weired_name {
const int x; // param#1 'x' captured by copy
const int &y; // param#2 '&y' captured by ref =20
const std::string z; // param#3 'u + " expression"' captured by value
public:
_some_compiler_gen_weired_name (int _p1, int& _p2, std::string _p3 ) :
x(_p1), y(_p2), z(_p3) {}
};
auto l =3D _some_compiler_gen_weired_name (x, y, u + " expression");
So, if we could=20
1 - Make captured data members public and accessible by their capture names=
..
2 - Make the "param decl ()" and "body {}" parts of lambda optional.
3 - When item 2 happens, set the default to "not const/mutable" members,=20
and also allow "const" somewhere before or after the [] to override 'not=20
const' default;=20
The 'person' example would be like this:
auto person =3D [name =3D "Bill"s, age =3D 25]; // <- allow () and [] be op=
tional=20
in lambda definition.
int m =3D person.age;
Other examples:
auto l =3D [x, &y, z =3D u + " expression" ];=20
int k =3D l.x + l.y + l.z.size() + l.w;
auto person2 =3D [name =3D "Bill"s; age =3D short(25)]; // forcing th=
e=20
string and short types
auto person3 =3D const [name =3D "Bill"s; age =3D short(25)]; // making con=
st=20
members
const auto person3 =3D [name =3D "Bill"s; age =3D short(25)]; // members ar=
e not=20
const, the variable 'person3' is.
template<typename T>=20
void foo(const T&...p) {=20
cout << p.a << " " << p.b << " " << p.c;
}
foo( [a=3D1, b=3D2, c=3D3] ); // Yeah ! you can call a function too !
foo( [a=3D"rhs structured bindings ?", b=3D"or heterogeneous initialization=
=20
list ?" , c=3D"or named parameters?" ] );
4 - On top of that, if we allow a scope after [] and define any members:
auto lambda =3D [x, y] {
int z =3D 8;
int square(){ return z*z; };
};
lambda.x =3D lambda.square() + lambda.y;
and the lambda will be expanded as usual, even the constructor for capture=
=20
( witch is one of main reason of this ), but with two new members (z=3D8 an=
d=20
foo) in the definition.
5 - Don=C2=B4t ask about "this", some duck-taping was made in "normal" lamb=
das,=20
I=C2=B4m not sure but I think we cannot apply the same idea here.
6 - Neither about non-default constructors (since we do not know the name=
=20
of the lambda type) if you want that, please use "normal" structures.
BR
Cleiton
Em segunda-feira, 25 de dezembro de 2017 13:17:45 UTC-2, Nicol Bolas=20
escreveu:
>
> On Monday, December 25, 2017 at 8:18:30 AM UTC-5, Jos=C3=A9 Rodrigo wrote=
:
>>
>> Why not allow this instead?
>>
>> auto person =3D struct { string name =3D "Bill"; short age =3D 25; };
>>
>
> I'm not a big fan of C/C++'s ability to have a giant, multi-line type=20
> declaration followed by a tiny, near-invisible variable name, but at the=
=20
> very least we already have the grammar to do this.
>
> Compared to *actual* problems that the language has, the difference=20
> between that and putting `person` at the end of that struct declaration i=
s=20
> exceedingly trivial.
>
>>
--=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/3e9a140c-64a6-4c85-b5ed-ccc28ee803ca%40isocpp.or=
g.
------=_Part_5880_727630054.1515520390330
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I=C2=B4ll give my 2 cents:<div><br></div><div>Lambdas alre=
ady do something like that, consider the following:<div><br></div><div><div=
class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); borde=
r-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-w=
rap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"=
><font face=3D"courier new, monospace"><div class=3D"subprettyprint">=C2=A0=
=C2=A0 int x =3D 10;</div><div class=3D"subprettyprint">=C2=A0 =C2=A0 int =
y =3D 20;</div><div class=3D"subprettyprint">=C2=A0 =C2=A0 std::string u =
=3D "test";</div><div class=3D"subprettyprint">=C2=A0 =C2=A0=C2=
=A0</div><div class=3D"subprettyprint">=C2=A0 =C2=A0 auto l =3D [x, &y,=
z =3D u + " expression" ](){}</div></font></div></code></div><di=
v><br></div><div>IDK for sure, but I presume that piece of code will probab=
ly be converted to :</div><div><br></div><div><div class=3D"prettyprint" st=
yle=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 18=
7); border-style: solid; border-width: 1px; word-wrap: break-word;"><code c=
lass=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">int</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> x </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-pretti=
fy">10</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> y </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" cla=
ss=3D"styled-by-prettify">20</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">;<br></span><span style=3D"" class=3D"styled-by-prettify"=
><font color=3D"#000000">std::string u =3D "test";</font><br><br>=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">class</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> _some_compiler=
_gen_weired_name=C2=A0</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br>=C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">const</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> x</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> =C2=A0</span><span style=3D"color=
: #800;" class=3D"styled-by-prettify">// param#1 'x' captured by co=
py</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=
=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">const<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">&</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">y</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: #800;" class=3D"styled-by-pre=
ttify">// param#2 '&y' captured by ref =C2=A0</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">const</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><font color=3D"#000088">=
<span style=3D"color: #000;" class=3D"styled-by-prettify">std</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">string</span></font><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> z</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">; // param#3 'u + " express=
ion"' captured by value</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">public</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">:</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br>=C2=A0 =C2=A0</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify"><span style=3D"color: rgb(0, 0, 0);">_some_compiler_gen_weired_=
name=C2=A0</span>(</span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">int</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> _p1</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> _p2</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: #000;" class=3D"st=
yled-by-prettify">std</span><font color=3D"#666600"><span style=3D"color: #=
660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">string</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">=C2=A0_p3</span></font><span style=3D"color: #000;"=
class=3D"styled-by-prettify">=C2=A0</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br>=C2=A0 =C2=A0 =C2=A0 =C2=A0x</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">_p1</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">),</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> y<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify">_p2</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">),</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> z</span><font color=3D"#666600"><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">_p3</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify">=C2=A0</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">{}</span></font><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">auto</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> l </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=C2=A0</sp=
an><span style=3D"color: rgb(0, 0, 0);">_some_compiler_gen_weired_name=C2=
=A0</span><span style=3D"color: rgb(0, 0, 0);"><span style=3D"color: #660;"=
class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">x</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> y</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">=C2=A0u + &quo=
t; expression"</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">);</span></span><span style=3D"color: rgb(0, 0, 0);"></span></div>=
</code></div><br>So, if we could=C2=A0</div><div><div>1 - Make captured dat=
a members public and accessible by their capture names.</div><div>2 - Make =
the "param decl ()" and "body {}"=C2=A0 parts of lambda=
optional.</div><div>3 - When item 2 happens, set the default to "not =
const/mutable" members, and also allow "const" somewhere bef=
ore or after the [] to override 'not const' default;=C2=A0</div><di=
v><br></div><div>The 'person' example would be like this:</div><div=
><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); =
border-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; w=
ord-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyp=
rint"><span style=3D"background-color: rgb(255, 255, 255);"><font face=3D"c=
ourier new, monospace">auto person =3D [name =3D "Bill"s, age =3D=
25];=C2=A0</font></span><span style=3D"font-family: "courier new"=
;, monospace;">// <- allow () and [] be optional in lambda definition.</=
span><span style=3D"background-color: rgb(255, 255, 255);"><font face=3D"co=
urier new, monospace"><br></font></span>int m =3D person.age;<br></div></co=
de></div><br>Other examples:</div></div><div><div class=3D"prettyprint" sty=
le=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187=
); border-style: solid; border-width: 1px; word-wrap: break-word;"><code cl=
ass=3D"prettyprint"><div class=3D"subprettyprint"><div class=3D"subprettypr=
int" style=3D""><font face=3D"courier new, monospace">auto l =3D [x, &y=
, z =3D u + " expression" ];=C2=A0</font><br><font face=3D"courie=
r new, monospace">int k =3D l.x + l.y + l.z.size() + l.w;</font><br><br><sp=
an style=3D"font-family: "courier new", monospace; background-col=
or: rgb(255, 255, 255);">auto person2 =3D=C2=A0 =C2=A0 =C2=A0 =C2=A0[name =
=3D "Bill"s; age =3D short(25)]; // forcing the string and short =
types</span><br style=3D"font-family: "courier new", monospace; b=
ackground-color: rgb(255, 255, 255);"><span style=3D"font-family: "cou=
rier new", monospace; background-color: rgb(255, 255, 255);">auto pers=
on3 =3D=C2=A0</span><span style=3D"background-color: rgb(255, 255, 255); fo=
nt-family: "courier new", monospace;">const=C2=A0</span><span sty=
le=3D"background-color: rgb(255, 255, 255); font-family: "courier new&=
quot;, monospace;">[name =3D "Bill"s; age =3D short(25)]; // maki=
ng const members</span></div><div class=3D"subprettyprint" style=3D""><span=
style=3D"font-family: "courier new", monospace; background-color=
: rgb(255, 255, 255);">const auto person3 =3D [name =3D "Bill"s; =
age =3D short(25)]; // members are not const, the variable 'person3'=
; is.</span><span style=3D"font-family: "courier new", monospace;=
background-color: rgb(255, 255, 255);"><br></span><br style=3D"font-family=
: "courier new", monospace; background-color: rgb(255, 255, 255);=
">template<typename T> <br>void foo(const T&...p) { <br>=C2=A0 =
=C2=A0cout << p.a << " " << p.b << "=
=C2=A0 " << p.c;<br>}<br><br>foo( [a=3D1, b=3D2, c=3D3]=C2=A0);=
=C2=A0 // Yeah ! you can call a function too !<br>foo( [a=3D"rhs struc=
tured bindings ?", b=3D"or heterogeneous initialization list ?&qu=
ot; , c=3D"or named parameters?" ] );<br></div></div></code></div=
><div><br></div>4 - On top of that, if we allow a scope after [] and define=
any members:</div><div><br></div><div><div class=3D"prettyprint" style=3D"=
background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); bor=
der-style: solid; border-width: 1px; word-wrap: break-word;"><code class=3D=
"prettyprint"><div class=3D"subprettyprint"><font color=3D"#660066">auto la=
mbda =3D [x, y] {<br>=C2=A0 int z =3D 8;<br>=C2=A0 int square(){ return z*z=
; };<br>};<br><br>lambda.x =3D lambda.</font><span style=3D"color: rgb(102,=
0, 102);">square() + lambda.y;</span></div></code></div><br>and the lambda=
will be expanded as usual, even the constructor for capture ( witch is one=
of main reason of this ), but with two new members (z=3D8 and foo) in the =
definition.<br></div><div><br></div><div><br></div><div>5 - Don=C2=B4t ask =
about "this", some duck-taping was made in "normal" lam=
bdas, I=C2=B4m not sure but I think we cannot apply the same idea here.</di=
v><div>6 - Neither about non-default constructors (since we do not know the=
name of the lambda type) if you want that, please use "normal" s=
tructures.</div><div><br></div><div><br></div><div><br></div><div>BR</div><=
div>Cleiton</div><div><br></div><div>Em segunda-feira, 25 de dezembro de 20=
17 13:17:45 UTC-2, Nicol Bolas escreveu:<blockquote class=3D"gmail_quote" =
style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-l=
eft: 1ex;"><div dir=3D"ltr">On Monday, December 25, 2017 at 8:18:30 AM UTC-=
5, Jos=C3=A9 Rodrigo wrote:<blockquote class=3D"gmail_quote" style=3D"margi=
n:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=
=3D"auto">Why not allow this instead?<div dir=3D"auto"><br></div><div dir=
=3D"auto">auto person =3D struct { string name =3D "Bill"; short =
age =3D 25; };</div></div></blockquote><div><br></div><div>I'm not a bi=
g fan of C/C++'s ability to have a giant, multi-line type declaration f=
ollowed by a tiny, near-invisible variable name, but at the very least we a=
lready have the grammar to do this.</div><div><br></div><div>Compared to <i=
>actual</i> problems that the language has, the difference between that and=
putting `person` at the end of that struct declaration is exceedingly triv=
ial.<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-le=
ft:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class=3D"gm=
ail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;bor=
der-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div>
</blockquote></div></blockquote></div></div></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/3e9a140c-64a6-4c85-b5ed-ccc28ee803ca%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/3e9a140c-64a6-4c85-b5ed-ccc28ee803ca=
%40isocpp.org</a>.<br />
------=_Part_5880_727630054.1515520390330--
------=_Part_5879_1888585083.1515520390330--
.