Topic: Primary constructors for C++ ?
Author: ripopov@gmail.com
Date: Tue, 25 Sep 2018 10:21:26 -0700 (PDT)
Raw View
------=_Part_987_802076215.1537896086955
Content-Type: multipart/alternative;
boundary="----=_Part_988_44493998.1537896086956"
------=_Part_988_44493998.1537896086956
Content-Type: text/plain; charset="UTF-8"
Hello, can you provide any feedback for this idea?
Primary constructors for C++
*Problem:*
C++11 allows in-class member initialization. However, in-class initializers
have no access to constructor parameters, which makes them useless in many
scenarios. Example:
template<typename T, unsigned N>
class MyClass {
public:
MyClass(unsigned n) {}
private:
T x0 {N}; // OK
T x1 {n}; // Error
T x2 {n + N}; // Error
}
So essentially in this case C++ favors compile-time template interfaces
over run-time constructor interfaces.
Currently we have to use old constructor member initializer list syntax, if
we need to pass parameters in run-time. This is less readable: member
initialization is separated from declaration.
*Possible solution: *
Primary constructors (similar to Scala, Kotlin and abandoned C# proposal)
We can designate one constructor as primary. Parameters of primary
constructor should be visible to in-class initializers. All other
constructors must call primary constructor in their constructor
initialization list. Primary constructor is public by default.
For example, we can use following syntax (similar to languages with this
feature):
template<typename T, unsigned N>
class MyClass (unsigned n) { // primary ctor , public
public:
// secondary ctor
MyClass() : MyClass(42) {}
private:
T x0 {N}; // OK
T x1 {n}; // OK
T x1 {n+N}; // OK
}
Advantages:
1.
Compile-time (template parameters) and run-time (constructor parameters)
interfaces are nicely grouped together. So class user can quickly check how
to construct an object.
2.
Data members declaration and initialization are grouped together
Some other languages also allow more complex multi-line initialization
inside constructor body.
This is very usefull for DSL construction.
I think it will be possible to reproduce it in C++ 20 using
[[no_unique_address]] attribute:
Example (With Kotlin syntax):
// Library support
template <unsigned UNIQ>
struct InitInvoker {
template <typename T>
InitInvoker(T && f) { f(); }
};
#define CONCAT_(x,y) x##y
#define CONCAT(x,y) CONCAT_(x,y)
#define init \
[[no_unique_address]] InitInvoker<__LINE__> CONCAT(__init_,__LINE__) =
[this] { \
CONCAT(__init_fn_,__LINE__) ();\
};\
void CONCAT(__init_fn_,__LINE__) ()
// Usage example
class TwoWidgetsWithInit (const std::string& basename, int x, int y) {
MyWidget w0 { name + std::to_string(0) };
init { w0.setX(x);
w0.setY(y); }
MyWidget w1 { name + std::to_string(1) };
init { w1.setX(x);
w1.setY(y); }
};
So essentially primary constructors are syntatic sugar to improve code
readability.
--
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/05c2d528-9837-4968-b19e-42875434962c%40isocpp.org.
------=_Part_988_44493998.1537896086956
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><font face=3D"arial, sans-serif" size=3D"2">Hello, can you=
provide any feedback for this idea?</font><div><font face=3D"arial, sans-s=
erif" size=3D"2"><br></font></div><div><span id=3D"docs-internal-guid-b825e=
030-7fff-7284-87ef-7776a5da2fae"><p dir=3D"ltr" style=3D"font-size: small; =
font-family: arial, sans-serif; line-height: 1.38; margin-top: 0pt; margin-=
bottom: 0pt;"><span style=3D"color: rgb(0, 0, 0); background-color: transpa=
rent; font-variant-numeric: normal; font-variant-east-asian: normal; vertic=
al-align: baseline; white-space: pre-wrap;">Primary constructors for C++</s=
pan></p><div style=3D"font-size: small; font-family: arial, sans-serif;"><s=
pan style=3D"color: rgb(0, 0, 0); background-color: transparent; font-varia=
nt-numeric: normal; font-variant-east-asian: normal; vertical-align: baseli=
ne; white-space: pre-wrap;"><br></span></div><div style=3D""><span style=3D=
"background-color: transparent; font-variant-numeric: normal; font-variant-=
east-asian: normal; vertical-align: baseline;"><span id=3D"docs-internal-gu=
id-7e9ba96d-7fff-98dd-4a0a-4a0e81a875d3" style=3D""><p dir=3D"ltr" style=3D=
"color: rgb(0, 0, 0); font-size: small; white-space: pre-wrap; font-family:=
arial, sans-serif; line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;=
"><span style=3D"background-color: transparent; font-variant-numeric: norma=
l; font-variant-east-asian: normal; vertical-align: baseline;"><b>Problem:<=
/b></span></p><div style=3D"color: rgb(0, 0, 0); font-size: small; white-sp=
ace: pre-wrap; font-family: arial, sans-serif;"><span style=3D"background-c=
olor: transparent; font-variant-numeric: normal; font-variant-east-asian: n=
ormal; vertical-align: baseline;"><br></span></div><div style=3D""><span st=
yle=3D"background-color: transparent; font-variant-numeric: normal; font-va=
riant-east-asian: normal; vertical-align: baseline;"><p dir=3D"ltr" style=
=3D"color: rgb(0, 0, 0); font-size: small; white-space: pre-wrap; font-fami=
ly: arial, sans-serif; line-height: 1.38;"><span style=3D"background-color:=
transparent; font-variant-numeric: normal; font-variant-east-asian: normal=
; vertical-align: baseline;">C++11 allows in-class member initialization. H=
owever, in-class initializers have no access to constructor parameters, whi=
ch makes them useless in many scenarios. Example:</span></p><font face=3D"a=
rial, sans-serif" style=3D"color: rgb(0, 0, 0); font-size: small; white-spa=
ce: pre-wrap;"><br></font><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font=
-size: small; white-space: pre-wrap; line-height: 1.38;"><span style=3D"bac=
kground-color: transparent; font-variant-numeric: normal; font-variant-east=
-asian: normal; vertical-align: baseline;"><font face=3D"courier new, monos=
pace">template<typename T, unsigned N></font></span></p><p dir=3D"ltr=
" style=3D"color: rgb(0, 0, 0); font-size: small; white-space: pre-wrap; li=
ne-height: 1.38;"><span style=3D"background-color: transparent; font-varian=
t-numeric: normal; font-variant-east-asian: normal; vertical-align: baselin=
e;"><font face=3D"courier new, monospace">class MyClass {</font></span></p>=
<p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: small; white-space:=
pre-wrap; line-height: 1.38;"><span style=3D"background-color: transparent=
; font-variant-numeric: normal; font-variant-east-asian: normal; vertical-a=
lign: baseline;"><font face=3D"courier new, monospace">public:</font></span=
></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: small; white-s=
pace: pre-wrap; line-height: 1.38;"><font face=3D"courier new, monospace"><=
span style=3D"background-color: transparent; font-variant-numeric: normal; =
font-variant-east-asian: normal; vertical-align: baseline;"><span class=3D"=
Apple-tab-span" style=3D"white-space:pre;"> </span></span><span style=3D"ba=
ckground-color: transparent; font-variant-numeric: normal; font-variant-eas=
t-asian: normal; vertical-align: baseline;">MyClass(unsigned n) {}</span></=
font></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: small; whi=
te-space: pre-wrap; line-height: 1.38;"><span style=3D"background-color: tr=
ansparent; font-variant-numeric: normal; font-variant-east-asian: normal; v=
ertical-align: baseline;"><font face=3D"courier new, monospace">private:</f=
ont></span></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: smal=
l; white-space: pre-wrap; line-height: 1.38;"><font face=3D"courier new, mo=
nospace"><span style=3D"background-color: transparent; font-variant-numeric=
: normal; font-variant-east-asian: normal; vertical-align: baseline;"><span=
class=3D"Apple-tab-span" style=3D"white-space:pre;"> </span></span><span s=
tyle=3D"background-color: transparent; font-variant-numeric: normal; font-v=
ariant-east-asian: normal; vertical-align: baseline;">T x0 {N}; // OK</span=
></font></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: small; =
white-space: pre-wrap; line-height: 1.38;"><font face=3D"courier new, monos=
pace"><span style=3D"background-color: transparent; font-variant-numeric: n=
ormal; font-variant-east-asian: normal; vertical-align: baseline;"><span cl=
ass=3D"Apple-tab-span" style=3D"white-space:pre;"> </span></span><span styl=
e=3D"background-color: transparent; font-variant-numeric: normal; font-vari=
ant-east-asian: normal; vertical-align: baseline;">T x1 {n}; // Error</span=
></font></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: small; =
white-space: pre-wrap; line-height: 1.38;"><font face=3D"courier new, monos=
pace"><span style=3D"background-color: transparent; font-variant-numeric: n=
ormal; font-variant-east-asian: normal; vertical-align: baseline;"><span cl=
ass=3D"Apple-tab-span" style=3D"white-space:pre;"> </span></span><span styl=
e=3D"background-color: transparent; font-variant-numeric: normal; font-vari=
ant-east-asian: normal; vertical-align: baseline;">T x2 {n + N}; // Error</=
span></font></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: sma=
ll; white-space: pre-wrap; line-height: 1.38;"><span style=3D"background-co=
lor: transparent; font-variant-numeric: normal; font-variant-east-asian: no=
rmal; vertical-align: baseline;"><font face=3D"courier new, monospace">}</f=
ont></span></p><font face=3D"arial, sans-serif" style=3D"color: rgb(0, 0, 0=
); font-size: small; white-space: pre-wrap;"><br></font><p dir=3D"ltr" styl=
e=3D"color: rgb(0, 0, 0); font-size: small; white-space: pre-wrap; font-fam=
ily: arial, sans-serif; line-height: 1.38;"><span style=3D"background-color=
: transparent; font-variant-numeric: normal; font-variant-east-asian: norma=
l; vertical-align: baseline;">So essentially in this case C++ favors compil=
e-time template interfaces over run-time constructor interfaces.</span></p>=
<p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: small; white-space:=
pre-wrap; font-family: arial, sans-serif; line-height: 1.38;"><span style=
=3D"background-color: transparent; font-variant-numeric: normal; font-varia=
nt-east-asian: normal; vertical-align: baseline;">Currently we have to use =
old constructor member initializer list syntax, if we need to pass paramete=
rs in run-time. This is less readable: member initialization is separated f=
rom declaration.</span></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); fon=
t-size: small; white-space: pre-wrap; font-family: arial, sans-serif; line-=
height: 1.38;"><span style=3D"background-color: transparent; font-variant-n=
umeric: normal; font-variant-east-asian: normal; vertical-align: baseline;"=
><br></span></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: sma=
ll; white-space: pre-wrap; font-family: arial, sans-serif; line-height: 1.3=
8;"><span style=3D"background-color: transparent; font-variant-numeric: nor=
mal; font-variant-east-asian: normal; vertical-align: baseline;"><span id=
=3D"docs-internal-guid-2b39a629-7fff-dc78-6723-1f83c06d07a9"></span></span>=
</p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: small; white-sp=
ace: pre-wrap; font-family: arial, sans-serif; line-height: 1.38; margin-to=
p: 0pt; margin-bottom: 0pt;"><span style=3D"color: rgb(0, 0, 0); background=
-color: transparent; font-style: normal; font-variant: normal; text-decorat=
ion: none; vertical-align: baseline; white-space: pre-wrap;"><b>Possible so=
lution: =C2=A0</b></span></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); f=
ont-size: small; white-space: pre-wrap; font-family: arial, sans-serif; lin=
e-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><span style=3D"color:=
rgb(0, 0, 0); background-color: transparent; font-weight: 400; font-style:=
normal; font-variant: normal; text-decoration: none; vertical-align: basel=
ine; white-space: pre-wrap;"><br></span></p><p dir=3D"ltr" style=3D"color: =
rgb(0, 0, 0); font-size: small; white-space: pre-wrap; font-family: arial, =
sans-serif; line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><span =
style=3D"color: rgb(0, 0, 0); background-color: transparent; font-weight: 4=
00; font-style: normal; font-variant: normal; text-decoration: none; vertic=
al-align: baseline; white-space: pre-wrap;">Primary constructors (similar t=
o Scala, Kotlin and abandoned C# proposal)</span></p><p dir=3D"ltr" style=
=3D"color: rgb(0, 0, 0); font-size: small; white-space: pre-wrap; font-fami=
ly: arial, sans-serif; line-height: 1.38; margin-top: 0pt; margin-bottom: 0=
pt;"><span style=3D"color: rgb(0, 0, 0); background-color: transparent; fon=
t-weight: 400; font-style: normal; font-variant: normal; text-decoration: n=
one; vertical-align: baseline; white-space: pre-wrap;"><b style=3D"font-wei=
ght:normal;" id=3D"docs-internal-guid-539dc48b-7fff-0f72-b7b2-b1fc45c38b62"=
><br></b></span></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size:=
small; white-space: pre-wrap; font-family: arial, sans-serif; line-height:=
1.38; margin-top: 0pt; margin-bottom: 0pt;"><span style=3D"color: rgb(0, 0=
, 0); background-color: transparent; font-weight: 400; font-style: normal; =
font-variant: normal; text-decoration: none; vertical-align: baseline; whit=
e-space: pre-wrap;">We can designate one constructor as primary. Parameters=
of primary constructor should be visible to in-class initializers. All oth=
er constructors must call primary constructor in their constructor initiali=
zation list. Primary constructor is public by default.</span></p><p dir=3D"=
ltr" style=3D"color: rgb(0, 0, 0); font-size: small; white-space: pre-wrap;=
font-family: arial, sans-serif; line-height: 1.38; margin-top: 0pt; margin=
-bottom: 0pt;"><span style=3D"color: rgb(0, 0, 0); background-color: transp=
arent; font-weight: 400; font-style: normal; font-variant: normal; text-dec=
oration: none; vertical-align: baseline; white-space: pre-wrap;"><b style=
=3D"font-weight:normal;"><br></b></span></p><p dir=3D"ltr" style=3D"color: =
rgb(0, 0, 0); font-size: small; white-space: pre-wrap; font-family: arial, =
sans-serif; line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><span =
style=3D"color: rgb(0, 0, 0); background-color: transparent; font-weight: 4=
00; font-style: normal; font-variant: normal; text-decoration: none; vertic=
al-align: baseline; white-space: pre-wrap;">For example, we can use followi=
ng syntax (similar to languages with this feature):</span></p><p dir=3D"ltr=
" style=3D"color: rgb(0, 0, 0); font-size: small; white-space: pre-wrap; fo=
nt-family: arial, sans-serif; line-height: 1.38; margin-top: 0pt; margin-bo=
ttom: 0pt;"><span style=3D"color: rgb(0, 0, 0); background-color: transpare=
nt; font-weight: 400; font-style: normal; font-variant: normal; text-decora=
tion: none; vertical-align: baseline; white-space: pre-wrap;"><b style=3D"f=
ont-weight:normal;"><br></b></span></p><p dir=3D"ltr" style=3D"color: rgb(0=
, 0, 0); font-size: small; white-space: pre-wrap; font-family: arial, sans-=
serif; line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><span style=
=3D"color: rgb(0, 0, 0); background-color: transparent; font-weight: 400; f=
ont-style: normal; font-variant: normal; text-decoration: none; vertical-al=
ign: baseline; white-space: pre-wrap;">template<typename T, unsigned N&g=
t;</span></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: small;=
white-space: pre-wrap; font-family: arial, sans-serif; line-height: 1.38; =
margin-top: 0pt; margin-bottom: 0pt;"><span style=3D"color: rgb(0, 0, 0); b=
ackground-color: transparent; font-weight: 400; font-style: normal; font-va=
riant: normal; text-decoration: none; vertical-align: baseline; white-space=
: pre-wrap;">class MyClass (unsigned n) { // primary ctor , public</span></=
p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: small; white-spac=
e: pre-wrap; font-family: arial, sans-serif; line-height: 1.38; margin-top:=
0pt; margin-bottom: 0pt;"><span style=3D"color: rgb(0, 0, 0); background-c=
olor: transparent; font-weight: 400; font-style: normal; font-variant: norm=
al; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;=
">public:</span></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size:=
small; white-space: pre-wrap; font-family: arial, sans-serif; line-height:=
1.38; margin-top: 0pt; margin-bottom: 0pt;"><span style=3D"color: rgb(0, 0=
, 0); background-color: transparent; font-weight: 400; font-style: normal; =
font-variant: normal; text-decoration: none; vertical-align: baseline; whit=
e-space: pre-wrap;"><span class=3D"Apple-tab-span" style=3D"white-space:pre=
;"> </span></span><span style=3D"color: rgb(0, 0, 0); background-color: tra=
nsparent; font-weight: 400; font-style: normal; font-variant: normal; text-=
decoration: none; vertical-align: baseline; white-space: pre-wrap;">// seco=
ndary ctor</span></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size=
: small; white-space: pre-wrap; font-family: arial, sans-serif; line-height=
: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><span style=3D"color: rgb(0, =
0, 0); background-color: transparent; font-weight: 400; font-style: normal;=
font-variant: normal; text-decoration: none; vertical-align: baseline; whi=
te-space: pre-wrap;"><span class=3D"Apple-tab-span" style=3D"white-space:pr=
e;"> </span></span><span style=3D"color: rgb(0, 0, 0); background-color: tr=
ansparent; font-weight: 400; font-style: normal; font-variant: normal; text=
-decoration: none; vertical-align: baseline; white-space: pre-wrap;">MyClas=
s() : MyClass(42) {}</span></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0);=
font-size: small; white-space: pre-wrap; font-family: arial, sans-serif; l=
ine-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><span style=3D"colo=
r: rgb(0, 0, 0); background-color: transparent; font-weight: 400; font-styl=
e: normal; font-variant: normal; text-decoration: none; vertical-align: bas=
eline; white-space: pre-wrap;">private:</span></p><p dir=3D"ltr" style=3D"c=
olor: rgb(0, 0, 0); font-size: small; white-space: pre-wrap; font-family: a=
rial, sans-serif; line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;">=
<span style=3D"color: rgb(0, 0, 0); background-color: transparent; font-wei=
ght: 400; font-style: normal; font-variant: normal; text-decoration: none; =
vertical-align: baseline; white-space: pre-wrap;"><span class=3D"Apple-tab-=
span" style=3D"white-space:pre;"> </span></span><span style=3D"color: rgb(0=
, 0, 0); background-color: transparent; font-weight: 400; font-style: norma=
l; font-variant: normal; text-decoration: none; vertical-align: baseline; w=
hite-space: pre-wrap;">T x0 {N}; // OK</span></p><p dir=3D"ltr" style=3D"co=
lor: rgb(0, 0, 0); font-size: small; white-space: pre-wrap; font-family: ar=
ial, sans-serif; line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><=
span style=3D"color: rgb(0, 0, 0); background-color: transparent; font-weig=
ht: 400; font-style: normal; font-variant: normal; text-decoration: none; v=
ertical-align: baseline; white-space: pre-wrap;"><span class=3D"Apple-tab-s=
pan" style=3D"white-space:pre;"> </span></span><span style=3D"color: rgb(0,=
0, 0); background-color: transparent; font-weight: 400; font-style: normal=
; font-variant: normal; text-decoration: none; vertical-align: baseline; wh=
ite-space: pre-wrap;">T x1 {n}; // OK</span></p><p dir=3D"ltr" style=3D"col=
or: rgb(0, 0, 0); font-size: small; white-space: pre-wrap; font-family: ari=
al, sans-serif; line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><s=
pan style=3D"color: rgb(0, 0, 0); background-color: transparent; font-weigh=
t: 400; font-style: normal; font-variant: normal; text-decoration: none; ve=
rtical-align: baseline; white-space: pre-wrap;"><span class=3D"Apple-tab-sp=
an" style=3D"white-space:pre;"> </span></span><span style=3D"color: rgb(0, =
0, 0); background-color: transparent; font-weight: 400; font-style: normal;=
font-variant: normal; text-decoration: none; vertical-align: baseline; whi=
te-space: pre-wrap;">T x1 {n+N}; // OK</span></p><p dir=3D"ltr" style=3D"co=
lor: rgb(0, 0, 0); font-size: small; white-space: pre-wrap; font-family: ar=
ial, sans-serif; line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><=
span style=3D"color: rgb(0, 0, 0); background-color: transparent; font-weig=
ht: 400; font-style: normal; font-variant: normal; text-decoration: none; v=
ertical-align: baseline; white-space: pre-wrap;">}</span></p><p dir=3D"ltr"=
style=3D"color: rgb(0, 0, 0); font-size: small; white-space: pre-wrap; fon=
t-family: arial, sans-serif; line-height: 1.38; margin-top: 0pt; margin-bot=
tom: 0pt;"><span style=3D"color: rgb(0, 0, 0); background-color: transparen=
t; font-weight: 400; font-style: normal; font-variant: normal; text-decorat=
ion: none; vertical-align: baseline; white-space: pre-wrap;">Advantages:</s=
pan></p><ol style=3D"color: rgb(0, 0, 0); font-size: small; white-space: pr=
e-wrap; font-family: arial, sans-serif; margin-top: 0pt; margin-bottom: 0pt=
;"><li dir=3D"ltr" style=3D"list-style-type: decimal; color: rgb(0, 0, 0); =
background-color: transparent; font-weight: 400; font-style: normal; font-v=
ariant: normal; text-decoration: none; vertical-align: baseline; white-spac=
e: pre;"><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bot=
tom:0pt;"><span style=3D"color: rgb(0, 0, 0); background-color: transparent=
; font-weight: 400; font-style: normal; font-variant: normal; text-decorati=
on: none; vertical-align: baseline; white-space: pre-wrap;">Compile-time (t=
emplate parameters) and run-time (constructor parameters) interfaces are ni=
cely grouped together. So class user can quickly check how to construct an =
object.</span></p></li><li dir=3D"ltr" style=3D"list-style-type: decimal; c=
olor: rgb(0, 0, 0); background-color: transparent; font-weight: 400; font-s=
tyle: normal; font-variant: normal; text-decoration: none; vertical-align: =
baseline; white-space: pre;"><p dir=3D"ltr" style=3D"line-height:1.38;margi=
n-top:0pt;margin-bottom:0pt;"><span style=3D"color: rgb(0, 0, 0); backgroun=
d-color: transparent; font-weight: 400; font-style: normal; font-variant: n=
ormal; text-decoration: none; vertical-align: baseline; white-space: pre-wr=
ap;">Data members declaration and initialization are grouped together</span=
></p></li></ol><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: smal=
l; white-space: pre-wrap; font-family: arial, sans-serif; line-height: 1.38=
; margin-top: 0pt; margin-bottom: 0pt;"><span style=3D"color: rgb(0, 0, 0);=
background-color: transparent; font-weight: 400; font-style: normal; font-=
variant: normal; text-decoration: none; vertical-align: baseline; white-spa=
ce: pre-wrap;"><b style=3D"font-weight:normal;"><br></b></span></p><p dir=
=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: small; white-space: pre-w=
rap; font-family: arial, sans-serif; line-height: 1.38; margin-top: 0pt; ma=
rgin-bottom: 0pt;"><span style=3D"color: rgb(0, 0, 0); background-color: tr=
ansparent; font-weight: 400; font-style: normal; font-variant: normal; text=
-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Some o=
ther languages also allow more complex multi-line initialization inside con=
structor body.</span></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-=
size: small; white-space: pre-wrap; font-family: arial, sans-serif; line-he=
ight: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><span style=3D"color: rgb=
(0, 0, 0); background-color: transparent; font-weight: 400; font-style: nor=
mal; font-variant: normal; text-decoration: none; vertical-align: baseline;=
white-space: pre-wrap;">This is very usefull for DSL construction. </span>=
</p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: small; white-sp=
ace: pre-wrap; font-family: arial, sans-serif; line-height: 1.38; margin-to=
p: 0pt; margin-bottom: 0pt;"><span style=3D"color: rgb(0, 0, 0); background=
-color: transparent; font-weight: 400; font-style: normal; font-variant: no=
rmal; text-decoration: none; vertical-align: baseline; white-space: pre-wra=
p;"><br></span></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: =
small; white-space: pre-wrap; font-family: arial, sans-serif; line-height: =
1.38; margin-top: 0pt; margin-bottom: 0pt;"><span style=3D"color: rgb(0, 0,=
0); background-color: transparent; font-weight: 400; font-style: normal; f=
ont-variant: normal; text-decoration: none; vertical-align: baseline; white=
-space: pre-wrap;">I think it will be possible to reproduce it in C++ 20 us=
ing [[no_unique_address]] attribute:</span></p><p dir=3D"ltr" style=3D"colo=
r: rgb(0, 0, 0); font-size: small; white-space: pre-wrap; font-family: aria=
l, sans-serif; line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><sp=
an style=3D"color: rgb(0, 0, 0); background-color: transparent; font-weight=
: 400; font-style: normal; font-variant: normal; text-decoration: none; ver=
tical-align: baseline; white-space: pre-wrap;"><b style=3D"font-weight:norm=
al;"><br></b></span></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-s=
ize: small; white-space: pre-wrap; font-family: arial, sans-serif; line-hei=
ght: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><span style=3D"color: rgb(=
0, 0, 0); background-color: transparent; font-weight: 400; font-style: norm=
al; font-variant: normal; text-decoration: none; vertical-align: baseline; =
white-space: pre-wrap;">Example (With Kotlin syntax):</span></p><p dir=3D"l=
tr" style=3D"color: rgb(0, 0, 0); font-size: small; white-space: pre-wrap; =
font-family: arial, sans-serif; line-height: 1.38; margin-top: 0pt; margin-=
bottom: 0pt;"><span style=3D"color: rgb(0, 0, 0); background-color: transpa=
rent; font-weight: 400; font-style: normal; font-variant: normal; text-deco=
ration: none; vertical-align: baseline; white-space: pre-wrap;"><b style=3D=
"font-weight:normal;"><br></b></span></p><p dir=3D"ltr" style=3D"color: rgb=
(0, 0, 0); font-size: small; white-space: pre-wrap; line-height: 1.38; marg=
in-top: 0pt; margin-bottom: 0pt;"><span style=3D"color: rgb(0, 0, 0); backg=
round-color: transparent; font-weight: 400; font-style: normal; font-varian=
t: normal; text-decoration: none; vertical-align: baseline; white-space: pr=
e-wrap;"><font face=3D"courier new, monospace">// Library support</font></s=
pan></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: small; whit=
e-space: pre-wrap; line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;"=
><span style=3D"color: rgb(0, 0, 0); background-color: transparent; font-we=
ight: 400; font-style: normal; font-variant: normal; text-decoration: none;=
vertical-align: baseline; white-space: pre-wrap;"><font face=3D"courier ne=
w, monospace">template <unsigned UNIQ></font></span></p><p dir=3D"ltr=
" style=3D"color: rgb(0, 0, 0); font-size: small; white-space: pre-wrap; li=
ne-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><span style=3D"color=
: rgb(0, 0, 0); background-color: transparent; font-weight: 400; font-style=
: normal; font-variant: normal; text-decoration: none; vertical-align: base=
line; white-space: pre-wrap;"><font face=3D"courier new, monospace">struct =
InitInvoker {</font></span></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0);=
font-size: small; white-space: pre-wrap; line-height: 1.38; margin-top: 0p=
t; margin-bottom: 0pt;"><span style=3D"color: rgb(0, 0, 0); background-colo=
r: transparent; font-weight: 400; font-style: normal; font-variant: normal;=
text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><=
font face=3D"courier new, monospace"> =C2=A0=C2=A0=C2=A0template <typena=
me T></font></span></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font=
-size: small; white-space: pre-wrap; line-height: 1.38; margin-top: 0pt; ma=
rgin-bottom: 0pt;"><span style=3D"color: rgb(0, 0, 0); background-color: tr=
ansparent; font-weight: 400; font-style: normal; font-variant: normal; text=
-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><font =
face=3D"courier new, monospace"> =C2=A0=C2=A0=C2=A0InitInvoker(T &&=
f) { f(); }</font></span></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); =
font-size: small; white-space: pre-wrap; line-height: 1.38; margin-top: 0pt=
; margin-bottom: 0pt;"><span style=3D"color: rgb(0, 0, 0); background-color=
: transparent; font-weight: 400; font-style: normal; font-variant: normal; =
text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><f=
ont face=3D"courier new, monospace">};</font></span></p><p dir=3D"ltr" styl=
e=3D"color: rgb(0, 0, 0); font-size: small; white-space: pre-wrap; line-hei=
ght: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><span style=3D"color: rgb(=
0, 0, 0); background-color: transparent; font-weight: 400; font-style: norm=
al; font-variant: normal; text-decoration: none; vertical-align: baseline; =
white-space: pre-wrap;"><b style=3D"font-weight:normal;"><font face=3D"cour=
ier new, monospace"><br></font></b></span></p><p dir=3D"ltr" style=3D"color=
: rgb(0, 0, 0); font-size: small; white-space: pre-wrap; line-height: 1.38;=
margin-top: 0pt; margin-bottom: 0pt;"><span style=3D"color: rgb(0, 0, 0); =
background-color: transparent; font-weight: 400; font-style: normal; font-v=
ariant: normal; text-decoration: none; vertical-align: baseline; white-spac=
e: pre-wrap;"><font face=3D"courier new, monospace">#define CONCAT_(x,y) x#=
#y</font></span></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size:=
small; white-space: pre-wrap; line-height: 1.38; margin-top: 0pt; margin-b=
ottom: 0pt;"><span style=3D"color: rgb(0, 0, 0); background-color: transpar=
ent; font-weight: 400; font-style: normal; font-variant: normal; text-decor=
ation: none; vertical-align: baseline; white-space: pre-wrap;"><font face=
=3D"courier new, monospace">#define CONCAT(x,y) CONCAT_(x,y)</font></span><=
/p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: small; white-spa=
ce: pre-wrap; line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><spa=
n style=3D"color: rgb(0, 0, 0); background-color: transparent; font-weight:=
400; font-style: normal; font-variant: normal; text-decoration: none; vert=
ical-align: baseline; white-space: pre-wrap;"><b style=3D"font-weight:norma=
l;"><font face=3D"courier new, monospace"><br></font></b></span></p><p dir=
=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: small; white-space: pre-w=
rap; line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><span style=
=3D"color: rgb(0, 0, 0); background-color: transparent; font-weight: 400; f=
ont-style: normal; font-variant: normal; text-decoration: none; vertical-al=
ign: baseline; white-space: pre-wrap;"><font face=3D"courier new, monospace=
">#define init \</font></span></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, =
0); font-size: small; white-space: pre-wrap; line-height: 1.38; margin-top:=
0pt; margin-bottom: 0pt;"><span style=3D"color: rgb(0, 0, 0); background-c=
olor: transparent; font-weight: 400; font-style: normal; font-variant: norm=
al; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;=
"><font face=3D"courier new, monospace">[[no_unique_address]] InitInvoker&l=
t;__LINE__> CONCAT(__init_,__LINE__) =3D [this] { \</font></span></p><p =
dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: small; white-space: pr=
e-wrap; line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><span styl=
e=3D"color: rgb(0, 0, 0); background-color: transparent; font-weight: 400; =
font-style: normal; font-variant: normal; text-decoration: none; vertical-a=
lign: baseline; white-space: pre-wrap;"><font face=3D"courier new, monospac=
e">CONCAT(__init_fn_,__LINE__) ();\</font></span></p><p dir=3D"ltr" style=
=3D"color: rgb(0, 0, 0); font-size: small; white-space: pre-wrap; line-heig=
ht: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><span style=3D"color: rgb(0=
, 0, 0); background-color: transparent; font-weight: 400; font-style: norma=
l; font-variant: normal; text-decoration: none; vertical-align: baseline; w=
hite-space: pre-wrap;"><font face=3D"courier new, monospace">};\</font></sp=
an></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: small; white=
-space: pre-wrap; line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;">=
<span style=3D"color: rgb(0, 0, 0); background-color: transparent; font-wei=
ght: 400; font-style: normal; font-variant: normal; text-decoration: none; =
vertical-align: baseline; white-space: pre-wrap;"><font face=3D"courier new=
, monospace">void CONCAT(__init_fn_,__LINE__) ()</font></span></p><p dir=3D=
"ltr" style=3D"color: rgb(0, 0, 0); font-size: small; white-space: pre-wrap=
; line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><span style=3D"c=
olor: rgb(0, 0, 0); background-color: transparent; font-weight: 400; font-s=
tyle: normal; font-variant: normal; text-decoration: none; vertical-align: =
baseline; white-space: pre-wrap;"><b style=3D"font-weight:normal;"><font fa=
ce=3D"courier new, monospace"><br></font></b></span></p><p dir=3D"ltr" styl=
e=3D"color: rgb(0, 0, 0); font-size: small; white-space: pre-wrap; line-hei=
ght: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><span style=3D"color: rgb(=
0, 0, 0); background-color: transparent; font-weight: 400; font-style: norm=
al; font-variant: normal; text-decoration: none; vertical-align: baseline; =
white-space: pre-wrap;"><font face=3D"courier new, monospace">// Usage exam=
ple</font></span></p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size=
: small; white-space: pre-wrap; line-height: 1.38; margin-top: 0pt; margin-=
bottom: 0pt;"><span style=3D"color: rgb(0, 0, 0); background-color: transpa=
rent; font-weight: 400; font-style: normal; font-variant: normal; text-deco=
ration: none; vertical-align: baseline; white-space: pre-wrap;"><font face=
=3D"courier new, monospace">class TwoWidgetsWithInit (const std::string&=
; basename, int x, int y) {</font></span></p><p dir=3D"ltr" style=3D"color:=
rgb(0, 0, 0); font-size: small; white-space: pre-wrap; line-height: 1.38; =
margin-top: 0pt; margin-bottom: 0pt;"><span style=3D"color: rgb(0, 0, 0); b=
ackground-color: transparent; font-weight: 400; font-style: normal; font-va=
riant: normal; text-decoration: none; vertical-align: baseline; white-space=
: pre-wrap;"><b style=3D"font-weight:normal;"><font face=3D"courier new, mo=
nospace"><br></font></b></span></p><p dir=3D"ltr" style=3D"color: rgb(0, 0,=
0); font-size: small; white-space: pre-wrap; line-height: 1.38; margin-top=
: 0pt; margin-bottom: 0pt;"><span style=3D"color: rgb(0, 0, 0); background-=
color: transparent; font-weight: 400; font-style: normal; font-variant: nor=
mal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap=
;"><font face=3D"courier new, monospace"> =C2=A0=C2=A0=C2=A0MyWidget w0 { n=
ame + std::to_string(0) };</font></span></p><p dir=3D"ltr" style=3D"color: =
rgb(0, 0, 0); font-size: small; white-space: pre-wrap; line-height: 1.38; m=
argin-top: 0pt; margin-bottom: 0pt;"><span style=3D"color: rgb(0, 0, 0); ba=
ckground-color: transparent; font-weight: 400; font-style: normal; font-var=
iant: normal; text-decoration: none; vertical-align: baseline; white-space:=
pre-wrap;"><font face=3D"courier new, monospace"> =C2=A0=C2=A0=C2=A0init {=
=C2=A0w0.setX(x); </font></span></p><p dir=3D"ltr" style=3D"color: rgb(0, =
0, 0); font-size: small; white-space: pre-wrap; line-height: 1.38; margin-t=
op: 0pt; margin-bottom: 0pt;"><span style=3D"color: rgb(0, 0, 0); backgroun=
d-color: transparent; font-weight: 400; font-style: normal; font-variant: n=
ormal; text-decoration: none; vertical-align: baseline; white-space: pre-wr=
ap;"><font face=3D"courier new, monospace"> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0w0.setY(y); }</font></span></p><p=
dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: small; white-space: p=
re-wrap; line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><span sty=
le=3D"color: rgb(0, 0, 0); background-color: transparent; font-weight: 400;=
font-style: normal; font-variant: normal; text-decoration: none; vertical-=
align: baseline; white-space: pre-wrap;"><b style=3D"font-weight:normal;"><=
font face=3D"courier new, monospace"><br></font></b></span></p><p dir=3D"lt=
r" style=3D"color: rgb(0, 0, 0); font-size: small; white-space: pre-wrap; l=
ine-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><span style=3D"colo=
r: rgb(0, 0, 0); background-color: transparent; font-weight: 400; font-styl=
e: normal; font-variant: normal; text-decoration: none; vertical-align: bas=
eline; white-space: pre-wrap;"><font face=3D"courier new, monospace"> =C2=
=A0=C2=A0=C2=A0MyWidget w1 { name + std::to_string(1) };</font></span></p><=
p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: small; white-space: =
pre-wrap; line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><span st=
yle=3D"color: rgb(0, 0, 0); background-color: transparent; font-weight: 400=
; font-style: normal; font-variant: normal; text-decoration: none; vertical=
-align: baseline; white-space: pre-wrap;"><font face=3D"courier new, monosp=
ace"> =C2=A0=C2=A0=C2=A0init { =C2=A0w1.setX(x); </font></span></p><p dir=
=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: small; white-space: pre-w=
rap; line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt; text-indent: 3=
6pt;"><span style=3D"color: rgb(0, 0, 0); background-color: transparent; fo=
nt-weight: 400; font-style: normal; font-variant: normal; text-decoration: =
none; vertical-align: baseline; white-space: pre-wrap;"><font face=3D"couri=
er new, monospace"> w1.setY(y); }</font></span></p><p dir=3D"ltr" style=3D"=
color: rgb(0, 0, 0); font-size: small; white-space: pre-wrap; line-height: =
1.38; margin-top: 0pt; margin-bottom: 0pt;"><font face=3D"courier new, mono=
space"><span style=3D"background-color: transparent;">};</span><br></font><=
/p><p dir=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: small; white-spa=
ce: pre-wrap; font-family: arial, sans-serif; line-height: 1.38; margin-top=
: 0pt; margin-bottom: 0pt;"><span style=3D"color: rgb(0, 0, 0); background-=
color: transparent; font-weight: 400; font-style: normal; font-variant: nor=
mal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap=
;"><br></span></p><p dir=3D"ltr" style=3D"font-family: arial, sans-serif; l=
ine-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;">So essentially prim=
ary constructors are syntatic sugar to improve code readability.</p><p dir=
=3D"ltr" style=3D"color: rgb(0, 0, 0); font-size: small; white-space: pre-w=
rap; font-family: arial, sans-serif; line-height: 1.38;"><br></p></span></d=
iv></span></span></div></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/05c2d528-9837-4968-b19e-42875434962c%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/05c2d528-9837-4968-b19e-42875434962c=
%40isocpp.org</a>.<br />
------=_Part_988_44493998.1537896086956--
------=_Part_987_802076215.1537896086955--
.
Author: Jake Arkinstall <jake.arkinstall@gmail.com>
Date: Tue, 25 Sep 2018 18:37:12 +0100
Raw View
--000000000000bf83260576b58e3a
Content-Type: text/plain; charset="UTF-8"
On Tue, 25 Sep 2018, 18:21 ,<ripopov@gmail.com> wrote:
> Currently we have to use old constructor member initializer list syntax,
> if we need to pass parameters in run-time. This is less readable: member
> initialization is separated from declaration.
>
This is a subjective claim. I find the initializer list approach more
readable, from a structural point of view.
The reason that we can use template arguments in member constructors is
that the template argument is in scope and because template arguments are
constexpr. That we can do this is completely logical, and that we can't do
this with variables is also completely logical.
The way I think about proposals is generally "how many confused posts is
this going to generate on programming forums?". I think that, although your
solution does go some way to solve a stylistic issue, it introduces some
conceptual issues surrounding scope.
For example, is "n" accessible elsewhere in the class - e.g. can it be
referred to within a function? If not, why not? It's in scope after all,
and not allowing it would be counter-intuitive to many people. If so,
though, what is its behaviour when the value changes elsewhere? If it's a
const reference, and the source variable is freed, what happens? How many
people are going to add instances of this object to a container in a loop
and wonder why they're getting memory access problems?
--
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/CAC%2B0CCPyW-_TdLfrO62q9B2dPFRATXpg8omkphfgDOUFUj9yAg%40mail.gmail.com.
--000000000000bf83260576b58e3a
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"auto"><div class=3D"gmail_quote" dir=3D"auto"><div dir=3D"ltr">=
On Tue, 25 Sep 2018, 18:21 ,<<a href=3D"mailto:ripopov@gmail.com">ripopo=
v@gmail.com</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=
=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=
=3D"ltr"><span id=3D"m_-2309461081484197675docs-internal-guid-b825e030-7fff=
-7284-87ef-7776a5da2fae"><span style=3D"background-color:transparent;font-v=
ariant-numeric:normal;font-variant-east-asian:normal;vertical-align:baselin=
e"><span id=3D"m_-2309461081484197675docs-internal-guid-7e9ba96d-7fff-98dd-=
4a0a-4a0e81a875d3"><span style=3D"background-color:transparent;font-variant=
-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline"><p =
dir=3D"ltr" style=3D"color:rgb(0,0,0);font-size:small;white-space:pre-wrap;=
font-family:arial,sans-serif;line-height:1.38">Currently we have to use old=
constructor member initializer list syntax, if we need to pass parameters =
in run-time. This is less readable: member initialization is separated from=
declaration.</p></span></span></span></span></div></blockquote></div><div =
dir=3D"auto"><br></div><div dir=3D"auto">This is a subjective claim. I find=
the initializer list approach more readable, from a structural point of vi=
ew.</div><div dir=3D"auto"><br></div><div dir=3D"auto">The reason that we c=
an use template arguments in member constructors is that the template argum=
ent is in scope and because template arguments are constexpr. That we can d=
o this is completely logical, and that we can't do this with variables =
is also completely logical.</div><div dir=3D"auto"><br></div><div dir=3D"au=
to"><span style=3D"font-family:sans-serif">The way I think about proposals =
is generally "how many confused posts is this going to generate on pro=
gramming forums?". I think that, although your solution does go some w=
ay to solve a stylistic issue, it introduces some conceptual issues surroun=
ding scope.</span><br></div><div dir=3D"auto"><br></div><div dir=3D"auto">F=
or example, is "n" accessible elsewhere in the class - e.g. can i=
t be referred to within a function? If not, why not? It's in scope afte=
r all, and not allowing it would be counter-intuitive to many people. If so=
, though, what is its behaviour when the value changes elsewhere? If it'=
;s a const reference, and the source variable is freed, what happens? How m=
any people are going to add instances of this object to a container in a lo=
op and wonder why they're getting memory access problems?</div><div cla=
ss=3D"gmail_quote" dir=3D"auto"></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/CAC%2B0CCPyW-_TdLfrO62q9B2dPFRATXpg8o=
mkphfgDOUFUj9yAg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAC%2B0CCPyW-_T=
dLfrO62q9B2dPFRATXpg8omkphfgDOUFUj9yAg%40mail.gmail.com</a>.<br />
--000000000000bf83260576b58e3a--
.
Author: random.romik@gmail.com
Date: Tue, 25 Sep 2018 10:52:02 -0700 (PDT)
Raw View
------=_Part_2485_1149589954.1537897922499
Content-Type: multipart/alternative;
boundary="----=_Part_2486_409632890.1537897922499"
------=_Part_2486_409632890.1537897922499
Content-Type: text/plain; charset="UTF-8"
On Tuesday, September 25, 2018 at 10:37:22 AM UTC-7, Jake Arkinstall wrote:
>
> On Tue, 25 Sep 2018, 18:21 ,<rip...@gmail.com <javascript:>> wrote:
>
>> Currently we have to use old constructor member initializer list syntax,
>> if we need to pass parameters in run-time. This is less readable: member
>> initialization is separated from declaration.
>>
>
> This is a subjective claim. I find the initializer list approach more
> readable, from a structural point of view.
>
> The reason that we can use template arguments in member constructors is
> that the template argument is in scope and because template arguments are
> constexpr. That we can do this is completely logical, and that we can't do
> this with variables is also completely logical.
>
> The way I think about proposals is generally "how many confused posts is
> this going to generate on programming forums?". I think that, although your
> solution does go some way to solve a stylistic issue, it introduces some
> conceptual issues surrounding scope.
>
>
Thanks for feedback, good point. I agree that syntax perception is
subjective.
> For example, is "n" accessible elsewhere in the class - e.g. can it be
> referred to within a function? If not, why not? It's in scope after all,
> and not allowing it would be counter-intuitive to many people. If so,
> though, what is its behaviour when the value changes elsewhere? If it's a
> const reference, and the source variable is freed, what happens? How many
> people are going to add instances of this object to a container in a loop
> and wonder why they're getting memory access problems?
>
n should only be accessible in initializers, because in-class member
initializers are parts of object construction. This feels very intuitive to
me.
On the other side old syntax is sometimes not intuitive and error-prope :
consider for example -Wreorder related bugs.
--
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/d37ec4f7-57d1-4802-8549-e49fb5f620fc%40isocpp.org.
------=_Part_2486_409632890.1537897922499
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Tuesday, September 25, 2018 at 10:37:22 AM UTC-=
7, Jake Arkinstall wrote:<blockquote class=3D"gmail_quote" style=3D"margin:=
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div =
dir=3D"auto"><div class=3D"gmail_quote" dir=3D"auto"><div dir=3D"ltr">On Tu=
e, 25 Sep 2018, 18:21 ,<<a href=3D"javascript:" target=3D"_blank" gdf-ob=
fuscated-mailto=3D"zEusqWc-CwAJ" rel=3D"nofollow" onmousedown=3D"this.href=
=3D'javascript:';return true;" onclick=3D"this.href=3D'javascri=
pt:';return true;">rip...@gmail.com</a>> wrote:<br></div><blockquote=
class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc soli=
d;padding-left:1ex"><div dir=3D"ltr"><span><span style=3D"background-color:=
transparent;vertical-align:baseline"><span><span style=3D"background-color:=
transparent;vertical-align:baseline"><p dir=3D"ltr" style=3D"color:rgb(0,0,=
0);font-size:small;white-space:pre-wrap;font-family:arial,sans-serif;line-h=
eight:1.38">Currently we have to use old constructor member initializer lis=
t syntax, if we need to pass parameters in run-time. This is less readable:=
member initialization is separated from declaration.</p></span></span></sp=
an></span></div></blockquote></div><div dir=3D"auto"><br></div><div dir=3D"=
auto">This is a subjective claim. I find the initializer list approach more=
readable, from a structural point of view.</div><div dir=3D"auto"><br></di=
v><div dir=3D"auto">The reason that we can use template arguments in member=
constructors is that the template argument is in scope and because templat=
e arguments are constexpr. That we can do this is completely logical, and t=
hat we can't do this with variables is also completely logical.</div><d=
iv dir=3D"auto"><br></div><div dir=3D"auto"><span style=3D"font-family:sans=
-serif">The way I think about proposals is generally "how many confuse=
d posts is this going to generate on programming forums?". I think tha=
t, although your solution does go some way to solve a stylistic issue, it i=
ntroduces some conceptual issues surrounding scope.</span><br></div><div di=
r=3D"auto"><br></div></div></blockquote><div><br></div><div>=C2=A0Thanks fo=
r feedback, good point. I agree that syntax perception is subjective.<br></=
div><div>=C2=A0</div><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"auto"><div dir=3D"auto"></div><div dir=3D"auto">For example, is "n=
" accessible elsewhere in the class - e.g. can it be referred to withi=
n a function? If not, why not? It's in scope after all, and not allowin=
g it would be counter-intuitive to many people. If so, though, what is its =
behaviour when the value changes elsewhere? If it's a const reference, =
and the source variable is freed, what happens? How many people are going t=
o add instances of this object to a container in a loop and wonder why they=
're getting memory access problems?</div></div></blockquote><div><br></=
div><div>n should only be accessible in initializers, because in-class memb=
er initializers are parts of object construction. This feels very intuitive=
to me.</div><div><br></div><div>On the other side old syntax is sometimes =
not intuitive and error-prope : consider for example -Wreorder related bugs=
..</div><div><br></div><div>=C2=A0</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/d37ec4f7-57d1-4802-8549-e49fb5f620fc%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/d37ec4f7-57d1-4802-8549-e49fb5f620fc=
%40isocpp.org</a>.<br />
------=_Part_2486_409632890.1537897922499--
------=_Part_2485_1149589954.1537897922499--
.
Author: andrzejuk.robert@gmail.com
Date: Sat, 17 Nov 2018 12:15:06 -0800 (PST)
Raw View
------=_Part_1678_898302835.1542485706924
Content-Type: text/plain; charset="UTF-8"
Hello
I find initializer lists very helpful during debugging.
I am able to follow which variables are initialized and see the order in which the are initialized, all in one place.
With this type of initialization and variables thrown about in a large class, it may be hard to follow.
Regards
Robert
--
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/78b649a5-185b-4e7b-9e27-43b5c0758044%40isocpp.org.
------=_Part_1678_898302835.1542485706924--
.
Author: Balog Pal <pasa@lib.hu>
Date: Sat, 17 Nov 2018 15:31:59 -0800 (PST)
Raw View
------=_Part_1728_289904313.1542497519257
Content-Type: multipart/alternative;
boundary="----=_Part_1729_1831666915.1542497519258"
------=_Part_1729_1831666915.1542497519258
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
2018. szeptember 25., kedd 19:21:27 UTC+2 id=C5=91pontban rip...@gmail.com =
a=20
k=C3=B6vetkez=C5=91t =C3=ADrta:
>
> C++11 allows in-class member initialization. However, in-class=20
> initializers have no access to constructor parameters, which makes them=
=20
> useless in many scenarios.
>
Yes, the by-member initializers are there for the ctors not providing a=20
different initializer.
=20
> So essentially in this case C++ favors compile-time template interfaces=
=20
> over run-time constructor interfaces
>
> ???
C++ favors nothing, it provides tools for the initialization that are=20
pretty clear and usable for all use cases. You can state the common/default=
=20
value at the member, then make a series of ctors delegating to each other=
=20
for more sophisticated init. =20
Or for simple cases you can even use the aggregate-init, to just dump=20
values instead of having the ctor that sets up a proper state.
=20
> Currently we have to use old constructor member initializer list syntax,=
=20
> if we need to pass parameters in run-time. This is less readable: member=
=20
> initialization is separated from declaration.
>
As the means of setting up the state belongs to the implementation, it=20
looks fairly natural to me. Why should it appear at declaration? And how?=
=20
And if your shop believes it must appear inside the class, what stops you=
=20
to just order the ctors implemented inline?
*Possible solution: *
>
>
> Primary constructors (similar to Scala, Kotlin and abandoned C# proposal)
>
>
> We can designate one constructor as primary. Parameters of primary=20
> constructor should be visible to in-class initializers. All other=20
> constructors must call primary constructor in their constructor=20
> initialization list. Primary constructor is public by default.
>
This certainly CAN be done, but question remains whether the related=20
trouble in specification, implementation and code rearranging is worth the=
=20
result. You need to show up some evidence beyond that it is more appealing=
=20
to your aestetics. =20
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/8623f882-d191-4a10-b045-0e1823a38fab%40isocpp.or=
g.
------=_Part_1729_1831666915.1542497519258
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>2018. szeptember 25., kedd 19:21:27 UTC+2 id=C5=91=
pontban rip...@gmail.com a k=C3=B6vetkez=C5=91t =C3=ADrta:<blockquote class=
=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #cc=
c solid;padding-left: 1ex;"><div dir=3D"ltr"><span style=3D"background-colo=
r:transparent;vertical-align:baseline"><p dir=3D"ltr" style=3D"color:rgb(0,=
0,0);font-size:small;white-space:pre-wrap;font-family:arial,sans-serif;line=
-height:1.38"><span style=3D"background-color:transparent;vertical-align:ba=
seline">C++11 allows in-class member initialization. However, in-class init=
ializers have no access to constructor parameters, which makes them useless=
in many scenarios.</span></p></span></div></blockquote><div><br></div><div=
>Yes, the by-member initializers are there for the ctors not providing a di=
fferent initializer.<br></div><div>=C2=A0</div><blockquote class=3D"gmail_q=
uote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;pad=
ding-left: 1ex;"><div dir=3D"ltr"><div><span><div><span style=3D"background=
-color:transparent;vertical-align:baseline"><span><div><span style=3D"backg=
round-color:transparent;vertical-align:baseline"><p dir=3D"ltr" style=3D"co=
lor:rgb(0,0,0);font-size:small;white-space:pre-wrap;font-family:arial,sans-=
serif;line-height:1.38"><span style=3D"background-color:transparent;vertica=
l-align:baseline">So essentially in this case C++ favors compile-time templ=
ate interfaces over run-time constructor interfaces</span></p></span><span =
style=3D"background-color:transparent;vertical-align:baseline"><font style=
=3D"color:rgb(0,0,0);font-size:small;white-space:pre-wrap" face=3D"arial, s=
ans-serif"><br></font></span></div></span></span></div></span></div></div><=
/blockquote><div>???</div><div>C++ favors nothing, it provides tools for th=
e initialization that are pretty clear and usable for all use cases. You ca=
n state the common/default value at the member, then make a series of ctors=
delegating to each other for more sophisticated init.=C2=A0 <br></div><div=
><br></div><div>Or for simple cases you can even use the aggregate-init, to=
just dump values instead of having the ctor that sets up a proper state.<b=
r></div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:=
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div =
dir=3D"ltr"><div><span><div><span style=3D"background-color:transparent;ver=
tical-align:baseline"><span><div><span style=3D"background-color:transparen=
t;vertical-align:baseline"></span><span style=3D"background-color:transpare=
nt;vertical-align:baseline"><p dir=3D"ltr" style=3D"color:rgb(0,0,0);font-s=
ize:small;white-space:pre-wrap;font-family:arial,sans-serif;line-height:1.3=
8"><span style=3D"background-color:transparent;vertical-align:baseline">Cur=
rently we have to use old constructor member initializer list syntax, if we=
need to pass parameters in run-time. This is less readable: member initial=
ization is separated from declaration.</span></p></span></div></span></span=
></div></span></div></div></blockquote><div><span style=3D"background-color=
:transparent;vertical-align:baseline"><br></span></div><div><span style=3D"=
background-color:transparent;vertical-align:baseline">As the means of setti=
ng up the state belongs to the implementation, it looks fairly natural to m=
e. Why should it appear at declaration? And how? And if your shop believes =
it must appear inside the class, what stops you to just order the ctors imp=
lemented inline?<br></span></div><div><span style=3D"background-color:trans=
parent;vertical-align:baseline"><br></span></div><div><span style=3D"backgr=
ound-color:transparent;vertical-align:baseline"></span></div><blockquote cl=
ass=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px =
#ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><span><div><span style=
=3D"background-color:transparent;vertical-align:baseline"><span><div><span =
style=3D"background-color:transparent;vertical-align:baseline"><p dir=3D"lt=
r" style=3D"color:rgb(0,0,0);font-size:small;white-space:pre-wrap;font-fami=
ly:arial,sans-serif;line-height:1.38"><span style=3D"background-color:trans=
parent;vertical-align:baseline"><span></span></span></p><p dir=3D"ltr" styl=
e=3D"color:rgb(0,0,0);font-size:small;white-space:pre-wrap;font-family:aria=
l,sans-serif;line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=
=3D"color:rgb(0,0,0);background-color:transparent;font-style:normal;font-va=
riant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-w=
rap"><b>Possible solution: =C2=A0</b></span></p><p dir=3D"ltr" style=3D"col=
or:rgb(0,0,0);font-size:small;white-space:pre-wrap;font-family:arial,sans-s=
erif;line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"colo=
r:rgb(0,0,0);background-color:transparent;font-weight:400;font-style:normal=
;font-variant:normal;text-decoration:none;vertical-align:baseline;white-spa=
ce:pre-wrap"><br></span></p><p dir=3D"ltr" style=3D"color:rgb(0,0,0);font-s=
ize:small;white-space:pre-wrap;font-family:arial,sans-serif;line-height:1.3=
8;margin-top:0pt;margin-bottom:0pt"><span style=3D"color:rgb(0,0,0);backgro=
und-color:transparent;font-weight:400;font-style:normal;font-variant:normal=
;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">Primary=
constructors (similar to Scala, Kotlin and abandoned C# proposal)</span></=
p><p dir=3D"ltr" style=3D"color:rgb(0,0,0);font-size:small;white-space:pre-=
wrap;font-family:arial,sans-serif;line-height:1.38;margin-top:0pt;margin-bo=
ttom:0pt"><span style=3D"color:rgb(0,0,0);background-color:transparent;font=
-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vert=
ical-align:baseline;white-space:pre-wrap"><b style=3D"font-weight:normal"><=
br></b></span></p><p dir=3D"ltr" style=3D"color:rgb(0,0,0);font-size:small;=
white-space:pre-wrap;font-family:arial,sans-serif;line-height:1.38;margin-t=
op:0pt;margin-bottom:0pt"><span style=3D"color:rgb(0,0,0);background-color:=
transparent;font-weight:400;font-style:normal;font-variant:normal;text-deco=
ration:none;vertical-align:baseline;white-space:pre-wrap">We can designate =
one constructor as primary. Parameters of primary constructor should be vis=
ible to in-class initializers. All other constructors must call primary con=
structor in their constructor initialization list. Primary constructor is p=
ublic by default.</span></p></span></div></span></span></div></span></div><=
/div></blockquote><div><br></div><div>This certainly CAN be done, but quest=
ion remains whether the related trouble in specification, implementation an=
d code rearranging is worth the result. You need to show up some evidence b=
eyond that it is more appealing to your aestetics.=C2=A0=C2=A0 <br></div><d=
iv><br></div><br></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/8623f882-d191-4a10-b045-0e1823a38fab%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/8623f882-d191-4a10-b045-0e1823a38fab=
%40isocpp.org</a>.<br />
------=_Part_1729_1831666915.1542497519258--
------=_Part_1728_289904313.1542497519257--
.
Author: =?UTF-8?Q?=27Thomas_K=C3=B6ppe=27_via_ISO_C=2B=2B_Standard_=2D_Future_Proposals?= <std-proposals@isocpp.org>
Date: Sat, 17 Nov 2018 16:19:15 -0800 (PST)
Raw View
------=_Part_1719_1870120074.1542500355862
Content-Type: multipart/alternative;
boundary="----=_Part_1720_258910137.1542500355862"
------=_Part_1720_258910137.1542500355862
Content-Type: text/plain; charset="UTF-8"
On Tuesday, 25 September 2018 18:21:27 UTC+1, rip...@gmail.com wrote:
>
> Currently we have to use old constructor member initializer list syntax,
> if we need to pass parameters in run-time. This is less readable: member
> initialization is separated from declaration.
>
I'm not sure this point has universal agreement. To me, readability is
about effective communication and minimizing the mental load on the reader.
Important considerations are (in some vague order desirability) that code
can be read in a single pass (i.e. earlier information should not need
revision due to later information), that information isn't ambiguous (=
could mean multiple things that are in scope), that I don't have to guess
(= information is missing), or that if I have to guess I don't guess wrong
(e.g. don't choose outright misleading names).
For non-static member initialization, I take that to mean that I only want
to use default member initializers if *every* constructor initializes the
member to the same value. If any constructor chooses a different initial
value than another constructor, then that member should appear in every
constructor's initializer list. (Defaulted special members don't interfere
with this.) In other words, I only want to see *one* initialization of the
member, and I don't want to see information that I later need to overwrite
in my mind or ignore.
For that reason, I don't find the proposed extension particularly helpful.
There's nothing "old" about the existing initalizer list syntax that
requires its replacement with something "new", just like "int" isn't an
"old" type that needs to be replaced. It does what it does, and when that's
the thing you want to do, then it's perfectly appropriate.
--
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/356afa59-d771-46df-b9d2-209c064bc9be%40isocpp.org.
------=_Part_1720_258910137.1542500355862
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, 25 September 2018 18:21:27 UTC+1, rip...@gmail=
..com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-lef=
t: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><=
div><span><div><span style=3D"background-color:transparent;vertical-align:b=
aseline"><span><div><span style=3D"background-color:transparent;vertical-al=
ign:baseline"><p dir=3D"ltr" style=3D"color:rgb(0,0,0);font-size:small;whit=
e-space:pre-wrap;font-family:arial,sans-serif;line-height:1.38"><span style=
=3D"background-color:transparent;vertical-align:baseline">Currently we have=
to use old constructor member initializer list syntax, if we need to pass =
parameters in run-time. This is less readable: member initialization is sep=
arated from declaration.</span></p></span></div></span></span></div></span>=
</div></div></blockquote><div><br></div><div>I'm not sure this point ha=
s universal agreement. To me, readability is about effective communication =
and minimizing the mental load on the reader. Important considerations are =
(in some vague order desirability) that code can be read in a single pass (=
i.e. earlier information should not need revision due to later information)=
, that information isn't ambiguous (=3D could mean multiple things that=
are in scope), that I don't have to guess (=3D information is missing)=
, or that if I have to guess I don't guess wrong (e.g. don't choose=
outright misleading names).</div><div><br></div><div>For non-static member=
initialization, I take that to mean that I only want to use default member=
initializers if <i>every</i> constructor initializes the member to the sam=
e value. If any constructor chooses a different initial value than another =
constructor, then that member should appear in every constructor's init=
ializer list. (Defaulted special members don't interfere with this.) In=
other words, I only want to see <i>one</i> initialization of the member, a=
nd I don't want to see information that I later need to overwrite in my=
mind or ignore.</div><div><br></div><div>For that reason, I don't find=
the proposed extension particularly helpful. There's nothing "old=
" about the existing initalizer list syntax that requires its replacem=
ent with something "new", just like "int" isn't an =
"old" type that needs to be replaced. It does what it does, and w=
hen that's the thing you want to do, then it's perfectly appropriat=
e.</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/356afa59-d771-46df-b9d2-209c064bc9be%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/356afa59-d771-46df-b9d2-209c064bc9be=
%40isocpp.org</a>.<br />
------=_Part_1720_258910137.1542500355862--
------=_Part_1719_1870120074.1542500355862--
.
Author: Roman Popov <ripopov@gmail.com>
Date: Sat, 17 Nov 2018 19:27:24 -0800
Raw View
--0000000000004cc767057ae7fb19
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Well, I've already understood that no one in C++ community likes this
syntax. And obviously C++ way of separating declarations and definitions
dictates against it.
Personally I would like to have something like this for DSL construction,
and it looks very concise in Scala, but luckily many problems with C++ can
be solved with macros, and hopefully soon with metaclasses.
=D1=81=D0=B1, 17 =D0=BD=D0=BE=D1=8F=D0=B1. 2018 =D0=B3. =D0=B2 16:19, Thoma=
s K=C3=B6ppe <tkoeppe@google.com>:
> On Tuesday, 25 September 2018 18:21:27 UTC+1, rip...@gmail.com wrote:
>>
>> Currently we have to use old constructor member initializer list syntax,
>> if we need to pass parameters in run-time. This is less readable: member
>> initialization is separated from declaration.
>>
>
> I'm not sure this point has universal agreement. To me, readability is
> about effective communication and minimizing the mental load on the reade=
r.
> Important considerations are (in some vague order desirability) that code
> can be read in a single pass (i.e. earlier information should not need
> revision due to later information), that information isn't ambiguous (=3D
> could mean multiple things that are in scope), that I don't have to guess
> (=3D information is missing), or that if I have to guess I don't guess wr=
ong
> (e.g. don't choose outright misleading names).
>
> For non-static member initialization, I take that to mean that I only wan=
t
> to use default member initializers if *every* constructor initializes the
> member to the same value. If any constructor chooses a different initial
> value than another constructor, then that member should appear in every
> constructor's initializer list. (Defaulted special members don't interfer=
e
> with this.) In other words, I only want to see *one* initialization of
> the member, and I don't want to see information that I later need to
> overwrite in my mind or ignore.
>
> For that reason, I don't find the proposed extension particularly helpful=
..
> There's nothing "old" about the existing initalizer list syntax that
> requires its replacement with something "new", just like "int" isn't an
> "old" type that needs to be replaced. It does what it does, and when that=
's
> the thing you want to do, then it's perfectly appropriate.
>
--=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/CAATAM3F-58jMZP_2jeSrSCnUCVTwBPhoGko58o4oYOPpODX=
p%3DA%40mail.gmail.com.
--0000000000004cc767057ae7fb19
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"auto"><div dir=3D"ltr">Well, I've already understood that n=
o one in C++ community likes this syntax. And obviously C++ way of separati=
ng declarations and definitions dictates against it.</div><div dir=3D"ltr">=
Personally I would like to have something like this for DSL construction, a=
nd it looks very concise in Scala, but luckily many problems with C++ can b=
e solved with macros, and hopefully soon with metaclasses.</div><div dir=3D=
"ltr"><div dir=3D"auto"><br></div></div><br><div class=3D"gmail_quote"><div=
dir=3D"ltr">=D1=81=D0=B1, 17 =D0=BD=D0=BE=D1=8F=D0=B1. 2018 =D0=B3. =D0=B2=
16:19, Thomas K=C3=B6ppe <<a href=3D"mailto:tkoeppe@google.com" target=
=3D"_blank" rel=3D"noreferrer">tkoeppe@google.com</a>>:<br></div><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">On Tuesday, 25 September 2018 18:2=
1:27 UTC+1, <a href=3D"mailto:rip...@gmail.com" target=3D"_blank" rel=3D"no=
referrer">rip...@gmail.com</a> wrote:<blockquote class=3D"gmail_quote" sty=
le=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1e=
x"><div dir=3D"ltr"><div><span><div><span style=3D"background-color:transpa=
rent;vertical-align:baseline"><span><div><span style=3D"background-color:tr=
ansparent;vertical-align:baseline"><p dir=3D"ltr" style=3D"color:rgb(0,0,0)=
;font-size:small;white-space:pre-wrap;font-family:arial,sans-serif;line-hei=
ght:1.38"><span style=3D"background-color:transparent;vertical-align:baseli=
ne">Currently we have to use old constructor member initializer list syntax=
, if we need to pass parameters in run-time. This is less readable: member =
initialization is separated from declaration.</span></p></span></div></span=
></span></div></span></div></div></blockquote><div><br></div><div>I'm n=
ot sure this point has universal agreement. To me, readability is about eff=
ective communication and minimizing the mental load on the reader. Importan=
t considerations are (in some vague order desirability) that code can be re=
ad in a single pass (i.e. earlier information should not need revision due =
to later information), that information isn't ambiguous (=3D could mean=
multiple things that are in scope), that I don't have to guess (=3D in=
formation is missing), or that if I have to guess I don't guess wrong (=
e.g. don't choose outright misleading names).</div><div><br></div><div>=
For non-static member initialization, I take that to mean that I only want =
to use default member initializers if <i>every</i> constructor initializes =
the member to the same value. If any constructor chooses a different initia=
l value than another constructor, then that member should appear in every c=
onstructor's initializer list. (Defaulted special members don't int=
erfere with this.) In other words, I only want to see <i>one</i> initializa=
tion of the member, and I don't want to see information that I later ne=
ed to overwrite in my mind or ignore.</div><div><br></div><div>For that rea=
son, I don't find the proposed extension particularly helpful. There=
9;s nothing "old" about the existing initalizer list syntax that =
requires its replacement with something "new", just like "in=
t" isn't an "old" type that needs to be replaced. It doe=
s what it does, and when that's the thing you want to do, then it's=
perfectly appropriate.</div></div></blockquote></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAATAM3F-58jMZP_2jeSrSCnUCVTwBPhoGko5=
8o4oYOPpODXp%3DA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAATAM3F-58jMZP=
_2jeSrSCnUCVTwBPhoGko58o4oYOPpODXp%3DA%40mail.gmail.com</a>.<br />
--0000000000004cc767057ae7fb19--
.