Topic: A more consistent variable declaration syntax
Author: Andy Prowl <andy.prowl@gmail.com>
Date: Tue, 9 Dec 2014 14:15:52 -0800 (PST)
Raw View
------=_Part_3386_884912300.1418163352703
Content-Type: multipart/alternative;
boundary="----=_Part_3387_1396770625.1418163352703"
------=_Part_3387_1396770625.1418163352703
Content-Type: text/plain; charset=UTF-8
Hello,
I would like to get some feedback on my (perhaps slightly provocative)
thoughts about how to make C++'s variable declaration syntax more
consistent, so I can decide whether it is worth investing more time on it
or not.
Specifically, I believe the language would benefit from a declaration
syntax that provided:
1. *Consistency*: A uniform way of declaring/initializing *any* kind of
variable, be it a data member, a function parameter, a lambda capture, or a
regular (function-local or namespace-scope) variable;
2. *Universality*: Universal applicability regardless of whether the
variable's type is movable or not, and regardless of whether it is a simple
type (e.g. "int") or a compound type (e.g. "int*");
3. *Readability*: A left-to-right style that first introduces the name
of the entity, then its type (unless it is deduced), then the initializing
value (if needed). This is because the role and semantics of the entity
(which is communicated by its name) matter the most, so this information
should come first. Next should come the entity's properties: its type,
which defines what can be done with it, and the initializing expression,
which defines its initial state. As a minor side-effect, variable names
happen to be aligned, improving readability.
Herb Sutter's AAA style pushes towards the direction of point 3) above, but
AAA style cannot be applied consistently and universally, thus failing to
satisfy points 1) and 2):
auto x = std::mutex{}; // Nope, not movable (and "auto&& x = std::mutex{};"
is an unelegant hack)
auto y = int*{foo()}; // Nope, the grammar forbids it
auto a = std::array<int, 500>{0}; // Potentially inefficient, hope for copy
elision
struct X
{
private:
auto z = int{42}; // Nope, not allowed for in-class initialization of
data members
public:
auto foo(int x) -> void; // Not allowed for function parameters
};
auto x = [w = y] { std::cout << w; }; // Not uniform, "auto" is implicit in
lambda captures
I would like to see C++ become simpler and more consistent in those areas
where that is possible. This is what I came up with:
<identifier> := [<type>] [{ [<expression>] }];
The identifier introduces the name of the entity. The type may be missing
and, if present, it may be "auto": in both cases the initializing
expression must be present, and the type of the variable is deduced from
the initializing expression. If the type is missing, then the curly braces
(but not the expression) may be omitted too. If the type is present and it
is not "auto", then the initializing expression may be omitted, in which
case the variable would be default-initialized. *Value-initialization* would
be achieved using empty braces. When an initializer is present, the
semantics is always the one of *direct-list-initialization*.
When declaring function parameters, the identifier would be optional too;
when the identifier is missing, the syntax reduces to the current one. In
agreement with the above syntax, default argument values could be specified
using curly braces (in addition to the current syntax that uses the equal
sign).
As an example:
s := 42; // Type "int" deduced from the initializer
t := auto{42}; // Same as above
x := std::mutex; // Default-constructed mutex
y := int*{foo()}; // Pointer to int initialized from foo()
w := int{}; // Value-initialized integer
v := int; // Default-initialized integer
a := std::array<int, 50>{0}; // Guaranteed efficient, no need for copy
elision
struct X
{
private:
z := int; // Non-static data member
w := std::string { "Hello" }; // Non-static data member with default
initializer
p := 42; // Non-static data member with default initializer and deduced
type "int"
public:
auto foo (x := int) -> void; // Function parameter without default
argument
auto bar (x := int { 42 }) -> void; // Function parameter with default
argument
};
x := [w := y] { std::cout << w; }; // Lambda capture with deduced type
auto fizz(x := auto) -> int; // Terse syntax as defined by Concepts TS
The ":=" token is an arbitrary choice and may not be the best one - I
wouldn't mind changing it, as long as the consistency and universality of
the syntax is preserved. Perhaps a more readable alternative would be to
use a single ":", but that may lead to confusion:
x : int { 42 }; // Declares variable "x"
x: int { 42 }; // Declares label "x", where temporary is instantiated.
Compilers could emit a warning, but we would still have two very similar
ways of writing two very different things, which I dislike. It would also
create confusion inside range-based "for" loops, where ":" is used to
separate the range from the iterating variable.
Please let me know your thoughts on this. Any kind of feedback is welcome.
Kind regards,
Andy
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_3387_1396770625.1418163352703
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hello,<br><br>I would like to get some feedback on my (per=
haps slightly provocative) thoughts about how to make C++'s variable declar=
ation syntax more consistent, so I can decide whether it is worth investing=
more time on it or not. <div><br></div><div>Specifically, I believe t=
he language would benefit from a declaration syntax that provided:<br><ol><=
li><b style=3D"font-size: 13px;">Consistency</b><span style=3D"font-size: 1=
3px;">: A uniform way of declaring/initializing </span><i style=3D"fon=
t-size: 13px;">any</i><span style=3D"font-size: 13px;"> kind of variab=
le, be it a data member, a function parameter, a lambda capture, or a regul=
ar (function-local or namespace-scope) variable;</span></li><li><b style=3D=
"font-size: 13px;">Universality</b><span style=3D"font-size: 13px;">: Unive=
rsal applicability regardless of whether the variable's type is movable or =
not, and regardless of whether it is a simple type (e.g. "int") or a compou=
nd type (e.g. "int*");</span></li><li><b style=3D"font-size: 13px;">Readabi=
lity</b><span style=3D"font-size: 13px;">: A left-to-right style that first=
introduces the name of the entity, then its type (unless it is deduced), t=
hen the initializing value (if needed). This is because </span><span s=
tyle=3D"font-size: 13px;">the role and semantics of the entity (which is co=
mmunicated by its name) matter the most, so this information should come fi=
rst. Next should come the entity's properties: its type, which defines what=
can be done with it, and the initializing expression, which defines its in=
itial state. As a minor side-effect, variable names happen to be aligned, i=
mproving readability.</span></li></ol><div>Herb Sutter's AAA style pushes t=
owards the direction of point 3) above, but AAA style cannot be applied con=
sistently and universally, thus failing to satisfy points 1) and 2):<br><br=
><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); =
word-wrap: break-word; background-color: rgb(250, 250, 250);"><code 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"sty=
led-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> std</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">mute=
x</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">// Nope, not movable (and=
"auto&& x =3D std::mutex{};" is an unelegant hack)</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"=
color: #008;" class=3D"styled-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-prettify">=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">int</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">*{</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
foo</span><span style=3D"color: #660;" class=3D"styled-by-prettify">()};</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #800;" class=3D"styled-by-prettify">// Nope, the gra=
mmar forbids it</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">a=
uto</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> a </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"> std</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">array</span><span style=3D"color: #=
660;" 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"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-pret=
tify">500</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
gt;{</span><span style=3D"color: #066;" class=3D"styled-by-prettify">0</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 style=3D"=
color: #800;" class=3D"styled-by-prettify">// Potentially inefficient, hope=
for copy elision</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">struct</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> X<br></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: #008;" class=3D"styled-by-prettify">private</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br> </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> z </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: #008;" cla=
ss=3D"styled-by-prettify">int</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">{</span><span style=3D"color: #066;" class=3D"styled-by-=
prettify">42</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #800;" class=3D"styled-by-prettify">// Nope, not al=
lowed for in-class initialization of data members</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">public</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: #008;" c=
lass=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> foo</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">(</span><font color=3D"#000088" style=3D"font-size: 13.33=
33330154419px;"><span style=3D"color: #008;" class=3D"styled-by-prettify">i=
nt</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> x</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">)</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"> </span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">void</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #800;" class=3D"styled-by-prettif=
y">// Not allowed for function parameters</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"styled-by-prettify"><br><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=3D"st=
yled-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-pretti=
fy"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">[</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">w </span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> y</span><span style=3D"colo=
r: #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-b=
y-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">co=
ut </span><span style=3D"color: #660;" class=3D"styled-by-prettify"><<=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> w</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">;</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><span style=3D"color: #800;" class=
=3D"styled-by-prettify">// Not uniform, "auto" is implicit in lambda captur=
es</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></sp=
an><font color=3D"#000088"></font></div></code></div><br>I would like to se=
e C++ become simpler and more consistent in those areas where that is possi=
ble. This is what I came up with:<br><br><div class=3D"prettyprint" style=
=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; background=
-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"subp=
rettyprint"><font color=3D"#660066"><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify"><identifier></span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> :=3D [</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify"><type></span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">] [{ [</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify"><expression></span><span style=3D"color: #000=
;" class=3D"styled-by-prettify">] }];</span></font></div></code></div><br>T=
he identifier introduces the name of the entity. The type may be missing an=
d, if present, it may be "auto": in both cases the initializing expression =
must be present, and the type of the variable is deduced from the initializ=
ing expression. If the type is missing, then the curly braces (but not the =
expression) may be omitted too. <span style=3D"font-size: 13px;">If th=
e type is present and it is not "auto", then the initializing expression ma=
y be omitted, in which case the variable would be default-initialized. <i>V=
alue-initialization</i> would be achieved using empty braces. </s=
pan><span style=3D"font-size: 13px;">When an initializer is present, the se=
mantics is always the one of <i>direct-list-initialization</i>.</span></div=
><div> <br>When declaring function parameters, the identifier would be=
optional too; when the identifier is missing, the syntax reduces to the cu=
rrent one. In agreement with the above syntax, default argument values coul=
d be specified using curly braces (in addition to the current syntax that u=
ses the equal sign).<br><br>As an example:<br><br><div class=3D"prettyprint=
" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; bac=
kground-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">s </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: #066;" class=3D"styled-by-prettify">42</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: #800;" =
class=3D"styled-by-prettify">// Type "int" deduced from the initializer</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>t </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">:=3D</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #066;" cl=
ass=3D"styled-by-prettify">42</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=
">// Same as above</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br>x </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">:=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> s=
td</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">mutex</span><spa=
n 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=
: #800;" class=3D"styled-by-prettify">// Default-constructed mutex</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br>y </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=
: #008;" class=3D"styled-by-prettify">int</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">*{</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">foo</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">()};</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify=
">// Pointer to int initialized from foo()</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br>w </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">:=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">int</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">{};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">// Value=
-initialized integer</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br>v </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: #008;" class=3D"styled-by-prettify">int</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #800;" class=3D"styled-by-prettify">// Default-initialized integer</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>a </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">:=3D</span><span s=
tyle=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">array</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify"><</span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">int</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettif=
y">50</span><span style=3D"color: #660;" class=3D"styled-by-prettify">>{=
</span><span style=3D"color: #066;" class=3D"styled-by-prettify">0</span><s=
pan style=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: #800;" class=3D"styled-by-prettify">// Guaranteed efficient, no need for=
copy elision</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>struct</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> X<=
br></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: #008;" class=3D"styled-by-prettify">private</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br> z </span><span s=
tyle=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=
: #008;" class=3D"styled-by-prettify">int</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: #800;" class=3D"style=
d-by-prettify">// Non-static data member</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"><br> w </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">:=3D</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> std</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">::</span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">string</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: #080;" class=3D"styled-by-prettify">"Hello"</sp=
an><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: #=
800;" class=3D"styled-by-prettify">// Non-static data member with default i=
nitializer</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br> p </span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">:=3D</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">42</s=
pan><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: #800;" class=3D"styled-by-prettify">// Non-static data member with =
default initializer and deduced type "int"</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">public</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">:</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> foo </span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">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><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">-></span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">void</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: #800;" class=3D"styled-by-prettify">// Func=
tion parameter without default argument</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br> </span><span style=3D"color:=
#008;" class=3D"styled-by-prettify">auto</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> bar </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify">x </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">:=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">int</s=
pan><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: #=
066;" class=3D"styled-by-prettify">42</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"st=
yled-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"> </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">void</span><s=
pan 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=
: #800;" class=3D"styled-by-prettify">// Function parameter with default ar=
gument</span><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"styled-by-prettify"><br><br>x </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">:=3D</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">[</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">w </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">:=3D</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> y</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"> std</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">cout </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify"><<</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> w</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"style=
d-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">//=
Lambda capture with deduced type</span><span style=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"color: #000;" class=3D"st=
yled-by-prettify"> fizz</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">x </span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</s=
pan><font color=3D"#000000"><span style=3D"color: #660;" class=3D"styled-by=
-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">-></span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">int</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: #800;" class=3D"styled-by-pr=
ettify">// Terse syntax as defined by Concepts TS</span></font><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></code></di=
v></div><div><br></div><div>The ":=3D" token is an arbitrary choice and may=
not be the best one - I wouldn't mind changing it, as long as the consiste=
ncy and universality of the syntax is preserved. Perhaps a more readable al=
ternative would be to use a single ":", but that may lead to confusion:<br>=
<br><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187=
); word-wrap: break-word; background-color: rgb(250, 250, 250);"><code clas=
s=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #000;=
" class=3D"styled-by-prettify">x </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">:</span><font color=3D"#000088"><span style=3D"colo=
r: #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"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">42<=
/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"> </span><span style=3D"color=
: #800;" class=3D"styled-by-prettify">// Declares variable "x"</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br>x</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">int</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-pret=
tify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">42<=
/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"> </span><span style=3D"color=
: #800;" class=3D"styled-by-prettify">// </span></font><span style=3D"color=
: rgb(136, 0, 0); font-size: 13.3333330154419px;"><span style=3D"color: #80=
0;" class=3D"styled-by-prettify">Declares</span></span><font color=3D"#0000=
88"><span style=3D"color: #800;" class=3D"styled-by-prettify"> label "x", w=
here temporary is instantiated.</span></font></div></code></div><br>Compile=
rs could emit a warning, but we would still have two very similar ways of w=
riting two very different things, which I dislike. It would also create con=
fusion inside range-based "for" loops, where ":" is used to separate the ra=
nge from the iterating variable.</div><div><br></div><div><span style=3D"fo=
nt-size: 13px;">Please let me know your thoughts on this. Any kind of feedb=
ack is welcome.</span><br></div><div><span style=3D"font-size: 13px;"><br><=
/span></div><div><span style=3D"font-size: 13px;">Kind regards,</span><br><=
/div><div><br>Andy<br></div></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_3387_1396770625.1418163352703--
------=_Part_3386_884912300.1418163352703--
.
Author: tomalak@gmail.com
Date: Tue, 9 Dec 2014 14:20:18 -0800 (PST)
Raw View
------=_Part_5913_649702312.1418163618814
Content-Type: multipart/alternative;
boundary="----=_Part_5914_1739896436.1418163618815"
------=_Part_5914_1739896436.1418163618815
Content-Type: text/plain; charset=UTF-8
I mostly like it in principle, Andy, but I feel it's "too late"; we
certainly don't need *yet another* declaration syntax. Heck we have too
many as it is.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_5914_1739896436.1418163618815
Content-Type: text/html; charset=UTF-8
<div dir="ltr">I mostly like it in principle, Andy, but I feel it's "too late"; we certainly don't need <i>yet another</i> declaration syntax. Heck we have too many as it is.</div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:std-proposals+unsubscribe@isocpp.org">std-proposals+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href="mailto:std-proposals@isocpp.org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href="http://groups.google.com/a/isocpp.org/group/std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/</a>.<br />
------=_Part_5914_1739896436.1418163618815--
------=_Part_5913_649702312.1418163618814--
.
Author: Richard Smith <richard@metafoo.co.uk>
Date: Tue, 9 Dec 2014 15:27:13 -0800
Raw View
--001a11c1c33c0ea9a00509d0e2ed
Content-Type: text/plain; charset=UTF-8
On Tue, Dec 9, 2014 at 2:15 PM, Andy Prowl <andy.prowl@gmail.com> wrote:
> Hello,
>
> I would like to get some feedback on my (perhaps slightly provocative)
> thoughts about how to make C++'s variable declaration syntax more
> consistent, so I can decide whether it is worth investing more time on it
> or not.
>
> Specifically, I believe the language would benefit from a declaration
> syntax that provided:
>
> 1. *Consistency*: A uniform way of declaring/initializing *any* kind
> of variable, be it a data member, a function parameter, a lambda capture,
> or a regular (function-local or namespace-scope) variable;
> 2. *Universality*: Universal applicability regardless of whether the
> variable's type is movable or not, and regardless of whether it is a simple
> type (e.g. "int") or a compound type (e.g. "int*");
> 3. *Readability*: A left-to-right style that first introduces the name
> of the entity, then its type (unless it is deduced), then the initializing
> value (if needed). This is because the role and semantics of the
> entity (which is communicated by its name) matter the most, so this
> information should come first. Next should come the entity's properties:
> its type, which defines what can be done with it, and the initializing
> expression, which defines its initial state. As a minor side-effect,
> variable names happen to be aligned, improving readability.
>
> Herb Sutter's AAA style pushes towards the direction of point 3) above,
> but AAA style cannot be applied consistently and universally, thus failing
> to satisfy points 1) and 2):
>
> auto x = std::mutex{}; // Nope, not movable (and "auto&& x =
> std::mutex{};" is an unelegant hack)
>
We can make this work (essentially by making copy-elision mandatory). No
syntax change, no semantics change (in implementations that perform the
optimization), and you get a uniform syntax for variables.
>
> auto y = int*{foo()}; // Nope, the grammar forbids it
>
Use a typedef or a different kind of cast. Why would you be casting to a
pointer type in this way in the first place?
auto y = foo();
auto y = reinterpret_cast<int*>(foo());
> auto a = std::array<int, 500>{0}; // Potentially inefficient, hope for
> copy elision
>
> struct X
> {
> private:
> auto z = int{42}; // Nope, not allowed for in-class initialization of
> data members
> public:
> auto foo(int x) -> void; // Not allowed for function parameters
>
Neither of these cases declares a variable. The type is so important here
that deducing it would seldom be a good idea, even if it didn't have
order-of-translation issues.
> };
>
> auto x = [w = y] { std::cout << w; }; // Not uniform, "auto" is implicit
> in lambda captures
>
> I would like to see C++ become simpler and more consistent in those areas
> where that is possible. This is what I came up with:
>
> <identifier> := [<type>] [{ [<expression>] }];
>
I don't see how adding another syntax for a variable declaration makes the
language simpler or more consistent; it seems to do the opposite.
The identifier introduces the name of the entity. The type may be missing
> and, if present, it may be "auto": in both cases the initializing
> expression must be present, and the type of the variable is deduced from
> the initializing expression. If the type is missing, then the curly braces
> (but not the expression) may be omitted too. If the type is present and
> it is not "auto", then the initializing expression may be omitted, in which
> case the variable would be default-initialized. *Value-initialization* would
> be achieved using empty braces. When an initializer is present, the
> semantics is always the one of *direct-list-initialization*.
>
And what if I want non-list initialization? What if I want
copy-initialization? It seems like you'd need to also allow
<identifier> := [<type>] ( <expression-list> );
When declaring function parameters, the identifier would be optional too;
> when the identifier is missing, the syntax reduces to the current one. In
> agreement with the above syntax, default argument values could be specified
> using curly braces (in addition to the current syntax that uses the equal
> sign).
>
Again, there are reasons for restricting function parameter initialization
to copy-initialization. Changing syntax doesn't remove those reasons. I
think you're trying to change too much.
As an example:
>
> s := 42; // Type "int" deduced from the initializer
>
This is not allowed by your above formulation, and it reintroduces the risk
of vexing parses, assuming you allow non-list initialization. You'd need to
write
s := { 42 };
to satisfy your rules.
> t := auto{42}; // Same as above
> x := std::mutex; // Default-constructed mutex
> y := int*{foo()}; // Pointer to int initialized from foo()
> w := int{}; // Value-initialized integer
> v := int; // Default-initialized integer
> a := std::array<int, 50>{0}; // Guaranteed efficient, no need for copy
> elision
>
> struct X
> {
> private:
> z := int; // Non-static data member
> w := std::string { "Hello" }; // Non-static data member with default
> initializer
> p := 42; // Non-static data member with default initializer and
> deduced type "int"
> public:
> auto foo (x := int) -> void; // Function parameter without default
> argument
> auto bar (x := int { 42 }) -> void; // Function parameter with
> default argument
> };
>
> x := [w := y] { std::cout << w; }; // Lambda capture with deduced type
>
> auto fizz(x := auto) -> int; // Terse syntax as defined by Concepts TS
>
> The ":=" token is an arbitrary choice and may not be the best one - I
> wouldn't mind changing it, as long as the consistency and universality of
> the syntax is preserved. Perhaps a more readable alternative would be to
> use a single ":", but that may lead to confusion:
>
> x : int { 42 }; // Declares variable "x"
> x: int { 42 }; // Declares label "x", where temporary is instantiated.
>
These are both a label today. This kind of rule does not fit into C++'s
lexical model.
> Compilers could emit a warning, but we would still have two very similar
> ways of writing two very different things, which I dislike. It would also
> create confusion inside range-based "for" loops, where ":" is used to
> separate the range from the iterating variable.
>
> Please let me know your thoughts on this. Any kind of feedback is welcome.
>
> Kind regards,
>
> Andy
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--001a11c1c33c0ea9a00509d0e2ed
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On T=
ue, Dec 9, 2014 at 2:15 PM, Andy Prowl <span dir=3D"ltr"><<a href=3D"mai=
lto:andy.prowl@gmail.com" target=3D"_blank">andy.prowl@gmail.com</a>></s=
pan> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0p=
x 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-lef=
t-style:solid;padding-left:1ex"><div dir=3D"ltr">Hello,<br><br>I would like=
to get some feedback on my (perhaps slightly provocative) thoughts about h=
ow to make C++'s variable declaration syntax more consistent, so I can =
decide whether it is worth investing more time on it or not.=C2=A0<div><br>=
</div><div>Specifically, I believe the language would benefit from a declar=
ation syntax that provided:<br><ol><li><b style=3D"font-size:13px">Consiste=
ncy</b><span style=3D"font-size:13px">: A uniform way of declaring/initiali=
zing=C2=A0</span><i style=3D"font-size:13px">any</i><span style=3D"font-siz=
e:13px">=C2=A0kind of variable, be it a data member, a function parameter, =
a lambda capture, or a regular (function-local or namespace-scope) variable=
;</span></li><li><b style=3D"font-size:13px">Universality</b><span style=3D=
"font-size:13px">: Universal applicability regardless of whether the variab=
le's type is movable or not, and regardless of whether it is a simple t=
ype (e.g. "int") or a compound type (e.g. "int*");</spa=
n></li><li><b style=3D"font-size:13px">Readability</b><span style=3D"font-s=
ize:13px">: A left-to-right style that first introduces the name of the ent=
ity, then its type (unless it is deduced), then the initializing value (if =
needed). This is because=C2=A0</span><span style=3D"font-size:13px">the rol=
e and semantics of the entity (which is communicated by its name) matter th=
e most, so this information should come first. Next should come the entity&=
#39;s properties: its type, which defines what can be done with it, and the=
initializing expression, which defines its initial state. As a minor side-=
effect, variable names happen to be aligned, improving readability.</span><=
/li></ol><div>Herb Sutter's AAA style pushes towards the direction of p=
oint 3) above, but AAA style cannot be applied consistently and universally=
, thus failing to satisfy points 1) and 2):<br><br><div style=3D"border:1px=
solid rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,250,2=
50)"><code><div><span style=3D"color:rgb(0,0,136)">auto</span><span style=
=3D"color:rgb(0,0,0)"> x </span><span style=3D"color:rgb(102,102,0)">=3D</s=
pan><span style=3D"color:rgb(0,0,0)"> std</span><span style=3D"color:rgb(10=
2,102,0)">::</span><span style=3D"color:rgb(0,0,0)">mutex</span><span style=
=3D"color:rgb(102,102,0)">{};</span><span style=3D"color:rgb(0,0,0)"> </spa=
n><span style=3D"color:rgb(136,0,0)">// Nope, not movable (and "auto&a=
mp;& x =3D std::mutex{};" is an unelegant hack)</span></div></code=
></div></div></div></div></blockquote><div><br></div><div>We can make this =
work (essentially by making copy-elision mandatory). No syntax change, no s=
emantics change (in implementations that perform the optimization), and you=
get a uniform syntax for variables.</div><div>=C2=A0</div><blockquote clas=
s=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;b=
order-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"=
><div dir=3D"ltr"><div><div><div style=3D"border:1px solid rgb(187,187,187)=
;word-wrap:break-word;background-color:rgb(250,250,250)"><code><div><span s=
tyle=3D"color:rgb(0,0,0)"><br></span><span style=3D"color:rgb(0,0,136)">aut=
o</span><span style=3D"color:rgb(0,0,0)"> y </span><span style=3D"color:rgb=
(102,102,0)">=3D</span><span style=3D"color:rgb(0,0,0)"> </span><span style=
=3D"color:rgb(0,0,136)">int</span><span style=3D"color:rgb(102,102,0)">*{</=
span><span style=3D"color:rgb(0,0,0)">foo</span><span style=3D"color:rgb(10=
2,102,0)">()};</span><span style=3D"color:rgb(0,0,0)"> =C2=A0</span><span s=
tyle=3D"color:rgb(136,0,0)">// Nope, the grammar forbids it</span></div></c=
ode></div></div></div></div></blockquote><div><br></div><div>Use a typedef =
or a different kind of cast. Why would you be casting to a pointer type in =
this way in the first place?</div><div><br></div><div>auto y =3D foo();<br>=
</div><div><div>auto y =3D reinterpret_cast<int*>(foo());</div></div>=
<div><br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0p=
x 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-lef=
t-style:solid;padding-left:1ex"><div dir=3D"ltr"><div><div><div style=3D"bo=
rder:1px solid rgb(187,187,187);word-wrap:break-word;background-color:rgb(2=
50,250,250)"><code><div><span style=3D"color:rgb(0,0,0)"><br></span><span s=
tyle=3D"color:rgb(0,0,136)">auto</span><span style=3D"color:rgb(0,0,0)"> a =
</span><span style=3D"color:rgb(102,102,0)">=3D</span><span style=3D"color:=
rgb(0,0,0)"> std</span><span style=3D"color:rgb(102,102,0)">::</span><span =
style=3D"color:rgb(0,0,0)">array</span><span style=3D"color:rgb(102,102,0)"=
><</span><span style=3D"color:rgb(0,0,136)">int</span><span style=3D"col=
or:rgb(102,102,0)">,</span><span style=3D"color:rgb(0,0,0)"> </span><span s=
tyle=3D"color:rgb(0,102,102)">500</span><span style=3D"color:rgb(102,102,0)=
">>{</span><span style=3D"color:rgb(0,102,102)">0</span><span style=3D"c=
olor:rgb(102,102,0)">};</span><span style=3D"color:rgb(0,0,0)"> </span><spa=
n style=3D"color:rgb(136,0,0)">// Potentially inefficient, hope for copy el=
ision</span><span style=3D"color:rgb(0,0,0)"><br><br></span><span style=3D"=
color:rgb(0,0,136)">struct</span><span style=3D"color:rgb(0,0,0)"> X<br></s=
pan><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rgb(0=
,0,0)"><br></span><span style=3D"color:rgb(0,0,136)">private</span><span st=
yle=3D"color:rgb(102,102,0)">:</span><span style=3D"color:rgb(0,0,0)"><br>=
=C2=A0 =C2=A0 </span><span style=3D"color:rgb(0,0,136)">auto</span><span st=
yle=3D"color:rgb(0,0,0)"> z </span><span style=3D"color:rgb(102,102,0)">=3D=
</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,=
0,136)">int</span><span style=3D"color:rgb(102,102,0)">{</span><span style=
=3D"color:rgb(0,102,102)">42</span><span style=3D"color:rgb(102,102,0)">};<=
/span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(136=
,0,0)">// Nope, not allowed for in-class initialization of data members</sp=
an><span style=3D"color:rgb(0,0,0)"><br></span><span style=3D"color:rgb(0,0=
,136)">public</span><span style=3D"color:rgb(102,102,0)">:</span><span styl=
e=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 </span><span style=3D"color:rgb(0,=
0,136)">auto</span><span style=3D"color:rgb(0,0,0)"> foo</span><span style=
=3D"color:rgb(102,102,0)">(</span><font color=3D"#000088" style=3D"font-siz=
e:13.3333330154419px"><span style=3D"color:rgb(0,0,136)">int</span><span st=
yle=3D"color:rgb(0,0,0)"> x</span><span style=3D"color:rgb(102,102,0)">)</s=
pan><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,1=
02,0)">-></span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"=
color:rgb(0,0,136)">void</span><span style=3D"color:rgb(102,102,0)">;</span=
><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(136,0,0)=
">// Not allowed for function parameters</span></font></div></code></div></=
div></div></div></blockquote><div><br></div><div>Neither of these cases dec=
lares a variable. The type is so important here that deducing it would seld=
om be a good idea, even if it didn't have order-of-translation issues.<=
/div><div><br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0=
px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);borde=
r-left-style:solid;padding-left:1ex"><div dir=3D"ltr"><div><div><div style=
=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;background-color=
:rgb(250,250,250)"><code><div><span style=3D"color:rgb(0,0,0)"><br></span><=
span style=3D"color:rgb(102,102,0)">};</span><span style=3D"color:rgb(0,0,0=
)"><br><br></span><span style=3D"color:rgb(0,0,136)">auto</span><span style=
=3D"color:rgb(0,0,0)"> x </span><span style=3D"color:rgb(102,102,0)">=3D</s=
pan><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,1=
02,0)">[</span><span style=3D"color:rgb(0,0,0)">w </span><span style=3D"col=
or:rgb(102,102,0)">=3D</span><span style=3D"color:rgb(0,0,0)"> y</span><spa=
n style=3D"color:rgb(102,102,0)">]</span><span style=3D"color:rgb(0,0,0)"> =
</span><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rg=
b(0,0,0)"> std</span><span style=3D"color:rgb(102,102,0)">::</span><span st=
yle=3D"color:rgb(0,0,0)">cout </span><span style=3D"color:rgb(102,102,0)">&=
lt;<</span><span style=3D"color:rgb(0,0,0)"> w</span><span style=3D"colo=
r:rgb(102,102,0)">;</span><span style=3D"color:rgb(0,0,0)"> </span><span st=
yle=3D"color:rgb(102,102,0)">};</span><span style=3D"color:rgb(0,0,0)"> </s=
pan><span style=3D"color:rgb(136,0,0)">// Not uniform, "auto" is =
implicit in lambda captures</span><span style=3D"color:rgb(0,0,0)"><br></sp=
an><font color=3D"#000088"></font></div></code></div><br>I would like to se=
e C++ become simpler and more consistent in those areas where that is possi=
ble. This is what I came up with:<br><br><div style=3D"border:1px solid rgb=
(187,187,187);word-wrap:break-word;background-color:rgb(250,250,250)"><code=
><div><font color=3D"#660066"><span style=3D"color:rgb(0,0,136)"><identi=
fier></span><span style=3D"color:rgb(0,0,0)"> :=3D [</span><span style=
=3D"color:rgb(0,0,136)"><type></span><span style=3D"color:rgb(0,0,0)"=
>] [{ [</span><span style=3D"color:rgb(0,0,136)"><expression></span><=
span style=3D"color:rgb(0,0,0)">] }];</span></font></div></code></div></div=
></div></div></blockquote><div><br></div><div>I don't see how adding an=
other syntax for a variable declaration makes the language simpler or more =
consistent; it seems to do the opposite.</div><div><br></div><blockquote cl=
ass=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px=
;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1e=
x"><div dir=3D"ltr"><div><div>The identifier introduces the name of the ent=
ity. The type may be missing and, if present, it may be "auto": i=
n both cases the initializing expression must be present, and the type of t=
he variable is deduced from the initializing expression. If the type is mis=
sing, then the curly braces (but not the expression) may be omitted too.=C2=
=A0<span style=3D"font-size:13px">If the type is present and it is not &quo=
t;auto", then the initializing expression may be omitted, in which cas=
e the variable would be default-initialized. <i>Value-initialization</i>=C2=
=A0would be achieved using empty braces.=C2=A0</span><span style=3D"font-si=
ze:13px">When an initializer is present, the semantics is always the one of=
<i>direct-list-initialization</i>.</span></div></div></div></blockquote><d=
iv><br></div><div>And what if I want non-list initialization? What if I wan=
t copy-initialization? It seems like you'd need to also allow</div><div=
><br></div><div>=C2=A0 <identifier> :=3D [<type>] ( <express=
ion-list> );</div><div><br></div><blockquote class=3D"gmail_quote" style=
=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(20=
4,204,204);border-left-style:solid;padding-left:1ex"><div dir=3D"ltr"><div>=
<div>When declaring function parameters, the identifier would be optional t=
oo; when the identifier is missing, the syntax reduces to the current one. =
In agreement with the above syntax, default argument values could be specif=
ied using curly braces (in addition to the current syntax that uses the equ=
al sign).<br></div></div></div></blockquote><div><br></div><div>Again, ther=
e are reasons for restricting function parameter initialization to copy-ini=
tialization. Changing syntax doesn't remove those reasons. I think you&=
#39;re trying to change too much.</div><div><br></div><blockquote class=3D"=
gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border=
-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div=
dir=3D"ltr"><div><div>As an example:<br><br><div style=3D"border:1px solid=
rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,250,250)"><=
code><div><span style=3D"color:rgb(0,0,0)">s </span><span style=3D"color:rg=
b(102,102,0)">:=3D</span><span style=3D"color:rgb(0,0,0)"> </span><span sty=
le=3D"color:rgb(0,102,102)">42</span><span style=3D"color:rgb(102,102,0)">;=
</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(13=
6,0,0)">// Type "int" deduced from the initializer</span></div></=
code></div></div></div></div></blockquote><div><br></div><div>This is not a=
llowed by your above formulation, and it reintroduces the risk of vexing pa=
rses, assuming you allow non-list initialization. You'd need to write</=
div><div><br></div><div>=C2=A0 s :=3D { 42 };</div><div><br></div><div>to s=
atisfy your rules.</div><div><br></div><blockquote class=3D"gmail_quote" st=
yle=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb=
(204,204,204);border-left-style:solid;padding-left:1ex"><div dir=3D"ltr"><d=
iv><div><div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-wor=
d;background-color:rgb(250,250,250)"><code><div><span style=3D"color:rgb(0,=
0,0)"><br>t </span><span style=3D"color:rgb(102,102,0)">:=3D</span><span st=
yle=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">auto</s=
pan><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rgb(0=
,102,102)">42</span><span style=3D"color:rgb(102,102,0)">};</span><span sty=
le=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(136,0,0)">// Same =
as above</span><span style=3D"color:rgb(0,0,0)"><br>x </span><span style=3D=
"color:rgb(102,102,0)">:=3D</span><span style=3D"color:rgb(0,0,0)"> std</sp=
an><span style=3D"color:rgb(102,102,0)">::</span><span style=3D"color:rgb(0=
,0,0)">mutex</span><span style=3D"color:rgb(102,102,0)">;</span><span style=
=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(136,0,0)">// Default=
-constructed mutex</span><span style=3D"color:rgb(0,0,0)"><br>y </span><spa=
n style=3D"color:rgb(102,102,0)">:=3D</span><span style=3D"color:rgb(0,0,0)=
"> </span><span style=3D"color:rgb(0,0,136)">int</span><span style=3D"color=
:rgb(102,102,0)">*{</span><span style=3D"color:rgb(0,0,0)">foo</span><span =
style=3D"color:rgb(102,102,0)">()};</span><span style=3D"color:rgb(0,0,0)">=
</span><span style=3D"color:rgb(136,0,0)">// Pointer to int initialized fr=
om foo()</span><span style=3D"color:rgb(0,0,0)"><br>w </span><span style=3D=
"color:rgb(102,102,0)">:=3D</span><span style=3D"color:rgb(0,0,0)"> </span>=
<span style=3D"color:rgb(0,0,136)">int</span><span style=3D"color:rgb(102,1=
02,0)">{};</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"co=
lor:rgb(136,0,0)">// Value-initialized integer</span><span style=3D"color:r=
gb(0,0,0)"><br>v </span><span style=3D"color:rgb(102,102,0)">:=3D</span><sp=
an style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">in=
t</span><span style=3D"color:rgb(102,102,0)">;</span><span style=3D"color:r=
gb(0,0,0)"> </span><span style=3D"color:rgb(136,0,0)">// Default-initialize=
d integer</span><span style=3D"color:rgb(0,0,0)"><br>a </span><span style=
=3D"color:rgb(102,102,0)">:=3D</span><span style=3D"color:rgb(0,0,0)"> std<=
/span><span style=3D"color:rgb(102,102,0)">::</span><span style=3D"color:rg=
b(0,0,0)">array</span><span style=3D"color:rgb(102,102,0)"><</span><span=
style=3D"color:rgb(0,0,136)">int</span><span style=3D"color:rgb(102,102,0)=
">,</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb=
(0,102,102)">50</span><span style=3D"color:rgb(102,102,0)">>{</span><spa=
n style=3D"color:rgb(0,102,102)">0</span><span style=3D"color:rgb(102,102,0=
)">};</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:r=
gb(136,0,0)">// Guaranteed efficient, no need for copy elision</span><span =
style=3D"color:rgb(0,0,0)"><br><br></span><span style=3D"color:rgb(0,0,136)=
">struct</span><span style=3D"color:rgb(0,0,0)"> X<br></span><span style=3D=
"color:rgb(102,102,0)">{</span><span style=3D"color:rgb(0,0,0)"><br></span>=
<span style=3D"color:rgb(0,0,136)">private</span><span style=3D"color:rgb(1=
02,102,0)">:</span><span style=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 z </s=
pan><span style=3D"color:rgb(102,102,0)">:=3D</span><span style=3D"color:rg=
b(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">int</span><span style=
=3D"color:rgb(102,102,0)">;</span><span style=3D"color:rgb(0,0,0)"> </span>=
<span style=3D"color:rgb(136,0,0)">// Non-static data member</span><span st=
yle=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 w </span><span style=3D"color:rg=
b(102,102,0)">:=3D</span><span style=3D"color:rgb(0,0,0)"> std</span><span =
style=3D"color:rgb(102,102,0)">::</span><span style=3D"color:rgb(0,0,136)">=
string</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:=
rgb(102,102,0)">{</span><span style=3D"color:rgb(0,0,0)"> </span><span styl=
e=3D"color:rgb(0,136,0)">"Hello"</span><span style=3D"color:rgb(0=
,0,0)"> </span><span style=3D"color:rgb(102,102,0)">};</span><span style=3D=
"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(136,0,0)">// Non-static=
data member with default initializer</span><span style=3D"color:rgb(0,0,0)=
"><br>=C2=A0 =C2=A0 p </span><span style=3D"color:rgb(102,102,0)">:=3D</spa=
n><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,102,1=
02)">42</span><span style=3D"color:rgb(102,102,0)">;</span><span style=3D"c=
olor:rgb(0,0,0)"> </span><span style=3D"color:rgb(136,0,0)">// Non-static d=
ata member with default initializer and deduced type "int"</span>=
<span style=3D"color:rgb(0,0,0)"><br></span><span style=3D"color:rgb(0,0,13=
6)">public</span><span style=3D"color:rgb(102,102,0)">:</span><span style=
=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 </span><span style=3D"color:rgb(0,0=
,136)">auto</span><span style=3D"color:rgb(0,0,0)"> foo </span><span style=
=3D"color:rgb(102,102,0)">(</span><span style=3D"color:rgb(0,0,0)">x </span=
><span style=3D"color:rgb(102,102,0)">:=3D</span><span style=3D"color:rgb(0=
,0,0)"> </span><span style=3D"color:rgb(0,0,136)">int</span><span style=3D"=
color:rgb(102,102,0)">)</span><span style=3D"color:rgb(0,0,0)"> </span><spa=
n style=3D"color:rgb(102,102,0)">-></span><span style=3D"color:rgb(0,0,0=
)"> </span><span style=3D"color:rgb(0,0,136)">void</span><span style=3D"col=
or:rgb(102,102,0)">;</span><span style=3D"color:rgb(0,0,0)"> </span><span s=
tyle=3D"color:rgb(136,0,0)">// Function parameter without default argument<=
/span><span style=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 </span><span style=
=3D"color:rgb(0,0,136)">auto</span><span style=3D"color:rgb(0,0,0)"> bar </=
span><span style=3D"color:rgb(102,102,0)">(</span><span style=3D"color:rgb(=
0,0,0)">x </span><span style=3D"color:rgb(102,102,0)">:=3D</span><span styl=
e=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">int</span=
><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,=
0)">{</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:r=
gb(0,102,102)">42</span><span style=3D"color:rgb(0,0,0)"> </span><span styl=
e=3D"color:rgb(102,102,0)">})</span><span style=3D"color:rgb(0,0,0)"> </spa=
n><span style=3D"color:rgb(102,102,0)">-></span><span style=3D"color:rgb=
(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">void</span><span style=
=3D"color:rgb(102,102,0)">;</span><span style=3D"color:rgb(0,0,0)"> </span>=
<span style=3D"color:rgb(136,0,0)">// Function parameter with default argum=
ent</span><span style=3D"color:rgb(0,0,0)"><br></span><span style=3D"color:=
rgb(102,102,0)">};</span><span style=3D"color:rgb(0,0,0)"><br><br>x </span>=
<span style=3D"color:rgb(102,102,0)">:=3D</span><span style=3D"color:rgb(0,=
0,0)"> </span><span style=3D"color:rgb(102,102,0)">[</span><span style=3D"c=
olor:rgb(0,0,0)">w </span><span style=3D"color:rgb(102,102,0)">:=3D</span><=
span style=3D"color:rgb(0,0,0)"> y</span><span style=3D"color:rgb(102,102,0=
)">]</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rg=
b(102,102,0)">{</span><span style=3D"color:rgb(0,0,0)"> std</span><span sty=
le=3D"color:rgb(102,102,0)">::</span><span style=3D"color:rgb(0,0,0)">cout =
</span><span style=3D"color:rgb(102,102,0)"><<</span><span style=3D"c=
olor:rgb(0,0,0)"> w</span><span style=3D"color:rgb(102,102,0)">;</span><spa=
n style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">}=
;</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(1=
36,0,0)">// Lambda capture with deduced type</span><span style=3D"color:rgb=
(0,0,0)"><br><br></span><span style=3D"color:rgb(0,0,136)">auto</span><span=
style=3D"color:rgb(0,0,0)"> fizz</span><span style=3D"color:rgb(102,102,0)=
">(</span><span style=3D"color:rgb(0,0,0)">x </span><span style=3D"color:rg=
b(102,102,0)">:</span><font color=3D"#000000"><span style=3D"color:rgb(102,=
102,0)">=3D</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"c=
olor:rgb(0,0,136)">auto</span><span style=3D"color:rgb(102,102,0)">)</span>=
<span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0=
)">-></span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"colo=
r:rgb(0,0,136)">int</span><span style=3D"color:rgb(102,102,0)">;</span><spa=
n style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(136,0,0)">// =
Terse syntax as defined by Concepts TS</span></font><span style=3D"color:rg=
b(0,0,0)"><br></span></div></code></div></div><div><br></div><div>The "=
;:=3D" token is an arbitrary choice and may not be the best one - I wo=
uldn't mind changing it, as long as the consistency and universality of=
the syntax is preserved. Perhaps a more readable alternative would be to u=
se a single ":", but that may lead to confusion:<br><br><div styl=
e=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;background-colo=
r:rgb(250,250,250)"><code><div><span style=3D"color:rgb(0,0,0)">x </span><s=
pan style=3D"color:rgb(102,102,0)">:</span><font color=3D"#000088"><span st=
yle=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">int</sp=
an><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,10=
2,0)">{</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color=
:rgb(0,102,102)">42</span><span style=3D"color:rgb(0,0,0)"> </span><span st=
yle=3D"color:rgb(102,102,0)">};</span><span style=3D"color:rgb(0,0,0)"> </s=
pan><span style=3D"color:rgb(136,0,0)">// Declares variable "x"</=
span><span style=3D"color:rgb(0,0,0)"><br>x</span><span style=3D"color:rgb(=
102,102,0)">:</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D=
"color:rgb(0,0,136)">int</span><span style=3D"color:rgb(0,0,0)"> </span><sp=
an style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rgb(0,0,0)">=
</span><span style=3D"color:rgb(0,102,102)">42</span><span style=3D"color:=
rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">};</span><span sty=
le=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(136,0,0)">// </spa=
n></font><span style=3D"color:rgb(136,0,0);font-size:13.3333330154419px"><s=
pan style=3D"color:rgb(136,0,0)">Declares</span></span><font color=3D"#0000=
88"><span style=3D"color:rgb(136,0,0)"> label "x", where temporar=
y is instantiated.</span></font></div></code></div></div></div></div></bloc=
kquote><div><br></div><div>These are both a label today. This kind of rule =
does not fit into C++'s lexical model.</div><div>=C2=A0</div><blockquot=
e class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width=
:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-lef=
t:1ex"><div dir=3D"ltr"><div><div>Compilers could emit a warning, but we wo=
uld still have two very similar ways of writing two very different things, =
which I dislike. It would also create confusion inside range-based "fo=
r" loops, where ":" is used to separate the range from the i=
terating variable.</div><div><br></div><div><span style=3D"font-size:13px">=
Please let me know your thoughts on this. Any kind of feedback is welcome.<=
/span><br></div><div><span style=3D"font-size:13px"><br></span></div><div><=
span style=3D"font-size:13px">Kind regards,</span><br></div><div><br>Andy<s=
pan class=3D""><font color=3D"#888888"><br></font></span></div></div></div>=
<span class=3D""><font color=3D"#888888">
<p></p>
-- <br>
<br>
--- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</font></span></blockquote></div><br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--001a11c1c33c0ea9a00509d0e2ed--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 10 Dec 2014 01:30:55 +0200
Raw View
On 10 December 2014 at 01:27, Richard Smith <richard@metafoo.co.uk> wrote:
> On Tue, Dec 9, 2014 at 2:15 PM, Andy Prowl <andy.prowl@gmail.com> wrote:
>> struct X
>> {
>> private:
>> auto z = int{42}; // Nope, not allowed for in-class initialization of
>> data members
>> public:
>> auto foo(int x) -> void; // Not allowed for function parameters
>
>
> Neither of these cases declares a variable. The type is so important here
> that deducing it would seldom be a good idea, even if it didn't have
> order-of-translation issues.
See also
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Alisdair Meredith <alisdairm@icloud.com>
Date: Tue, 09 Dec 2014 14:04:11 -1000
Raw View
--Apple-Mail-BD2B5D5B-0D2A-4365-8E9D-C4FEB29C344A
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Is it time to consider making (N)RVO mandatory? Most implementations seem =
to have it, and making it mandatory rather than optional gives programs wit=
h predictable semantics.
(I typically run into this issue when writing test drivers where the behavi=
or of a returned copy is observable)
Sent from my iPhone
> On Dec 9, 2014, at 1:27 PM, Richard Smith <richard@metafoo.co.uk> wrote:
>=20
>> On Tue, Dec 9, 2014 at 2:15 PM, Andy Prowl <andy.prowl@gmail.com> wrote:
>> Hello,
>>=20
>> I would like to get some feedback on my (perhaps slightly provocative) t=
houghts about how to make C++'s variable declaration syntax more consistent=
, so I can decide whether it is worth investing more time on it or not.=20
>>=20
>> Specifically, I believe the language would benefit from a declaration sy=
ntax that provided:
>> Consistency: A uniform way of declaring/initializing any kind of variabl=
e, be it a data member, a function parameter, a lambda capture, or a regula=
r (function-local or namespace-scope) variable;
>> Universality: Universal applicability regardless of whether the variable=
's type is movable or not, and regardless of whether it is a simple type (e=
..g. "int") or a compound type (e.g. "int*");
>> Readability: A left-to-right style that first introduces the name of the=
entity, then its type (unless it is deduced), then the initializing value =
(if needed). This is because the role and semantics of the entity (which is=
communicated by its name) matter the most, so this information should come=
first. Next should come the entity's properties: its type, which defines w=
hat can be done with it, and the initializing expression, which defines its=
initial state. As a minor side-effect, variable names happen to be aligned=
, improving readability.
>> Herb Sutter's AAA style pushes towards the direction of point 3) above, =
but AAA style cannot be applied consistently and universally, thus failing =
to satisfy points 1) and 2):
>>=20
>> auto x =3D std::mutex{}; // Nope, not movable (and "auto&& x =3D std::mu=
tex{};" is an unelegant hack)
>=20
> We can make this work (essentially by making copy-elision mandatory). No =
syntax change, no semantics change (in implementations that perform the opt=
imization), and you get a uniform syntax for variables.
> =20
>>=20
>> auto y =3D int*{foo()}; // Nope, the grammar forbids it
>=20
> Use a typedef or a different kind of cast. Why would you be casting to a =
pointer type in this way in the first place?
>=20
> auto y =3D foo();
> auto y =3D reinterpret_cast<int*>(foo());
>=20
>>=20
>> auto a =3D std::array<int, 500>{0}; // Potentially inefficient, hope for=
copy elision
>>=20
>> struct X
>> {
>> private:
>> auto z =3D int{42}; // Nope, not allowed for in-class initialization=
of data members
>> public:
>> auto foo(int x) -> void; // Not allowed for function parameters
>=20
> Neither of these cases declares a variable. The type is so important here=
that deducing it would seldom be a good idea, even if it didn't have order=
-of-translation issues.
>=20
>>=20
>> };
>>=20
>> auto x =3D [w =3D y] { std::cout << w; }; // Not uniform, "auto" is impl=
icit in lambda captures
>>=20
>> I would like to see C++ become simpler and more consistent in those area=
s where that is possible. This is what I came up with:
>>=20
>> <identifier> :=3D [<type>] [{ [<expression>] }];
>=20
> I don't see how adding another syntax for a variable declaration makes th=
e language simpler or more consistent; it seems to do the opposite.
>=20
>> The identifier introduces the name of the entity. The type may be missin=
g and, if present, it may be "auto": in both cases the initializing express=
ion must be present, and the type of the variable is deduced from the initi=
alizing expression. If the type is missing, then the curly braces (but not =
the expression) may be omitted too. If the type is present and it is not "a=
uto", then the initializing expression may be omitted, in which case the va=
riable would be default-initialized. Value-initialization would be achieved=
using empty braces. When an initializer is present, the semantics is alway=
s the one of direct-list-initialization.
>=20
> And what if I want non-list initialization? What if I want copy-initializ=
ation? It seems like you'd need to also allow
>=20
> <identifier> :=3D [<type>] ( <expression-list> );
>=20
>> When declaring function parameters, the identifier would be optional too=
; when the identifier is missing, the syntax reduces to the current one. In=
agreement with the above syntax, default argument values could be specifie=
d using curly braces (in addition to the current syntax that uses the equal=
sign).
>=20
> Again, there are reasons for restricting function parameter initializatio=
n to copy-initialization. Changing syntax doesn't remove those reasons. I t=
hink you're trying to change too much.
>=20
>> As an example:
>>=20
>> s :=3D 42; // Type "int" deduced from the initializer
>=20
> This is not allowed by your above formulation, and it reintroduces the ri=
sk of vexing parses, assuming you allow non-list initialization. You'd need=
to write
>=20
> s :=3D { 42 };
>=20
> to satisfy your rules.
>=20
>>=20
>> t :=3D auto{42}; // Same as above
>> x :=3D std::mutex; // Default-constructed mutex
>> y :=3D int*{foo()}; // Pointer to int initialized from foo()
>> w :=3D int{}; // Value-initialized integer
>> v :=3D int; // Default-initialized integer
>> a :=3D std::array<int, 50>{0}; // Guaranteed efficient, no need for copy=
elision
>>=20
>> struct X
>> {
>> private:
>> z :=3D int; // Non-static data member
>> w :=3D std::string { "Hello" }; // Non-static data member with defau=
lt initializer
>> p :=3D 42; // Non-static data member with default initializer and de=
duced type "int"
>> public:
>> auto foo (x :=3D int) -> void; // Function parameter without default=
argument
>> auto bar (x :=3D int { 42 }) -> void; // Function parameter with def=
ault argument
>> };
>>=20
>> x :=3D [w :=3D y] { std::cout << w; }; // Lambda capture with deduced ty=
pe
>>=20
>> auto fizz(x :=3D auto) -> int; // Terse syntax as defined by Concepts TS
>>=20
>> The ":=3D" token is an arbitrary choice and may not be the best one - I =
wouldn't mind changing it, as long as the consistency and universality of t=
he syntax is preserved. Perhaps a more readable alternative would be to use=
a single ":", but that may lead to confusion:
>>=20
>> x : int { 42 }; // Declares variable "x"
>> x: int { 42 }; // Declares label "x", where temporary is instantiated.
>=20
> These are both a label today. This kind of rule does not fit into C++'s l=
exical model.
> =20
>> Compilers could emit a warning, but we would still have two very similar=
ways of writing two very different things, which I dislike. It would also =
create confusion inside range-based "for" loops, where ":" is used to separ=
ate the range from the iterating variable.
>>=20
>> Please let me know your thoughts on this. Any kind of feedback is welcom=
e.
>>=20
>> Kind regards,
>>=20
>> Andy
>> --=20
>>=20
>> ---=20
>> 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.
>> Visit this group at http://groups.google.com/a/isocpp.org/group/std-prop=
osals/.
>=20
> --=20
>=20
> ---=20
> You received this message because you are subscribed to the Google Groups=
"ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an=
email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at http://groups.google.com/a/isocpp.org/group/std-propo=
sals/.
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--Apple-Mail-BD2B5D5B-0D2A-4365-8E9D-C4FEB29C344A
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html><head><meta http-equiv=3D"content-type" content=3D"text/html; charset=
=3Dutf-8"></head><body dir=3D"auto"><div>Is it time to consider making (N)R=
VO mandatory? Most implementations seem to have it, and making it man=
datory rather than optional gives programs with predictable semantics.</div=
><div><br></div><div>(I typically run into this issue when writing test dri=
vers where the behavior of a returned copy is observable)<br><br>Sent from =
my iPhone</div><div><br>On Dec 9, 2014, at 1:27 PM, Richard Smith <<a hr=
ef=3D"mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>> wrote:<br=
><br></div><blockquote type=3D"cite"><div><div dir=3D"ltr"><div class=3D"gm=
ail_extra"><div class=3D"gmail_quote">On Tue, Dec 9, 2014 at 2:15 PM, Andy =
Prowl <span dir=3D"ltr"><<a href=3D"mailto:andy.prowl@gmail.com" target=
=3D"_blank">andy.prowl@gmail.com</a>></span> wrote:<br><blockquote class=
=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;bo=
rder-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">=
<div dir=3D"ltr">Hello,<br><br>I would like to get some feedback on my (per=
haps slightly provocative) thoughts about how to make C++'s variable declar=
ation syntax more consistent, so I can decide whether it is worth investing=
more time on it or not. <div><br></div><div>Specifically, I believe t=
he language would benefit from a declaration syntax that provided:<br><ol><=
li><b style=3D"font-size:13px">Consistency</b><span style=3D"font-size:13px=
">: A uniform way of declaring/initializing </span><i style=3D"font-si=
ze:13px">any</i><span style=3D"font-size:13px"> kind of variable, be i=
t a data member, a function parameter, a lambda capture, or a regular (func=
tion-local or namespace-scope) variable;</span></li><li><b style=3D"font-si=
ze:13px">Universality</b><span style=3D"font-size:13px">: Universal applica=
bility regardless of whether the variable's type is movable or not, and reg=
ardless of whether it is a simple type (e.g. "int") or a compound type (e.g=
.. "int*");</span></li><li><b style=3D"font-size:13px">Readability</b><span =
style=3D"font-size:13px">: A left-to-right style that first introduces the =
name of the entity, then its type (unless it is deduced), then the initiali=
zing value (if needed). This is because </span><span style=3D"font-siz=
e:13px">the role and semantics of the entity (which is communicated by its =
name) matter the most, so this information should come first. Next should c=
ome the entity's properties: its type, which defines what can be done with =
it, and the initializing expression, which defines its initial state. As a =
minor side-effect, variable names happen to be aligned, improving readabili=
ty.</span></li></ol><div>Herb Sutter's AAA style pushes towards the directi=
on of point 3) above, but AAA style cannot be applied consistently and univ=
ersally, thus failing to satisfy points 1) and 2):<br><br><div style=3D"bor=
der:1px solid rgb(187,187,187);word-wrap:break-word;background-color:rgb(25=
0,250,250)"><code><div><span style=3D"color:rgb(0,0,136)">auto</span><span =
style=3D"color:rgb(0,0,0)"> x </span><span style=3D"color:rgb(102,102,0)">=
=3D</span><span style=3D"color:rgb(0,0,0)"> std</span><span style=3D"color:=
rgb(102,102,0)">::</span><span style=3D"color:rgb(0,0,0)">mutex</span><span=
style=3D"color:rgb(102,102,0)">{};</span><span style=3D"color:rgb(0,0,0)">=
</span><span style=3D"color:rgb(136,0,0)">// Nope, not movable (and "auto&=
amp;& x =3D std::mutex{};" is an unelegant hack)</span></div></code></d=
iv></div></div></div></blockquote><div><br></div><div>We can make this work=
(essentially by making copy-elision mandatory). No syntax change, no seman=
tics change (in implementations that perform the optimization), and you get=
a uniform syntax for variables.</div><div> </div><blockquote class=3D=
"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;borde=
r-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><di=
v dir=3D"ltr"><div><div><div style=3D"border:1px solid rgb(187,187,187);wor=
d-wrap:break-word;background-color:rgb(250,250,250)"><code><div><span style=
=3D"color:rgb(0,0,0)"><br></span><span style=3D"color:rgb(0,0,136)">auto</s=
pan><span style=3D"color:rgb(0,0,0)"> y </span><span style=3D"color:rgb(102=
,102,0)">=3D</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"=
color:rgb(0,0,136)">int</span><span style=3D"color:rgb(102,102,0)">*{</span=
><span style=3D"color:rgb(0,0,0)">foo</span><span style=3D"color:rgb(102,10=
2,0)">()};</span><span style=3D"color:rgb(0,0,0)"> </span><span style=
=3D"color:rgb(136,0,0)">// Nope, the grammar forbids it</span></div></code>=
</div></div></div></div></blockquote><div><br></div><div>Use a typedef or a=
different kind of cast. Why would you be casting to a pointer type in this=
way in the first place?</div><div><br></div><div>auto y =3D foo();<br></di=
v><div><div>auto y =3D reinterpret_cast<int*>(foo());</div></div><div=
><br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.=
8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-st=
yle:solid;padding-left:1ex"><div dir=3D"ltr"><div><div><div style=3D"border=
:1px solid rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,2=
50,250)"><code><div><span style=3D"color:rgb(0,0,0)"><br></span><span style=
=3D"color:rgb(0,0,136)">auto</span><span style=3D"color:rgb(0,0,0)"> a </sp=
an><span style=3D"color:rgb(102,102,0)">=3D</span><span style=3D"color:rgb(=
0,0,0)"> std</span><span style=3D"color:rgb(102,102,0)">::</span><span styl=
e=3D"color:rgb(0,0,0)">array</span><span style=3D"color:rgb(102,102,0)"><=
;</span><span style=3D"color:rgb(0,0,136)">int</span><span style=3D"color:r=
gb(102,102,0)">,</span><span style=3D"color:rgb(0,0,0)"> </span><span style=
=3D"color:rgb(0,102,102)">500</span><span style=3D"color:rgb(102,102,0)">&g=
t;{</span><span style=3D"color:rgb(0,102,102)">0</span><span style=3D"color=
:rgb(102,102,0)">};</span><span style=3D"color:rgb(0,0,0)"> </span><span st=
yle=3D"color:rgb(136,0,0)">// Potentially inefficient, hope for copy elisio=
n</span><span style=3D"color:rgb(0,0,0)"><br><br></span><span style=3D"colo=
r:rgb(0,0,136)">struct</span><span style=3D"color:rgb(0,0,0)"> X<br></span>=
<span style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rgb(0,0,0=
)"><br></span><span style=3D"color:rgb(0,0,136)">private</span><span style=
=3D"color:rgb(102,102,0)">:</span><span style=3D"color:rgb(0,0,0)"><br>&nbs=
p; </span><span style=3D"color:rgb(0,0,136)">auto</span><span style=
=3D"color:rgb(0,0,0)"> z </span><span style=3D"color:rgb(102,102,0)">=3D</s=
pan><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,1=
36)">int</span><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"=
color:rgb(0,102,102)">42</span><span style=3D"color:rgb(102,102,0)">};</spa=
n><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(136,0,0=
)">// Nope, not allowed for in-class initialization of data members</span><=
span style=3D"color:rgb(0,0,0)"><br></span><span style=3D"color:rgb(0,0,136=
)">public</span><span style=3D"color:rgb(102,102,0)">:</span><span style=3D=
"color:rgb(0,0,0)"><br> </span><span style=3D"color:rgb(0,0,13=
6)">auto</span><span style=3D"color:rgb(0,0,0)"> foo</span><span style=3D"c=
olor:rgb(102,102,0)">(</span><font color=3D"#000088" style=3D"font-size:13.=
3333330154419px"><span style=3D"color:rgb(0,0,136)">int</span><span style=
=3D"color:rgb(0,0,0)"> x</span><span style=3D"color:rgb(102,102,0)">)</span=
><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,=
0)">-></span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"col=
or:rgb(0,0,136)">void</span><span style=3D"color:rgb(102,102,0)">;</span><s=
pan style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(136,0,0)">/=
/ Not allowed for function parameters</span></font></div></code></div></div=
></div></div></blockquote><div><br></div><div>Neither of these cases declar=
es a variable. The type is so important here that deducing it would seldom =
be a good idea, even if it didn't have order-of-translation issues.</div><d=
iv><br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px =
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-=
style:solid;padding-left:1ex"><div dir=3D"ltr"><div><div><div style=3D"bord=
er:1px solid rgb(187,187,187);word-wrap:break-word;background-color:rgb(250=
,250,250)"><code><div><span style=3D"color:rgb(0,0,0)"><br></span><span sty=
le=3D"color:rgb(102,102,0)">};</span><span style=3D"color:rgb(0,0,0)"><br><=
br></span><span style=3D"color:rgb(0,0,136)">auto</span><span style=3D"colo=
r:rgb(0,0,0)"> x </span><span style=3D"color:rgb(102,102,0)">=3D</span><spa=
n style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">[=
</span><span style=3D"color:rgb(0,0,0)">w </span><span style=3D"color:rgb(1=
02,102,0)">=3D</span><span style=3D"color:rgb(0,0,0)"> y</span><span style=
=3D"color:rgb(102,102,0)">]</span><span style=3D"color:rgb(0,0,0)"> </span>=
<span style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rgb(0,0,0=
)"> std</span><span style=3D"color:rgb(102,102,0)">::</span><span style=3D"=
color:rgb(0,0,0)">cout </span><span style=3D"color:rgb(102,102,0)"><<=
</span><span style=3D"color:rgb(0,0,0)"> w</span><span style=3D"color:rgb(1=
02,102,0)">;</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"=
color:rgb(102,102,0)">};</span><span style=3D"color:rgb(0,0,0)"> </span><sp=
an style=3D"color:rgb(136,0,0)">// Not uniform, "auto" is implicit in lambd=
a captures</span><span style=3D"color:rgb(0,0,0)"><br></span><font color=3D=
"#000088"></font></div></code></div><br>I would like to see C++ become simp=
ler and more consistent in those areas where that is possible. This is what=
I came up with:<br><br><div style=3D"border:1px solid rgb(187,187,187);wor=
d-wrap:break-word;background-color:rgb(250,250,250)"><code><div><font color=
=3D"#660066"><span style=3D"color:rgb(0,0,136)"><identifier></span><s=
pan style=3D"color:rgb(0,0,0)"> :=3D [</span><span style=3D"color:rgb(0,0,1=
36)"><type></span><span style=3D"color:rgb(0,0,0)">] [{ [</span><span=
style=3D"color:rgb(0,0,136)"><expression></span><span style=3D"color=
:rgb(0,0,0)">] }];</span></font></div></code></div></div></div></div></bloc=
kquote><div><br></div><div>I don't see how adding another syntax for a vari=
able declaration makes the language simpler or more consistent; it seems to=
do the opposite.</div><div><br></div><blockquote class=3D"gmail_quote" sty=
le=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(=
204,204,204);border-left-style:solid;padding-left:1ex"><div dir=3D"ltr"><di=
v><div>The identifier introduces the name of the entity. The type may be mi=
ssing and, if present, it may be "auto": in both cases the initializing exp=
ression must be present, and the type of the variable is deduced from the i=
nitializing expression. If the type is missing, then the curly braces (but =
not the expression) may be omitted too. <span style=3D"font-size:13px"=
>If the type is present and it is not "auto", then the initializing express=
ion may be omitted, in which case the variable would be default-initialized=
.. <i>Value-initialization</i> would be achieved using empty braces.&nb=
sp;</span><span style=3D"font-size:13px">When an initializer is present, th=
e semantics is always the one of <i>direct-list-initialization</i>.</span><=
/div></div></div></blockquote><div><br></div><div>And what if I want non-li=
st initialization? What if I want copy-initialization? It seems like you'd =
need to also allow</div><div><br></div><div> <identifier> :=3D =
[<type>] ( <expression-list> );</div><div><br></div><blockquote=
class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:=
1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left=
:1ex"><div dir=3D"ltr"><div><div>When declaring function parameters, the id=
entifier would be optional too; when the identifier is missing, the syntax =
reduces to the current one. In agreement with the above syntax, default arg=
ument values could be specified using curly braces (in addition to the curr=
ent syntax that uses the equal sign).<br></div></div></div></blockquote><di=
v><br></div><div>Again, there are reasons for restricting function paramete=
r initialization to copy-initialization. Changing syntax doesn't remove tho=
se reasons. I think you're trying to change too much.</div><div><br></div><=
blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l=
eft-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;pa=
dding-left:1ex"><div dir=3D"ltr"><div><div>As an example:<br><br><div style=
=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;background-color=
:rgb(250,250,250)"><code><div><span style=3D"color:rgb(0,0,0)">s </span><sp=
an style=3D"color:rgb(102,102,0)">:=3D</span><span style=3D"color:rgb(0,0,0=
)"> </span><span style=3D"color:rgb(0,102,102)">42</span><span style=3D"col=
or:rgb(102,102,0)">;</span><span style=3D"color:rgb(0,0,0)"> </span><span s=
tyle=3D"color:rgb(136,0,0)">// Type "int" deduced from the initializer</spa=
n></div></code></div></div></div></div></blockquote><div><br></div><div>Thi=
s is not allowed by your above formulation, and it reintroduces the risk of=
vexing parses, assuming you allow non-list initialization. You'd need to w=
rite</div><div><br></div><div> s :=3D { 42 };</div><div><br></div><di=
v>to satisfy your rules.</div><div><br></div><blockquote class=3D"gmail_quo=
te" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-col=
or:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir=3D"l=
tr"><div><div><div style=3D"border:1px solid rgb(187,187,187);word-wrap:bre=
ak-word;background-color:rgb(250,250,250)"><code><div><span style=3D"color:=
rgb(0,0,0)"><br>t </span><span style=3D"color:rgb(102,102,0)">:=3D</span><s=
pan style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">a=
uto</span><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"color=
:rgb(0,102,102)">42</span><span style=3D"color:rgb(102,102,0)">};</span><sp=
an style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(136,0,0)">//=
Same as above</span><span style=3D"color:rgb(0,0,0)"><br>x </span><span st=
yle=3D"color:rgb(102,102,0)">:=3D</span><span style=3D"color:rgb(0,0,0)"> s=
td</span><span style=3D"color:rgb(102,102,0)">::</span><span style=3D"color=
:rgb(0,0,0)">mutex</span><span style=3D"color:rgb(102,102,0)">;</span><span=
style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(136,0,0)">// D=
efault-constructed mutex</span><span style=3D"color:rgb(0,0,0)"><br>y </spa=
n><span style=3D"color:rgb(102,102,0)">:=3D</span><span style=3D"color:rgb(=
0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">int</span><span style=3D=
"color:rgb(102,102,0)">*{</span><span style=3D"color:rgb(0,0,0)">foo</span>=
<span style=3D"color:rgb(102,102,0)">()};</span><span style=3D"color:rgb(0,=
0,0)"> </span><span style=3D"color:rgb(136,0,0)">// Pointer to int initiali=
zed from foo()</span><span style=3D"color:rgb(0,0,0)"><br>w </span><span st=
yle=3D"color:rgb(102,102,0)">:=3D</span><span style=3D"color:rgb(0,0,0)"> <=
/span><span style=3D"color:rgb(0,0,136)">int</span><span style=3D"color:rgb=
(102,102,0)">{};</span><span style=3D"color:rgb(0,0,0)"> </span><span style=
=3D"color:rgb(136,0,0)">// Value-initialized integer</span><span style=3D"c=
olor:rgb(0,0,0)"><br>v </span><span style=3D"color:rgb(102,102,0)">:=3D</sp=
an><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,13=
6)">int</span><span style=3D"color:rgb(102,102,0)">;</span><span style=3D"c=
olor:rgb(0,0,0)"> </span><span style=3D"color:rgb(136,0,0)">// Default-init=
ialized integer</span><span style=3D"color:rgb(0,0,0)"><br>a </span><span s=
tyle=3D"color:rgb(102,102,0)">:=3D</span><span style=3D"color:rgb(0,0,0)"> =
std</span><span style=3D"color:rgb(102,102,0)">::</span><span style=3D"colo=
r:rgb(0,0,0)">array</span><span style=3D"color:rgb(102,102,0)"><</span><=
span style=3D"color:rgb(0,0,136)">int</span><span style=3D"color:rgb(102,10=
2,0)">,</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color=
:rgb(0,102,102)">50</span><span style=3D"color:rgb(102,102,0)">>{</span>=
<span style=3D"color:rgb(0,102,102)">0</span><span style=3D"color:rgb(102,1=
02,0)">};</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"col=
or:rgb(136,0,0)">// Guaranteed efficient, no need for copy elision</span><s=
pan style=3D"color:rgb(0,0,0)"><br><br></span><span style=3D"color:rgb(0,0,=
136)">struct</span><span style=3D"color:rgb(0,0,0)"> X<br></span><span styl=
e=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rgb(0,0,0)"><br></s=
pan><span style=3D"color:rgb(0,0,136)">private</span><span style=3D"color:r=
gb(102,102,0)">:</span><span style=3D"color:rgb(0,0,0)"><br> z=
</span><span style=3D"color:rgb(102,102,0)">:=3D</span><span style=3D"colo=
r:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">int</span><span st=
yle=3D"color:rgb(102,102,0)">;</span><span style=3D"color:rgb(0,0,0)"> </sp=
an><span style=3D"color:rgb(136,0,0)">// Non-static data member</span><span=
style=3D"color:rgb(0,0,0)"><br> w </span><span style=3D"color=
:rgb(102,102,0)">:=3D</span><span style=3D"color:rgb(0,0,0)"> std</span><sp=
an style=3D"color:rgb(102,102,0)">::</span><span style=3D"color:rgb(0,0,136=
)">string</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"col=
or:rgb(102,102,0)">{</span><span style=3D"color:rgb(0,0,0)"> </span><span s=
tyle=3D"color:rgb(0,136,0)">"Hello"</span><span style=3D"color:rgb(0,0,0)">=
</span><span style=3D"color:rgb(102,102,0)">};</span><span style=3D"color:=
rgb(0,0,0)"> </span><span style=3D"color:rgb(136,0,0)">// Non-static data m=
ember with default initializer</span><span style=3D"color:rgb(0,0,0)"><br>&=
nbsp; p </span><span style=3D"color:rgb(102,102,0)">:=3D</span><span=
style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,102,102)">42=
</span><span style=3D"color:rgb(102,102,0)">;</span><span style=3D"color:rg=
b(0,0,0)"> </span><span style=3D"color:rgb(136,0,0)">// Non-static data mem=
ber with default initializer and deduced type "int"</span><span style=3D"co=
lor:rgb(0,0,0)"><br></span><span style=3D"color:rgb(0,0,136)">public</span>=
<span style=3D"color:rgb(102,102,0)">:</span><span style=3D"color:rgb(0,0,0=
)"><br> </span><span style=3D"color:rgb(0,0,136)">auto</span><=
span style=3D"color:rgb(0,0,0)"> foo </span><span style=3D"color:rgb(102,10=
2,0)">(</span><span style=3D"color:rgb(0,0,0)">x </span><span style=3D"colo=
r:rgb(102,102,0)">:=3D</span><span style=3D"color:rgb(0,0,0)"> </span><span=
style=3D"color:rgb(0,0,136)">int</span><span style=3D"color:rgb(102,102,0)=
">)</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb=
(102,102,0)">-></span><span style=3D"color:rgb(0,0,0)"> </span><span sty=
le=3D"color:rgb(0,0,136)">void</span><span style=3D"color:rgb(102,102,0)">;=
</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(13=
6,0,0)">// Function parameter without default argument</span><span style=3D=
"color:rgb(0,0,0)"><br> </span><span style=3D"color:rgb(0,0,13=
6)">auto</span><span style=3D"color:rgb(0,0,0)"> bar </span><span style=3D"=
color:rgb(102,102,0)">(</span><span style=3D"color:rgb(0,0,0)">x </span><sp=
an style=3D"color:rgb(102,102,0)">:=3D</span><span style=3D"color:rgb(0,0,0=
)"> </span><span style=3D"color:rgb(0,0,136)">int</span><span style=3D"colo=
r:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">{</span><span st=
yle=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,102,102)">42</s=
pan><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,1=
02,0)">})</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"col=
or:rgb(102,102,0)">-></span><span style=3D"color:rgb(0,0,0)"> </span><sp=
an style=3D"color:rgb(0,0,136)">void</span><span style=3D"color:rgb(102,102=
,0)">;</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:=
rgb(136,0,0)">// Function parameter with default argument</span><span style=
=3D"color:rgb(0,0,0)"><br></span><span style=3D"color:rgb(102,102,0)">};</s=
pan><span style=3D"color:rgb(0,0,0)"><br><br>x </span><span style=3D"color:=
rgb(102,102,0)">:=3D</span><span style=3D"color:rgb(0,0,0)"> </span><span s=
tyle=3D"color:rgb(102,102,0)">[</span><span style=3D"color:rgb(0,0,0)">w </=
span><span style=3D"color:rgb(102,102,0)">:=3D</span><span style=3D"color:r=
gb(0,0,0)"> y</span><span style=3D"color:rgb(102,102,0)">]</span><span styl=
e=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">{</span=
><span style=3D"color:rgb(0,0,0)"> std</span><span style=3D"color:rgb(102,1=
02,0)">::</span><span style=3D"color:rgb(0,0,0)">cout </span><span style=3D=
"color:rgb(102,102,0)"><<</span><span style=3D"color:rgb(0,0,0)"> w</=
span><span style=3D"color:rgb(102,102,0)">;</span><span style=3D"color:rgb(=
0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">};</span><span style=
=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(136,0,0)">// Lambda =
capture with deduced type</span><span style=3D"color:rgb(0,0,0)"><br><br></=
span><span style=3D"color:rgb(0,0,136)">auto</span><span style=3D"color:rgb=
(0,0,0)"> fizz</span><span style=3D"color:rgb(102,102,0)">(</span><span sty=
le=3D"color:rgb(0,0,0)">x </span><span style=3D"color:rgb(102,102,0)">:</sp=
an><font color=3D"#000000"><span style=3D"color:rgb(102,102,0)">=3D</span><=
span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">=
auto</span><span style=3D"color:rgb(102,102,0)">)</span><span style=3D"colo=
r:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">-></span><spa=
n style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">int=
</span><span style=3D"color:rgb(102,102,0)">;</span><span style=3D"color:rg=
b(0,0,0)"> </span><span style=3D"color:rgb(136,0,0)">// Terse syntax as def=
ined by Concepts TS</span></font><span style=3D"color:rgb(0,0,0)"><br></spa=
n></div></code></div></div><div><br></div><div>The ":=3D" token is an arbit=
rary choice and may not be the best one - I wouldn't mind changing it, as l=
ong as the consistency and universality of the syntax is preserved. Perhaps=
a more readable alternative would be to use a single ":", but that may lea=
d to confusion:<br><br><div style=3D"border:1px solid rgb(187,187,187);word=
-wrap:break-word;background-color:rgb(250,250,250)"><code><div><span style=
=3D"color:rgb(0,0,0)">x </span><span style=3D"color:rgb(102,102,0)">:</span=
><font color=3D"#000088"><span style=3D"color:rgb(0,0,0)"> </span><span sty=
le=3D"color:rgb(0,0,136)">int</span><span style=3D"color:rgb(0,0,0)"> </spa=
n><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rgb(0,0=
,0)"> </span><span style=3D"color:rgb(0,102,102)">42</span><span style=3D"c=
olor:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">};</span><spa=
n style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(136,0,0)">// =
Declares variable "x"</span><span style=3D"color:rgb(0,0,0)"><br>x</span><s=
pan style=3D"color:rgb(102,102,0)">:</span><span style=3D"color:rgb(0,0,0)"=
> </span><span style=3D"color:rgb(0,0,136)">int</span><span style=3D"color:=
rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">{</span><span styl=
e=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,102,102)">42</spa=
n><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102=
,0)">};</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color=
:rgb(136,0,0)">// </span></font><span style=3D"color:rgb(136,0,0);font-size=
:13.3333330154419px"><span style=3D"color:rgb(136,0,0)">Declares</span></sp=
an><font color=3D"#000088"><span style=3D"color:rgb(136,0,0)"> label "x", w=
here temporary is instantiated.</span></font></div></code></div></div></div=
></div></blockquote><div><br></div><div>These are both a label today. This =
kind of rule does not fit into C++'s lexical model.</div><div> </div><=
blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l=
eft-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;pa=
dding-left:1ex"><div dir=3D"ltr"><div><div>Compilers could emit a warning, =
but we would still have two very similar ways of writing two very different=
things, which I dislike. It would also create confusion inside range-based=
"for" loops, where ":" is used to separate the range from the iterating va=
riable.</div><div><br></div><div><span style=3D"font-size:13px">Please let =
me know your thoughts on this. Any kind of feedback is welcome.</span><br><=
/div><div><span style=3D"font-size:13px"><br></span></div><div><span style=
=3D"font-size:13px">Kind regards,</span><br></div><div><br>Andy<span class=
=3D""><font color=3D"#888888"><br></font></span></div></div></div><span cla=
ss=3D""><font color=3D"#888888">
<p></p>
-- <br>
<br>
--- <br>
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</font></span></blockquote></div><br></div></div>
<p></p>
-- <br>
<br>
--- <br>
You received this message because you are subscribed to the Google Groups "=
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>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br>
</div></blockquote></body></html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--Apple-Mail-BD2B5D5B-0D2A-4365-8E9D-C4FEB29C344A--
.
Author: Andy Prowl <andy.prowl@gmail.com>
Date: Tue, 9 Dec 2014 16:06:23 -0800 (PST)
Raw View
------=_Part_889_1366942950.1418169983740
Content-Type: multipart/alternative;
boundary="----=_Part_890_430105044.1418169983740"
------=_Part_890_430105044.1418169983740
Content-Type: text/plain; charset=UTF-8
Thank you for your answer Richard.
auto x = std::mutex{}; // Nope, not movable (and "auto&& x = std::mutex{};"
>> is an unelegant hack)
>>
>
> We can make this work (essentially by making copy-elision mandatory). No
> syntax change, no semantics change (in implementations that perform the
> optimization), and you get a uniform syntax for variables.
>
OK, this would be nice, although it would not solve the issue below:
>
>> auto y = int*{foo()}; // Nope, the grammar forbids it
>>
>
> Use a typedef or a different kind of cast. Why would you be casting to a
> pointer type in this way in the first place?
>
For the same reason why I would write "int* p = foo()" or "int* p =
nullptr;". I just want to have a consistent AAA-like way of writing it. The
static_cast<T*> syntax is unnecessarily verbose, and so is the use of a
typedef. I could even use std::add_pointer_t<int>{foo()}, but none of these
alternatives help readability IMO.
>
>> auto a = std::array<int, 500>{0}; // Potentially inefficient, hope for
>> copy elision
>>
>> struct X
>> {
>> private:
>> auto z = int{42}; // Nope, not allowed for in-class initialization
>> of data members
>> public:
>> auto foo(int x) -> void; // Not allowed for function parameters
>>
>
> Neither of these cases declares a variable. The type is so important here
> that deducing it would seldom be a good idea, even if it didn't have
> order-of-translation issues.
>
Right, sorry for the imprecision. The ability of deducing type is not the
fundamental point for me: the fundamental point is that the name can appear
first and the type next, consistently with the way I declare variables (OK,
these are not variables, but they are named entities which are used pretty
much the same way, and I think the considerations in point 3) of my OP
still apply).
> I don't see how adding another syntax for a variable declaration makes the
> language simpler or more consistent; it seems to do the opposite.
>
I think adding a consistent syntax to the language makes the language more
consistent. Granted, the fact of having (too) many alternative
non-consistent ways of doing the same thing (as Tomalak already pointed
out) is not nice. I just thought I'd throw an attempt at doing something
constructive rather than just keep complaining about the status quo. In
case I failed, I apologize.
And what if I want non-list initialization? What if I want
> copy-initialization? It seems like you'd need to also allow [...]
>
I would not allow that. I know I'm going to be flamed for saying this, but
in line with what I wrote above, I think that having too many ways of doing
the same thing is confusing, especially considering that not all of the
options below extend to all types (e.g. std::atomic<int>):
int x = 42; auto x = 42; // int
int x = {42}; auto x = {42}; // std::initializer_list<int>
int x{42}; auto x{42}; // will be int
int x(42); auto x(42); // int
IMO this is a mess. I would just pick one (direct-list-initialization) and
forbid the others. At that point, I'd also pick the cleanest syntax for the
one that remains. Scott Meyers shared similar thoughts at Meeting C++,
based on the observation that Clang-based tools would allow migrating
existing code to the new syntax automatically and correctly - unless you
say that's not true, in that case I *think *I should trust you :)
> Again, there are reasons for restricting function parameter initialization
> to copy-initialization. Changing syntax doesn't remove those reasons. I
> think you're trying to change too much.
>
OK, I understand the topic is more complex than I thought, and I should
probably just give up :) Thank you for your time and feedback anyway.
Kind regards,
Andy
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_890_430105044.1418169983740
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Thank you for your answer Richard.<div><br><blockquote cla=
ss=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #=
ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><div class=3D"gmail_quo=
te"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bor=
der-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:sol=
id;padding-left:1ex"><div dir=3D"ltr"><div><div><div style=3D"border:1px so=
lid rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,250,250)=
"><code><div><span style=3D"color:rgb(0,0,136)">auto</span><span style=3D"c=
olor:rgb(0,0,0)"> x </span><span style=3D"color:rgb(102,102,0)">=3D</span><=
span style=3D"color:rgb(0,0,0)"> std</span><span style=3D"color:rgb(102,102=
,0)">::</span><span style=3D"color:rgb(0,0,0)">mutex</span><span style=3D"c=
olor:rgb(102,102,0)">{};</span><span style=3D"color:rgb(0,0,0)"> </span><sp=
an style=3D"color:rgb(136,0,0)">// Nope, not movable (and "auto&& x=
=3D std::mutex{};" is an unelegant hack)</span></div></code></div></div></=
div></div></blockquote><div><br></div><div>We can make this work (essential=
ly by making copy-elision mandatory). No syntax change, no semantics change=
(in implementations that perform the optimization), and you get a uniform =
syntax for variables.</div><div></div></div></div></div></blockquote><div><=
br>OK, this would be nice, although it would not solve the issue below:<br>=
<span style=3D"font-size: 13px;"> </span></div><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"><div class=3D"gmail_quote"><bl=
ockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-lef=
t-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padd=
ing-left:1ex"><div dir=3D"ltr"><div><div><div style=3D"border:1px solid rgb=
(187,187,187);word-wrap:break-word;background-color:rgb(250,250,250)"><code=
><div><span style=3D"color:rgb(0,0,0)"><br></span><span style=3D"color:rgb(=
0,0,136)">auto</span><span style=3D"color:rgb(0,0,0)"> y </span><span style=
=3D"color:rgb(102,102,0)">=3D</span><span style=3D"color:rgb(0,0,0)"> </spa=
n><span style=3D"color:rgb(0,0,136)">int</span><span style=3D"color:rgb(102=
,102,0)">*{</span><span style=3D"color:rgb(0,0,0)">foo</span><span style=3D=
"color:rgb(102,102,0)">()};</span><span style=3D"color:rgb(0,0,0)"> <=
/span><span style=3D"color:rgb(136,0,0)">// Nope, the grammar forbids it</s=
pan></div></code></div></div></div></div></blockquote><div><br></div><div>U=
se a typedef or a different kind of cast. Why would you be casting to a poi=
nter type in this way in the first place?</div></div></div></blockquote><di=
v><br>For the same reason why I would write "int* p =3D foo()" or "int* p =
=3D nullptr;". I just want to have a consistent AAA-like way of writing it.=
The static_cast<T*> syntax is unnecessarily verbose, and so is the u=
se of a typedef. I could even use std::add_pointer_t<int>{foo()}, but=
none of these alternatives help readability IMO.<br> </div><blockquot=
e class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: =
1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><div class=3D"gmai=
l_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8e=
x;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-styl=
e:solid;padding-left:1ex"><div dir=3D"ltr"><div><div><div style=3D"border:1=
px solid rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,250=
,250)"><code><div><span style=3D"color:rgb(0,0,0)"><br></span><span style=
=3D"color:rgb(0,0,136)">auto</span><span style=3D"color:rgb(0,0,0)"> a </sp=
an><span style=3D"color:rgb(102,102,0)">=3D</span><span style=3D"color:rgb(=
0,0,0)"> std</span><span style=3D"color:rgb(102,102,0)">::</span><span styl=
e=3D"color:rgb(0,0,0)">array</span><span style=3D"color:rgb(102,102,0)"><=
;</span><span style=3D"color:rgb(0,0,136)">int</span><span style=3D"color:r=
gb(102,102,0)">,</span><span style=3D"color:rgb(0,0,0)"> </span><span style=
=3D"color:rgb(0,102,102)">500</span><span style=3D"color:rgb(102,102,0)">&g=
t;{</span><span style=3D"color:rgb(0,102,102)">0</span><span style=3D"color=
:rgb(102,102,0)">};</span><span style=3D"color:rgb(0,0,0)"> </span><span st=
yle=3D"color:rgb(136,0,0)">// Potentially inefficient, hope for copy elisio=
n</span><span style=3D"color:rgb(0,0,0)"><br><br></span><span style=3D"colo=
r:rgb(0,0,136)">struct</span><span style=3D"color:rgb(0,0,0)"> X<br></span>=
<span style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rgb(0,0,0=
)"><br></span><span style=3D"color:rgb(0,0,136)">private</span><span style=
=3D"color:rgb(102,102,0)">:</span><span style=3D"color:rgb(0,0,0)"><br>&nbs=
p; </span><span style=3D"color:rgb(0,0,136)">auto</span><span style=
=3D"color:rgb(0,0,0)"> z </span><span style=3D"color:rgb(102,102,0)">=3D</s=
pan><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,1=
36)">int</span><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"=
color:rgb(0,102,102)">42</span><span style=3D"color:rgb(102,102,0)">};</spa=
n><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(136,0,0=
)">// Nope, not allowed for in-class initialization of data members</span><=
span style=3D"color:rgb(0,0,0)"><br></span><span style=3D"color:rgb(0,0,136=
)">public</span><span style=3D"color:rgb(102,102,0)">:</span><span style=3D=
"color:rgb(0,0,0)"><br> </span><span style=3D"color:rgb(0,0,13=
6)">auto</span><span style=3D"color:rgb(0,0,0)"> foo</span><span style=3D"c=
olor:rgb(102,102,0)">(</span><font color=3D"#000088" style=3D"font-size:13.=
3333330154419px"><span style=3D"color:rgb(0,0,136)">int</span><span style=
=3D"color:rgb(0,0,0)"> x</span><span style=3D"color:rgb(102,102,0)">)</span=
><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,=
0)">-></span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"col=
or:rgb(0,0,136)">void</span><span style=3D"color:rgb(102,102,0)">;</span><s=
pan style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(136,0,0)">/=
/ Not allowed for function parameters</span></font></div></code></div></div=
></div></div></blockquote><div><br></div><div>Neither of these cases declar=
es a variable. The type is so important here that deducing it would seldom =
be a good idea, even if it didn't have order-of-translation issues.</div></=
div></div></div></blockquote><div><br></div><div>Right, sorry for the impre=
cision. The ability of deducing type is not the fundamental point for me: t=
he fundamental point is that the name can appear first and the type next, c=
onsistently with the way I declare variables (OK, these are not variables, =
but they are named entities which are used pretty much the same way, and I =
think the considerations in point 3) of my OP still apply).</div><div><span=
style=3D"font-size: 13px;"> </span></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><div class=3D"gmail_quote"><div>I do=
n't see how adding another syntax for a variable declaration makes the lang=
uage simpler or more consistent; it seems to do the opposite.</div></div></=
div></div></blockquote><div><br></div><div>I think adding a consistent synt=
ax to the language makes the language more consistent. Granted, the fact of=
having (too) many alternative non-consistent ways of doing the same thing =
(as Tomalak already pointed out) is not nice. I just thought I'd throw an a=
ttempt at doing something constructive rather than just keep complaining ab=
out the status quo. In case I failed, I apologize.</div><div><br></div><blo=
ckquote 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 class=
=3D"gmail_quote"><div>And what if I want non-list initialization? What if I=
want copy-initialization? It seems like you'd need to also allow [...]</di=
v></div></div></div></blockquote><div><br></div><div>I would not allow that=
.. I know I'm going to be flamed for saying this, but in line with what I wr=
ote above, I think that having too many ways of doing the same thing is con=
fusing, especially considering that not all of the options below extend to =
all types (e.g. std::atomic<int>):</div><div><br></div><div><div clas=
s=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap:=
break-word; background-color: rgb(250, 250, 250);"><code class=3D"prettypr=
int"><div class=3D"subprettyprint"><font color=3D"#000088"><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">int</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span></font><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">x </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><font color=3D"#006666"><span style=3D"color: #06=
6;" class=3D"styled-by-prettify">42</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">auto</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> x </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
</span><span style=3D"color: #066;" class=3D"styled-by-prettify">42</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #800;" class=3D"styled-by-prettify">// int</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"><br></span></font><span style=3D"color:=
#008;" class=3D"styled-by-prettify">int</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">x </span><span style=3D"colo=
r: #660;" 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><span style=3D"color: #066;" class=3D"style=
d-by-prettify">42</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">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 s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #06=
6;" class=3D"styled-by-prettify">42</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">};</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #800;" class=3D"styled-by-pr=
ettify">// std::initializer_list<int></span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">int</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: #066;" class=3D"styled-by-prettif=
y">42</span><span style=3D"color: #660;" class=3D"styled-by-prettify">};</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">  =
; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> x</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D=
"color: #066;" class=3D"styled-by-prettify">42</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: #800;" class=3D"s=
tyled-by-prettify">// will be int</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> x</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">(</span><span style=3D"color: #066;" class=3D"styled-by-prettify">42</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> x</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #=
066;" class=3D"styled-by-prettify">42</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">);</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #800;" class=3D"styled-by-=
prettify">// int</span></font></div></code></div><br>IMO this is a mess. I =
would just pick one (direct-list-initialization) and forbid the others. At =
that point, I'd also pick the cleanest syntax for the one that remains. Sco=
tt Meyers shared similar thoughts at Meeting C++, based on the observation =
that Clang-based tools would allow migrating existing code to the new synta=
x automatically and correctly - unless you say that's not true, in that cas=
e I <i>think </i>I should trust you :)</div><div><span style=3D"font-size: =
13px;"> </span></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><div class=3D"gmail_quote"><div>Again, there are reasons =
for restricting function parameter initialization to copy-initialization. C=
hanging syntax doesn't remove those reasons. I think you're trying to chang=
e too much.</div></div></div></div></blockquote><div><br></div><div>OK, I u=
nderstand the topic is more complex than I thought, and I should probably j=
ust give up :) Thank you for your time and feedback anyway.<br><br></d=
iv><div>Kind regards,<br><br>Andy</div></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_890_430105044.1418169983740--
------=_Part_889_1366942950.1418169983740--
.
Author: Andy Prowl <andy.prowl@gmail.com>
Date: Tue, 9 Dec 2014 16:14:14 -0800 (PST)
Raw View
------=_Part_5651_1370529856.1418170454975
Content-Type: multipart/alternative;
boundary="----=_Part_5652_1809066289.1418170454980"
------=_Part_5652_1809066289.1418170454980
Content-Type: text/plain; charset=UTF-8
Thank you for the pointer Ville.
Once again, to me the important part is not type deduction, but
left-to-right style. Using "auto" is currently the only way of enforcing a
left-to-right style, but that is quite an abuse of it IMO. When I follow
Herb's advice and write:
auto x = type{value};
my goal is not to let the compiler deduce the type of x: the goal is to
write the declaration of x left-to-right. I think we should have a
convenient and consistent syntax for doing that, rather than (ab)using
"auto".
Kind regards,
Andy
On Wednesday, December 10, 2014 12:30:56 AM UTC+1, Ville Voutilainen wrote:
>
> On 10 December 2014 at 01:27, Richard Smith <ric...@metafoo.co.uk
> <javascript:>> wrote:
> > On Tue, Dec 9, 2014 at 2:15 PM, Andy Prowl <andy....@gmail.com
> <javascript:>> wrote:
> >> struct X
> >> {
> >> private:
> >> auto z = int{42}; // Nope, not allowed for in-class initialization
> of
> >> data members
> >> public:
> >> auto foo(int x) -> void; // Not allowed for function parameters
> >
> >
> > Neither of these cases declares a variable. The type is so important
> here
> > that deducing it would seldom be a good idea, even if it didn't have
> > order-of-translation issues.
>
> See also
> 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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_5652_1809066289.1418170454980
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Thank you for the pointer Ville.<br><br>Once again, to me =
the important part is not type deduction, but left-to-right style. Using "a=
uto" is currently the only way of enforcing a left-to-right style, but that=
is quite an abuse of it IMO. When I follow Herb's advice and write:<br><br=
><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); =
word-wrap: break-word; background-color: rgb(250, 250, 250);"><code 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"sty=
led-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> type</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify">valu=
e</span><span style=3D"color: #660;" class=3D"styled-by-prettify">};</span>=
</div></code></div><br>my goal is not to let the compiler deduce the type o=
f x: the goal is to write the declaration of x left-to-right. I think we sh=
ould have a convenient and consistent syntax for doing that, rather than (a=
b)using "auto".<div><br></div><div>Kind regards,<br><br>Andy<br><br><br><br=
>On Wednesday, December 10, 2014 12:30:56 AM UTC+1, Ville Voutilainen wrote=
:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bo=
rder-left: 1px #ccc solid;padding-left: 1ex;">On 10 December 2014 at 01:27,=
Richard Smith <<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated=
-mailto=3D"qx6n_QypD8UJ" onmousedown=3D"this.href=3D'javascript:';return tr=
ue;" onclick=3D"this.href=3D'javascript:';return true;">ric...@metafoo.co.u=
k</a>> wrote:
<br>> On Tue, Dec 9, 2014 at 2:15 PM, Andy Prowl <<a href=3D"javascri=
pt:" target=3D"_blank" gdf-obfuscated-mailto=3D"qx6n_QypD8UJ" onmousedown=
=3D"this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'javascr=
ipt:';return true;">andy....@gmail.com</a>> wrote:
<br>>> struct X
<br>>> {
<br>>> private:
<br>>> auto z =3D int{42}; // Nope, not allowed for in-=
class initialization of
<br>>> data members
<br>>> public:
<br>>> auto foo(int x) -> void; // Not allowed for f=
unction parameters
<br>>
<br>>
<br>> Neither of these cases declares a variable. The type is so importa=
nt here
<br>> that deducing it would seldom be a good idea, even if it didn't ha=
ve
<br>> order-of-translation issues.
<br>
<br>See also
<br><a href=3D"http://open-std.org/JTC1/SC22/WG21/docs/papers/2014/n3897.ht=
ml" target=3D"_blank" onmousedown=3D"this.href=3D'http://www.google.com/url=
?q\75http%3A%2F%2Fopen-std.org%2FJTC1%2FSC22%2FWG21%2Fdocs%2Fpapers%2F2014%=
2Fn3897.html\46sa\75D\46sntz\0751\46usg\75AFQjCNE93tuQmcRVqAup74EnVuW7ajKEZ=
g';return true;" onclick=3D"this.href=3D'http://www.google.com/url?q\75http=
%3A%2F%2Fopen-std.org%2FJTC1%2FSC22%2FWG21%2Fdocs%2Fpapers%2F2014%2Fn3897.h=
tml\46sa\75D\46sntz\0751\46usg\75AFQjCNE93tuQmcRVqAup74EnVuW7ajKEZg';return=
true;">http://open-std.org/JTC1/SC22/<wbr>WG21/docs/papers/2014/n3897.<wbr=
>html</a>
<br></blockquote></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_5652_1809066289.1418170454980--
------=_Part_5651_1370529856.1418170454975--
.