Topic: Extending Casts
Author: Florian Weber <gmail@florianjw.de>
Date: Sun, 9 Nov 2014 08:06:35 -0800 (PST)
Raw View
------=_Part_239_371238305.1415549195335
Content-Type: text/plain; charset=UTF-8
Currently there are three casts with somewhat legit use-cases:
- dynamic_cast, to do a checked pointer/ref-downcast
- static_cast, to do an unchecked pointer/ref-downcast *and** to cast
between arithmetic types*
- reinterpret_cast, to cast between pointers of arbitrary types
There is one big inconsistency: dynamic_cast and reinterpret_cast are
limited to pointers/references, while static_cast has an additional,
actually not very related field of use.
In order to improve on consistency and because those operations look quite
useful to me, I propose to extend dynamic_cast and reinterpret_cast like
this:
- dynamic_cast should additionally cast between arithmetic types (like
static_cast does), but throw std::bad_cast, if information would be lost:
auto i1 = dynamic_cast<std::uint8_t>(int{3});
assert(i1 == 3);
auto i2 = dynamic_cast<std::uint8_t>(1000); // throws std::bad_cast
// not sure about this:
auto f1 = dynamic_cast<int>(1.0);
assert(f1 == 1);
auto f2 = dynamic_cast<int>(1.0001); // throws std::bad_cast
I am not sure whether floating_point to integer would work, but if it is
possible, I'd like to see that too.
- reinterpret_cast should be able to reinterpret instances of all
(primitive?) types as an instance of any other (primitive?) type of equal
size:
static_assert(sizeof(int) == sizeof(float),"");
auto i1 = reinterpret_cast<int>(1.0f);
// same as:
auto f = 1.0f;
auto i2 = int{};
std::memcpy(&i2, f, sizeof(i2));
// again, I am not absolutely sure about this:
struct struct1 {int i1, i2;};
struct struct2{float f1, f2;};
static_assert(sizeof(s1) == sizeof(s2), "don't get padding-problems");
auto s1 = struct1{3, 5};
auto s2 = reinterpret_cast<struct2>(s1);
//assuming identical padding:
assert(s1.i1 = reinterpret_cast<int>(s2.f1));
assert(s2.f1 = reinterpret_cast<int>(s1.i1));
If I am not mistaken, these changes would be as backwards-compatible, as
changes can be in the presence of SFINAE. They would also provide very
valuable functionality that is currently either completely missing from the
standard (dynamic_cast) or only possible with lot's of code that is in
addition verbose, difficult to search for using grep (since there are other
uses of memcpy as well) and not as self-explaining as it could be
(reinterpret_cast).
Does this sound reasonable to you and do you have any suggestions what to
change?
Thanks,
Florian
--
---
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_239_371238305.1415549195335
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Currently there are three casts with somewhat legit use-ca=
ses:<br><br><ul><li>dynamic_cast, to do a checked pointer/ref-downcast</li=
><li>static_cast, to do an unchecked pointer/ref-downcast <b>and</b><i> to =
cast between arithmetic types</i><br></li><li>reinterpret_cast, to cast bet=
ween pointers of arbitrary types</li></ul><p>There is one big inconsistency=
: dynamic_cast and reinterpret_cast are limited to pointers/references, whi=
le static_cast has an additional, actually not very related field of use.</=
p><p>In order to improve on consistency and because those operations look q=
uite useful to me, I propose to extend dynamic_cast and reinterpret_cast li=
ke this:</p><ul><li>dynamic_cast should additionally cast between arithmeti=
c types (like static_cast does), but throw std::bad_cast, if information wo=
uld be lost:<br></li></ul><div style=3D"margin-left: 40px;"><div class=3D"p=
rettyprint" style=3D"background-color: rgb(250, 250, 250); border-color: rg=
b(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: break-=
word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> i1 </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">dynamic_cast</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify"><</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">std</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">uint8_t</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><spa=
n style=3D"color: #066;" class=3D"styled-by-prettify">3</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">});</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">assert</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">i1 </span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">=3D=3D</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify"=
>3</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 s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> i2 </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">dynamic_cast</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify"><</span><span style=3D"color: #000;" cl=
ass=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-b=
y-prettify">uint8_t</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">>(</span><span style=3D"color: #066;" class=3D"styled-by-pretti=
fy">1000</span><span style=3D"color: #660;" class=3D"styled-by-prettify">);=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #800;" class=3D"styled-by-prettify">// throws std::bad_=
cast</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><b=
r></span><span style=3D"color: #800;" class=3D"styled-by-prettify">// not s=
ure about this:</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">auto</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> f1=
</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 st=
yle=3D"color: #008;" class=3D"styled-by-prettify">dynamic_cast</span><span =
style=3D"color: #080;" class=3D"styled-by-prettify"><int></span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D=
"color: #066;" class=3D"styled-by-prettify">1.0</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">assert</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify">f1 </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">=3D=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
</span><span style=3D"color: #066;" class=3D"styled-by-prettify">1</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> f2 </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">dynamic_cast</span><span style=3D"color: #080;" class=3D=
"styled-by-prettify"><int></span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #066;" class=3D"style=
d-by-prettify">1.0001</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">// thr=
ows std::bad_cast</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br></span></div></code></div><br>I am not sure whether floating_poi=
nt to integer would work, but if it is possible, I'd like to see that too.<=
br></div><ul><li>reinterpret_cast should be able to reinterpret instances o=
f all (primitive?) types as an instance of any other (primitive?) type of e=
qual size:</li></ul><p style=3D"margin-left: 40px;"></p><div class=3D"prett=
yprint" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(18=
7, 187, 187); border-style: solid; border-width: 1px; word-wrap: break-word=
;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><font face=3D"=
"Arial","Helvetica",sans-serif"><span style=3D"color: #=
008;" class=3D"styled-by-prettify">static_assert</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">sizeof</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">int</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D=3D</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
style=3D"color: #008;" class=3D"styled-by-prettify">sizeof</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">float</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">),</span><span style=3D"color: #080;" cl=
ass=3D"styled-by-prettify">""</span><span style=3D"color: #660;" class=3D"s=
tyled-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-p=
rettify">auto</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> i1 </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">reinterpret_cast</s=
pan><span style=3D"color: #080;" class=3D"styled-by-prettify"><int></=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><spa=
n style=3D"color: #066;" class=3D"styled-by-prettify">1.0f</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color=
: #800;" class=3D"styled-by-prettify">// same as:</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">auto</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> f </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-pretti=
fy">1.0f</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">auto</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> i2 </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"col=
or: #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"sty=
led-by-prettify"><br>std</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">memcpy</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">(&</span><span style=3D"color: #000;" class=3D"styled-by-prettify">i2=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> f</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;"=
class=3D"styled-by-prettify">sizeof</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify">i2</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">));</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> <br><br></span><span style=3D"color: #800;" class=3D"styled-by-prettify"=
>// again, I am not absolutely sure about this:</span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"><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"> struct1 </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: #000;" class=3D"styled=
-by-prettify"> i1</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> i=
2</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">struct</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> struct2</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">float</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> f1</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> f2</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">;};</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">sta=
tic_assert</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">sizeof</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify">s1</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">=3D=3D</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">sizeof</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">s2</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: #080;" class=3D"styled-by-prettify">"don't get padding-pro=
blems"</span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> s1 </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> struct1</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #066;=
" class=3D"styled-by-prettify">3</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">5</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">auto</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> s2 </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">reinterpret_cast</span><span style=3D"color:=
#080;" class=3D"styled-by-prettify"><struct2></span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">s1</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">);</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br></span><span style=3D"color: #800;" class=3D"styled-by=
-prettify">//assuming identical padding:</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">assert</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify">s1</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">.</span><span style=3D"color: #000;" class=3D"styled-by-prettify">i1 </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">reinterpret_cast</span><span=
style=3D"color: #080;" class=3D"styled-by-prettify"><int></span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">s2</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify">f1</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">));</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"></span></font><font face=3D""Arial","Helvet=
ica",sans-serif"><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><code class=3D"prettyprint"><font face=3D""Arial","Helv=
etica",sans-serif"><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>assert</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">s2</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">f1 </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">reinterpret_cast</span><span style=3D"color: #080;"=
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">s1</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">.</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">i1</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)=
);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"></span><=
/font></code><br></span></font></div></code></div><p></p><p><br></p><p>If I=
am not mistaken, these changes would be as backwards-compatible, as change=
s can be in the presence of SFINAE. They would also provide very valuable f=
unctionality that is currently either completely missing from the standard =
(dynamic_cast) or only possible with lot's of code that is in addition verb=
ose, difficult to search for using grep (since there are other uses of memc=
py as well) and not as self-explaining as it could be (reinterpret_cast).</=
p><p>Does this sound reasonable to you and do you have any suggestions what=
to change?</p><p>Thanks,</p><p>Florian<br></p></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_239_371238305.1415549195335--
.
Author: Jens Maurer <Jens.Maurer@gmx.net>
Date: Sun, 09 Nov 2014 19:42:05 +0100
Raw View
On 11/09/2014 05:06 PM, Florian Weber wrote:
> * reinterpret_cast should be able to reinterpret instances of all (primitive?) types as an instance of any other (primitive?) type of equal size:
See core issue 944, which should probably go though EWG first.
Jens
--
---
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: Florian Weber <gmail@florianjw.de>
Date: Sun, 9 Nov 2014 10:50:09 -0800 (PST)
Raw View
------=_Part_271_1562192764.1415559009918
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
> > * reinterpret_cast should be able to reinterpret instances of all=20
> (primitive?) types as an instance of any other (primitive?) type of equal=
=20
> size:=20
>
> See core issue 944, which should probably go though EWG first.=20
>
>
Are you talking about =E2=80=9C994. *braced-init-list* as a default argumen=
t=E2=80=9D? I=20
don't see how this is related.
Florian
--=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/.
------=_Part_271_1562192764.1415559009918
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">> &nbs=
p; * reinterpret_cast should be able to reinterpret instances of all (primi=
tive?) types as an instance of any other (primitive?) type of equal size:
<br>
<br>See core issue 944, which should probably go though EWG first.
<br>
<br></blockquote><div><br>Are you talking about =E2=80=9C994.
=20
<i>braced-init-list</i> as a default argument=E2=80=9D? I don't see how thi=
s is related.<br><br>Florian<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 />
------=_Part_271_1562192764.1415559009918--
.
Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@gmail.com>
Date: Sun, 9 Nov 2014 19:51:32 +0100
Raw View
2014-11-09 19:50 GMT+01:00 Florian Weber <gmail@florianjw.de>:
>
>> > * reinterpret_cast should be able to reinterpret instances of all
>> > (primitive?) types as an instance of any other (primitive?) type of equal
>> > size:
>>
>> See core issue 944, which should probably go though EWG first.
>>
> Are you talking about "994. braced-init-list as a default argument"? I don't
> see how this is related.
I don't think that it was Jens, who made a typo when referring to
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#944
- Daniel
--
---
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: Jens Maurer <Jens.Maurer@gmx.net>
Date: Sun, 09 Nov 2014 19:53:15 +0100
Raw View
On 11/09/2014 07:50 PM, Florian Weber wrote:
>=20
> > * reinterpret_cast should be able to reinterpret instances of all=
(primitive?) types as an instance of any other (primitive?) type of equal =
size:
>=20
> See core issue 944, which should probably go though EWG first.
>=20
>=20
> Are you talking about =E2=80=9C994. /braced-init-list/ as a default argum=
ent=E2=80=9D? I don't see how this is related.
No, I'm talking about core issue 944 "reinterpret_cast for all types with t=
he same size and alignment":
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4192.html#944
Jens
--=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/.
.
Author: Florian Weber <gmail@florianjw.de>
Date: Sun, 9 Nov 2014 10:59:58 -0800 (PST)
Raw View
------=_Part_2233_2019599036.1415559598602
Content-Type: text/plain; charset=UTF-8
>
> No, I'm talking about core issue 944 "reinterpret_cast for all types with
> the same size and alignment":
>
>
Yes, sorry, I am stupid and unable to type down a three digit-number.
In that case, the reinterpret cast is obviously already in work, so let's
focus on the dynamic_cast. Do you have any objections, suggestions or other
comments regarding that part?
Florian
--
---
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_2233_2019599036.1415559598602
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
<br>No, I'm talking about core issue 944 "reinterpret_cast for all types wi=
th the same size and alignment":
<br>
<br></blockquote><div><br>Yes, sorry, I am stupid and unable to type down a=
three digit-number.<br><br>In that case, the reinterpret cast is obviously=
already in work, so let's focus on the dynamic_cast. Do you have any objec=
tions, suggestions or other comments regarding that part?<br><br>Florian<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 />
------=_Part_2233_2019599036.1415559598602--
.
Author: Jens Maurer <Jens.Maurer@gmx.net>
Date: Sun, 09 Nov 2014 20:19:26 +0100
Raw View
On 11/09/2014 07:59 PM, Florian Weber wrote:
> In that case, the reinterpret cast is obviously already in work,
In my opinion, this is an incorrect description of the situation.
Just because a core issue exists doesn't mean it'll be worked on soon.
Offering wording that implements the core issue would speed up the
processing.
> so let's focus on the dynamic_cast. Do you have any objections, suggestions or other comments regarding that part?
dynamic_cast is very much a runtime cast. Using literals (i.e. constexpr) in
your examples doesn't help the cause, because those cases would already be
caught when using brace-initialization (which forbids narrowing), e.g.
char{267} // ill-formed
Other than that, I can see the utility, but I don't have a strong
opinion whether this facility should be added or not. Using
dynamic_cast (with its existing provision to throw an exception)
seems somewhat compelling, although strange at first sight.
Jens
--
---
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: Florian Weber <gmail@florianjw.de>
Date: Sun, 9 Nov 2014 13:43:17 -0800 (PST)
Raw View
------=_Part_488_851117068.1415569397263
Content-Type: text/plain; charset=UTF-8
> Using literals (i.e. constexpr) in your examples doesn't help the cause,
> because those cases would already be caught when using brace-initialization
>
It was of course only meant as an example, but you are right, it is chosen
quite badly. In fact I think that the code should definitely be ill-formed
if the compiler can proof, that the cast won't succeed. I would like to
encourage that behavior even in non-constexpr-contexts, like this:
auto x = std::int16_t{1000};
auto y = dynamic_cast<std::int8_t>(x); // compilers are encouraged, but not
required to reject this code.
The reason is simply that I wouldn't use a checked_cast, If I wouldn't want
to make sure, that I get a valid value.
A better example for how it should work would be this:
int some_fun();
// ...
auto var = dynamic_cast<short>(some_fun()); // throw if some_fun() is not
representable as short
--
---
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_488_851117068.1415569397263
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">Using lit=
erals (i.e. constexpr) in
your examples doesn't help the cause, because those cases would already be
caught when using brace-initialization<br></blockquote><div><br>It was of c=
ourse only meant as an example, but you are right, it is chosen quite badly=
.. In fact I think that the code should definitely be ill-formed if the comp=
iler can proof, that the cast won't succeed. I would like to encourage that=
behavior even in non-constexpr-contexts, like this:<br><br><div class=3D"p=
rettyprint" style=3D"background-color: rgb(250, 250, 250); border-color: rg=
b(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: break-=
word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> x </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> std</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">int16_t</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">{</span><span style=3D"color: #066;" class=3D"styled-by-pretti=
fy">1000</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">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"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">dynamic_cast</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify"><</span><span style=3D"color: #000;" cl=
ass=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-b=
y-prettify">int8_t</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">>(</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">x</span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #800;" class=3D"styled-by-prettify">// compilers are encour=
aged, but not required to reject this code.</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br></span></div></code></div><br>The reas=
on is simply that I wouldn't use a checked_cast, If I wouldn't want to make=
sure, that I get a valid value.<br><br>A better example for how it should =
work would be this:<br><br><div class=3D"prettyprint" style=3D"background-c=
olor: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: s=
olid; border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint=
"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"style=
d-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> some_fun</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">();</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br><br></span><span style=3D"color: #800;" class=3D"styled-by-prettify">//=
...</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><b=
r></span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">var</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">dynamic_cast</span><span style=3D"color: #080;" cla=
ss=3D"styled-by-prettify"><short></span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify">some_fun</span><span style=3D"color: #660;" class=3D"st=
yled-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">// throw if some_fun() is not representable as short</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></code></di=
v></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_488_851117068.1415569397263--
.
Author: Tony V E <tvaneerd@gmail.com>
Date: Sun, 09 Nov 2014 23:25:38 -0500
Raw View
<html><head></head><body style=3D"background-color: rgb(255, 255, 255); lin=
e-height: initial;"> =
<div style=3D"width: 100%; font-size: initia=
l; font-family: Calibri, 'Slate Pro', sans-serif; color: rgb(31, 73, 125); =
text-align: initial; background-color: rgb(255, 255, 255);"><br></div> =
=
<div style=3D"width: 1=
00%; font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif; col=
or: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, =
255);"><br></div><span style=3D"font-family: monospace; background-color: r=
gb(250, 250, 250); color: rgb(0, 0, 136);">auto</span><span style=3D"font-f=
amily: monospace; background-color: rgb(250, 250, 250);"> x </spa=
n><span style=3D"font-family: monospace; background-color: rgb(250, 250, 25=
0); color: rgb(102, 102, 0);">=3D</span><span style=3D"font-family: monospa=
ce; background-color: rgb(250, 250, 250);"> std</span><span style=3D"f=
ont-family: monospace; background-color: rgb(250, 250, 250); color: rgb(102=
, 102, 0);">::</span><span style=3D"font-family: monospace; background-colo=
r: rgb(250, 250, 250);">int16_t</span><span style=3D"font-family: monospace=
; background-color: rgb(250, 250, 250); color: rgb(102, 102, 0);">{</span><=
span style=3D"font-family: monospace; background-color: rgb(250, 250, 250);=
color: rgb(0, 102, 102);">1000</span><span style=3D"font-family: monospace=
; background-color: rgb(250, 250, 250); color: rgb(102, 102, 0);">};</span>=
<span style=3D"font-family: monospace; background-color: rgb(250, 250, 250)=
;"><br></span><span style=3D"font-family: monospace; background-color: rgb(=
250, 250, 250); color: rgb(0, 0, 136);">auto</span><span style=3D"font-fami=
ly: monospace; background-color: rgb(250, 250, 250);"> y </span><=
span style=3D"font-family: monospace; background-color: rgb(250, 250, 250);=
color: rgb(102, 102, 0);">=3D</span><span style=3D"font-family: monospace;=
background-color: rgb(250, 250, 250);"> </span><span style=3D"font-fa=
mily: monospace; background-color: rgb(250, 250, 250); color: rgb(0, 0, 136=
);">dynamic_cast</span><span style=3D"font-family: monospace; background-co=
lor: rgb(250, 250, 250); color: rgb(102, 102, 0);"><</span><span style=
=3D"font-family: monospace; background-color: rgb(250, 250, 250);">std</spa=
n><span style=3D"font-family: monospace; background-color: rgb(250, 250, 25=
0); color: rgb(102, 102, 0);">::</span><span style=3D"font-family: monospac=
e; background-color: rgb(250, 250, 250);">int8_t</span><span style=3D"font-=
family: monospace; background-color: rgb(250, 250, 250); color: rgb(102, 10=
2, 0);">>(</span><span style=3D"font-family: monospace; background-color=
: rgb(250, 250, 250);">x</span><span style=3D"font-family: monospace; backg=
round-color: rgb(250, 250, 250); color: rgb(102, 102, 0);">);</span><span s=
tyle=3D"font-family: monospace; background-color: rgb(250, 250, 250);">&nbs=
p;</span><span style=3D"font-family: monospace; background-color: rgb(250, =
250, 250); color: rgb(136, 0, 0);">// compilers are encouraged, but not req=
uired to reject this code</span><div><span style=3D"font-family: monospace;=
background-color: rgb(250, 250, 250); color: rgb(136, 0, 0);"><br></span><=
/div><div><span style=3D"font-family: monospace; background-color: rgb(250,=
250, 250); color: rgb(136, 0, 0);"><br></span></div><div><span style=3D"fo=
nt-family: monospace; background-color: rgb(250, 250, 250); color: rgb(136,=
0, 0);"><span style=3D"line-height: initial; background-color: rgb(255, 25=
5, 255); color: rgb(31, 73, 125); font-family: Calibri, 'Slate Pro', sans-s=
erif; font-size: initial; text-align: initial;"><br></span><br></span><span=
style=3D"font-family: sans-serif;">That shouldn't =E2=80=8Ebe I'll formed.=
If you define the behaviour of dynamic_cast to throw on data loss, then th=
is code is well defined to throw. Don't make extra rules when not required.=
Particularly rules that allow implementation divergence. </span></div=
><div><span style=3D"font-family: sans-serif;"><br></span></div><div><span =
style=3D"font-family: sans-serif;"><br></span></div><div><span style=3D"fon=
t-family: sans-serif;"><br></span><span style=3D"line-height: initial;"></s=
pan></div><div><div style=3D"font-size: initial; font-family: Calibri, 'Sla=
te Pro', sans-serif; color: rgb(31, 73, 125); text-align: initial; backgrou=
nd-color: rgb(255, 255, 255);">Sent from my BlackBerry 10 smartphone.</div>=
<div style=3D"display:none"></div><d=
iv style=3D"font-size: initial; text-align: initial; background-color: rgb(=
255, 255, 255);"><table width=3D"100%" style=3D"background-color:white; bor=
der-spacing:0px;"> <tbody><tr><td>=
</td><td id=3D"_separatorInternal" rowspan=3D"2" style=3D"text-align: cente=
r; font-size: initial; background-color: rgb(255, 255, 255);"> =
=
<span id=3D"_bb10TempSeparatorText" style=3D"background-color:white; co=
lor:#0073BC;font-size:smaller;font-family:"Slate Pro""> Ori=
ginal Message </span> </td></tr> =
=
<tr> <td colspan=3D"2">=
<div style=3D"border:none;border-top:solid #0073BC 1.0pt;"></div> =
=
</td></tr></tbody></table></div> =
=
<table width=3D"100%" style=3D"background-color:white;=
border-spacing:0px;"> <tbody><tr><td colspan=3D"2" style=3D"font-size: init=
ial; text-align: initial; background-color: rgb(255, 255, 255);"> =
<div style=3D"font-size: smaller;font-family:"Tahoma&=
quot;,"BB Alpha Sans","Slate Pro","sans-serif"=
;;"> <div><b>From: </b>Florian Weber</div><div><b>Sent: </b>Sunday, Novemb=
er 9, 2014 4:43 PM</div><div><b>To: </b>std-proposals@isocpp.org</div><div>=
<b>Reply To: </b>std-proposals@isocpp.org</div><div><b>Subject: </b>Re: [st=
d-proposals] Extending Casts</div></div></td></tr></tbody></table><div styl=
e=3D"border-style: solid none none; border-top-color: rgb(186, 188, 209); b=
order-top-width: 1pt; font-size: initial; text-align: initial; background-c=
olor: rgb(255, 255, 255);"></div><br><div id=3D"_originalContent" style=3D"=
"><div dir=3D"ltr"><br><blockquote class=3D"gmail_quote" style=3D"margin: 0=
;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">Using l=
iterals (i.e. constexpr) in
your examples doesn't help the cause, because those cases would already be
caught when using brace-initialization<br></blockquote><div><br>It was of c=
ourse only meant as an example, but you are right, it is chosen quite badly=
.. In fact I think that the code should definitely be ill-formed if the comp=
iler can proof, that the cast won't succeed. I would like to encourage that=
behavior even in non-constexpr-contexts, like this:<br><br><div class=3D"p=
rettyprint" style=3D"background-color: rgb(250, 250, 250); border-color: rg=
b(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: break-=
word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> x </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> std</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">int16_t</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">{</span><span style=3D"color: #066;" class=3D"styled-by-pretti=
fy">1000</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">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"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">dynamic_cast</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify"><</span><span style=3D"color: #000;" cl=
ass=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-b=
y-prettify">int8_t</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">>(</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">x</span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #800;" class=3D"styled-by-prettify">// compilers are encour=
aged, but not required to reject this code.</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br></span></div></code></div><br>The reas=
on is simply that I wouldn't use a checked_cast, If I wouldn't want to make=
sure, that I get a valid value.<br><br>A better example for how it should =
work would be this:<br><br><div class=3D"prettyprint" style=3D"background-c=
olor: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: s=
olid; border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint=
"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"style=
d-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> some_fun</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">();</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br><br></span><span style=3D"color: #800;" class=3D"styled-by-prettify">//=
...</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><b=
r></span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">var</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">dynamic_cast</span><span style=3D"color: #080;" cla=
ss=3D"styled-by-prettify"><short></span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify">some_fun</span><span style=3D"color: #660;" class=3D"st=
yled-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">// throw if some_fun() is not representable as short</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></code></di=
v></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>
<br><!--end of _originalContent --></div></div></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 />
.