Topic: Replace 'C' style type-casting meaning to creation of


Author: sasho648 <sasho648@mail.bg>
Date: Fri, 28 Nov 2014 03:39:18 -0800 (PST)
Raw View
------=_Part_6930_1935025101.1417174758668
Content-Type: multipart/alternative;
 boundary="----=_Part_6931_474522339.1417174758668"

------=_Part_6931_474522339.1417174758668
Content-Type: text/plain; charset=UTF-8

As casting variable to another type just means creating a temporary object
of the target type using the variable casted why don't we just deprecate
the construct:

*(**type-to-cast**)(**variable-to-cast**)*

And create a new one:

*(**type-of-the-unnamed-object**)**(**initialization-parameters**)*

Which will create a temporary unnamed object using the ''
*initialization-parameters''. *This will remove the term ''most vexing
parse'' as there will be a clear difference when an unnamed object is being
created and when a function is declared. It will also keep compatibility
with old-code as casting to another type is simply what the new construct
will mean - creating an unnamed object. I suggest that old
'casting-operators' are supported too only if there is no defined a copy
constructor for the object being created. Example:

class Type1;


class Type
{

Type(const Type1 &); //copy-constructor for objects of type 'Type1'



};
class Type1
{

Type1 (const Type1 &); // copy-constructor



Type operator Type() const; //cast operator

};


int main()
{

(Type1 var1)() //this construction for 'default' initialization will be
supported too

(Type var)((Type)(var1)); // as there is constructor 'Type::Type(const Type1
 &)'  the cast operator - 'Type Type1::operator Type() const'  wouldn't be
instanced but instead the constructor

}

This will also remove the term ''most vexing parse'', shown here:

int bar(int(x)) // a function declaration


int bar ( (int)(x) ) // a variable initialized with a temporary

--

---
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_6931_474522339.1417174758668
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">As casting variable to another type just&nbsp;means&nbsp;c=
reating a temporary object of the target type using the variable casted why=
 don't we just deprecate the construct:<br><br><b>(</b><i>type-to-cast</i><=
b>)(</b><i>variable-to-cast</i><b>)</b><div><b><br></b></div><div>And creat=
e a new one:<br><br><b>(</b><i>type-of-the-unnamed-object</i><b>)</b><b>(</=
b><i>initialization-parameters</i><b>)</b><br></div><div><b><br></b></div><=
div>Which will create a temporary unnamed object using the ''<i>initializat=
ion-parameters''.&nbsp;</i>This will remove the term ''most vexing parse'' =
as there will be a clear difference when an unnamed object is being created=
 and when a function is declared. It will also keep compatibility with old-=
code as casting to another type is simply what the new construct will mean =
- creating an unnamed object. I suggest that old 'casting-operators' are su=
pported too only if there is no defined a copy constructor for the object b=
eing created. Example:<br><br></div><div class=3D"prettyprint" style=3D"bor=
der: 1px solid rgb(187, 187, 187); word-wrap: break-word; background-color:=
 rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"subprettypr=
int"><span style=3D"color: #008;" class=3D"styled-by-prettify">class</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #606;" class=3D"styled-by-prettify">Type1</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br><br><br></span><span style=3D"color:=
 #008;" class=3D"styled-by-prettify">class</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Type</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">{<br></span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br></span><span style=3D"color: #606;" class=3D"styled-by-prettify"=
>Type</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">const</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">Type1</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">&amp;);</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> </span><span style=3D"color: #800;" class=3D=
"styled-by-prettify">//copy-constructor for objects of type '</span><span s=
tyle=3D"color: rgb(102, 0, 102); font-family: Arial, Helvetica, sans-serif;=
">Type1</span><span style=3D"color: rgb(136, 0, 0); font-family: Arial, Hel=
vetica, sans-serif;">'</span></div><div class=3D"subprettyprint"><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br><br><br></span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: =
#008;" class=3D"styled-by-prettify">class</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Type1</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">{<br></span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br><span style=3D"color: rgb(102, 0, 102);">Type1 (</span><span cl=
ass=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 136);">const</span><sp=
an class=3D"styled-by-prettify">&nbsp;</span><span class=3D"styled-by-prett=
ify" style=3D"color: rgb(102, 0, 102);">Type1</span><span class=3D"styled-b=
y-prettify">&nbsp;</span><span class=3D"styled-by-prettify" style=3D"color:=
 rgb(102, 102, 0);">&amp;); // c</span><span style=3D"color: rgb(136, 0, 0)=
;">opy-constructor<br></span><br><br><br></span><span style=3D"color: #008;=
" class=3D"styled-by-prettify"><span style=3D"color: rgb(102, 0, 102);">Typ=
e&nbsp;</span>operator</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettif=
y">Type</span><span style=3D"color: #660;" class=3D"styled-by-prettify">()<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">const</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #800=
;" class=3D"styled-by-prettify">//cast operator</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">};</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br><br><br></span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">int</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> main</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">{</span><font color=3D"#880000"><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br></span></font><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br></span><span style=3D"color: rgb(102, 0, 102);"><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">Type1</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> var1</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">)(</span></span><span style=3D"color: =
rgb(102, 102, 0); font-family: Arial, Helvetica, sans-serif;">)&nbsp;</span=
><span style=3D"color: rgb(136, 0, 0); font-family: Arial, Helvetica, sans-=
serif;">//this construction for 'default' initialization will be supported =
too</span><span style=3D"color: rgb(102, 102, 0); font-family: Arial, Helve=
tica, sans-serif;">&nbsp;</span></div><div class=3D"subprettyprint"><span s=
tyle=3D"color: rgb(102, 102, 0); font-family: Arial, Helvetica, sans-serif;=
"><br></span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 10=
2, 0);">(</span><span class=3D"styled-by-prettify" style=3D"color: rgb(102,=
 0, 102);">Type</span><span class=3D"styled-by-prettify" style=3D"color: rg=
b(0, 0, 0);">&nbsp;</span><span class=3D"styled-by-prettify" style=3D"color=
: rgb(0, 0, 136);">var</span><span class=3D"styled-by-prettify" style=3D"co=
lor: rgb(102, 102, 0);">)((</span><span class=3D"styled-by-prettify" style=
=3D"font-family: Arial, Helvetica, sans-serif; color: rgb(102, 0, 102);">Ty=
pe</span><span class=3D"styled-by-prettify" style=3D"font-family: Arial, He=
lvetica, sans-serif; color: rgb(0, 0, 0);">)(</span><span style=3D"color: r=
gb(0, 0, 0); font-family: Arial, Helvetica, sans-serif;">var1)</span><span =
class=3D"styled-by-prettify" style=3D"font-family: Arial, Helvetica, sans-s=
erif; color: rgb(102, 102, 0);">);</span><span class=3D"styled-by-prettify"=
 style=3D"font-family: Arial, Helvetica, sans-serif; color: rgb(0, 0, 0);">=
&nbsp;</span><span style=3D"color: rgb(102, 102, 0); font-family: Arial, He=
lvetica, sans-serif;">// as there is constructor '</span><span style=3D"col=
or: rgb(102, 0, 102); font-family: Arial, Helvetica, sans-serif;">Type::</s=
pan><span class=3D"styled-by-prettify" style=3D"font-family: Arial, Helveti=
ca, sans-serif; color: rgb(102, 0, 102);">Type</span><span class=3D"styled-=
by-prettify" style=3D"font-family: Arial, Helvetica, sans-serif; color: rgb=
(102, 102, 0);">(</span><span class=3D"styled-by-prettify" style=3D"font-fa=
mily: Arial, Helvetica, sans-serif; color: rgb(0, 0, 136);">const</span><sp=
an class=3D"styled-by-prettify" style=3D"font-family: Arial, Helvetica, san=
s-serif; color: rgb(0, 0, 0);">&nbsp;</span><span class=3D"styled-by-pretti=
fy" style=3D"font-family: Arial, Helvetica, sans-serif; color: rgb(102, 0, =
102);">Type1</span><span class=3D"styled-by-prettify" style=3D"font-family:=
 Arial, Helvetica, sans-serif; color: rgb(0, 0, 0);">&nbsp;</span><span cla=
ss=3D"styled-by-prettify" style=3D"font-family: Arial, Helvetica, sans-seri=
f; color: rgb(102, 102, 0);">&amp;)</span><span style=3D"color: rgb(102, 10=
2, 0); font-family: Arial, Helvetica, sans-serif;">' &nbsp;the cast operato=
r - '</span><span class=3D"styled-by-prettify" style=3D"font-family: Arial,=
 Helvetica, sans-serif; color: rgb(0, 0, 136);"><span style=3D"color: rgb(1=
02, 0, 102);">Type&nbsp;</span></span><span style=3D"color: rgb(102, 0, 102=
); font-family: Arial, Helvetica, sans-serif;">Type1::</span><span class=3D=
"styled-by-prettify" style=3D"font-family: Arial, Helvetica, sans-serif; co=
lor: rgb(0, 0, 136);">operator</span><span class=3D"styled-by-prettify" sty=
le=3D"font-family: Arial, Helvetica, sans-serif; color: rgb(0, 0, 0);">&nbs=
p;</span><span class=3D"styled-by-prettify" style=3D"font-family: Arial, He=
lvetica, sans-serif; color: rgb(102, 0, 102);">Type</span><span class=3D"st=
yled-by-prettify" style=3D"font-family: Arial, Helvetica, sans-serif; color=
: rgb(102, 102, 0);">()</span><span class=3D"styled-by-prettify" style=3D"f=
ont-family: Arial, Helvetica, sans-serif; color: rgb(0, 0, 0);">&nbsp;</spa=
n><span class=3D"styled-by-prettify" style=3D"font-family: Arial, Helvetica=
, sans-serif; color: rgb(0, 0, 136);">const</span><span style=3D"color: rgb=
(102, 102, 0); font-family: Arial, Helvetica, sans-serif;">' &nbsp;wouldn't=
 be instanced but instead the constructor</span></div><div class=3D"subpret=
typrint"><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span></div>=
</code></div><div><br></div><div>This will also remove the term ''most vexi=
ng parse'', shown here:<br><br></div><div class=3D"prettyprint" style=3D"bo=
rder: 1px solid rgb(187, 187, 187); word-wrap: break-word; background-color=
: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"subprettyp=
rint"><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> bar</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">int</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">x</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">))</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">=
// a function declaration</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br><br><br></span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> bar </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">)(</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">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: #660;" class=3D"styled-b=
y-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">// a v=
ariable initialized with a temporary</span></div></code></div><div><br></di=
v></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; 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_6931_474522339.1417174758668--
------=_Part_6930_1935025101.1417174758668--

.