Topic: Allow forward class declarations to match a type alias.
Author: Bengt Gustafsson <bengt.gustafsson@beamways.com>
Date: Fri, 29 Jun 2018 00:56:26 -0700 (PDT)
Raw View
------=_Part_10954_67878902.1530258986119
Content-Type: multipart/alternative;
boundary="----=_Part_10955_1719410585.1530258986120"
------=_Part_10955_1719410585.1530258986120
Content-Type: text/plain; charset="UTF-8"
A forward declaration of a class name is currently not allowed to be
resolved by a type alias of a class template. I don't see the logic to
this, why is this illegal:
// forward declaration in one header file.
class FloatImage;
// Definition in another header file.
template<typename T> class CudaImage {
};
using FloatImage = CudaImage<float>;
Godbolt: https://godbolt.org/g/mmTTeQ shows that all compilers reject this.
This has created a fair amount of trouble for me when trying to refactor
what was previously a FloatImage class to a generic pixel type template. I
don't see the logic to making this
illegal as FloatImage is still the name of a class, i.e. an instance of the
CudaImage class template.
While I can update the forward declaration to:
// forward declaration in one header file.
template<typename T> class CudaImage;
using FloatImage = CudaImage<float>;
This seems to be an unnecessary leakage of implementation detail.
so is there a technical reason preventing this from being allowed or is it
just an oversight that could be corrected?
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/b2fb570b-aadb-423e-9821-025cb447cf60%40isocpp.org.
------=_Part_10955_1719410585.1530258986120
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">A forward declaration of a class name is currently not all=
owed to be resolved by a type alias of a class template. I don't see th=
e logic to this, why is this illegal:<div><br></div><div><div style=3D"colo=
r: #000000;background-color: #fffffe;font-family: Consolas, " liberation=3D=
"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;font-size:=
=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D""><div liberat=
ion=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;font-=
size:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D""><div cl=
ass=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-c=
olor: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap=
: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><s=
pan style=3D"color: #800;" class=3D"styled-by-prettify">// forward declarat=
ion in one header file.</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">class</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">FloatIm=
age</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></sp=
an><span style=3D"color: #800;" class=3D"styled-by-prettify">// Definition =
in another header file.</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">template</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify"><</span><span style=3D"color: #008;" class=3D"styled-by-prettify">t=
ypename</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> T<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">></span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #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">CudaImage</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><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">=
using</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #606;" class=3D"styled-by-prettify">FloatImage</sp=
an><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=
: #606;" class=3D"styled-by-prettify">CudaImage</span><span style=3D"color:=
#080;" class=3D"styled-by-prettify"><float></span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br></span></div></code></div><br><br>Godbol=
t:=C2=A0https://godbolt.org/g/mmTTeQ shows that all compilers reject this.<=
/div><div liberation=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=
=3D"" normal;font-size:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" =
pre;"=3D""><br></div><div liberation=3D"" mono",=3D"" courier,=3D"" monospa=
ce;font-weight:=3D"" normal;font-size:=3D"" 14px;line-height:=3D"" 19px;whi=
te-space:=3D"" pre;"=3D"">This has=C2=A0 created a fair amount of trouble f=
or me when trying to refactor what was previously a FloatImage class to a g=
eneric pixel type template. I don't see the logic to making this</div><=
div liberation=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" n=
ormal;font-size:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=
=3D"">illegal as FloatImage is still the name of a class, i.e. an instance =
of the CudaImage class template.</div><div liberation=3D"" mono",=3D"" cour=
ier,=3D"" monospace;font-weight:=3D"" normal;font-size:=3D"" 14px;line-heig=
ht:=3D"" 19px;white-space:=3D"" pre;"=3D""><br></div><div liberation=3D"" m=
ono",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;font-size:=3D""=
14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D"">While I can updat=
e the forward declaration to:</div><div class=3D"prettyprint" style=3D"back=
ground-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-=
style: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"pre=
ttyprint"><div class=3D"subprettyprint"><span style=3D"color: #800;" class=
=3D"styled-by-prettify">// forward declaration in one header file.</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">template</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> T</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">class</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettif=
y">CudaImage</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">using</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #606;" class=3D"styled-by-prettify">FloatImage</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </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: #606;" class=
=3D"styled-by-prettify">CudaImage</span><span style=3D"color: #080;" class=
=3D"styled-by-prettify"><float></span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br></span></div></code></div><div liberation=3D"" mono",=
=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;font-size:=3D"" 14px=
;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D""><div liberation=3D"" m=
ono",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;font-size:=3D""=
14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D""><br>This seems to=
be an unnecessary leakage of implementation detail.</div><div liberation=
=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;font-siz=
e:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D""><br></div>=
<div liberation=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" =
normal;font-size:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=
=3D"">so is there a technical reason preventing this from being allowed or =
is it just an oversight that could be corrected?</div><div liberation=3D"" =
mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;font-size:=3D"=
" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D""><br></div></div>=
</div></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/b2fb570b-aadb-423e-9821-025cb447cf60%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/b2fb570b-aadb-423e-9821-025cb447cf60=
%40isocpp.org</a>.<br />
------=_Part_10955_1719410585.1530258986120--
------=_Part_10954_67878902.1530258986119--
.
Author: mihailnajdenov@gmail.com
Date: Fri, 29 Jun 2018 01:48:26 -0700 (PDT)
Raw View
------=_Part_11175_15024228.1530262106687
Content-Type: multipart/alternative;
boundary="----=_Part_11176_1127489972.1530262106688"
------=_Part_11176_1127489972.1530262106688
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
We have to see what is the situation after Modules.=20
For now your best bet is to actually create a class=20
class FloatImage : public CudaImage<float> { /*using =E2=80=A6*/ };
On Friday, June 29, 2018 at 10:56:26 AM UTC+3, Bengt Gustafsson wrote:
>
> A forward declaration of a class name is currently not allowed to be=20
> resolved by a type alias of a class template. I don't see the logic to=20
> this, why is this illegal:
>
> // forward declaration in one header file.
> class FloatImage;
>
>
> // Definition in another header file.
> template<typename T> class CudaImage {
> };
>
> using FloatImage =3D CudaImage<float>;
>
>
> Godbolt: https://godbolt.org/g/mmTTeQ shows that all compilers reject=20
> this.
>
> This has created a fair amount of trouble for me when trying to refactor=
=20
> what was previously a FloatImage class to a generic pixel type template. =
I=20
> don't see the logic to making this
> illegal as FloatImage is still the name of a class, i.e. an instance of=
=20
> the CudaImage class template.
>
> While I can update the forward declaration to:
> // forward declaration in one header file.
> template<typename T> class CudaImage;
> using FloatImage =3D CudaImage<float>;
>
> This seems to be an unnecessary leakage of implementation detail.
>
> so is there a technical reason preventing this from being allowed or is i=
t=20
> just an oversight that could be corrected?
>
>
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/975ab4cd-2ff0-4a09-9fac-7c37dc67cf16%40isocpp.or=
g.
------=_Part_11176_1127489972.1530262106688
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>We have to see what is the situation after Modules.=
=C2=A0</div><div><br></div><div>For now your best bet is to actually create=
a class=C2=A0<span style=3D"background-color: transparent; border-bottom-c=
olor: rgb(0, 0, 0); border-bottom-style: none; border-bottom-width: 0px; bo=
rder-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100=
%; border-image-source: none; border-image-width: 1; border-left-color: rgb=
(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-co=
lor: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; borde=
r-top-color: rgb(0, 0, 0); border-top-style: none; border-top-width: 0px; c=
olor: rgb(0, 0, 0); font-family: &quot;Arial&quot;,&quot;Helvet=
ica&quot;,sans-serif; font-size: 13px; font-style: normal; font-variant=
: normal; font-weight: 400; letter-spacing: normal; margin-bottom: 0px; mar=
gin-left: 0px; margin-right: 0px; margin-top: 0px; orphans: 2; padding-bott=
om: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-alig=
n: left; text-decoration: none; text-indent: 0px; text-transform: none; -we=
bkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"><br s=
tyle=3D"border-bottom-color: rgb(0, 0, 0); border-bottom-style: none; borde=
r-bottom-width: 0px; border-image-outset: 0; border-image-repeat: stretch; =
border-image-slice: 100%; border-image-source: none; border-image-width: 1;=
border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-widt=
h: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-=
right-width: 0px; border-top-color: rgb(0, 0, 0); border-top-style: none; b=
order-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0=
px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right:=
0px; padding-top: 0px;"></span><font face=3D"courier new,monospace">class =
FloatImage : public CudaImage<float> { /*using =E2=80=A6*/ };</font><=
/div><div><b></b><i></i><u></u><sub></sub><sup></sup><strike></strike><font=
face=3D"courier new,monospace"></font><br></div><div><br></div>On Friday, =
June 29, 2018 at 10:56:26 AM UTC+3, Bengt Gustafsson wrote:<blockquote clas=
s=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #c=
cc solid;padding-left: 1ex;"><div dir=3D"ltr">A forward declaration of a cl=
ass name is currently not allowed to be resolved by a type alias of a class=
template. I don't see the logic to this, why is this illegal:<div><br>=
</div><div><div><div><div style=3D"background-color:rgb(250,250,250);border=
-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:break=
-word"><code><div><span style=3D"color:#800">// forward declaration in one =
header file.</span><span style=3D"color:#000"><br></span><span style=3D"col=
or:#008">class</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#606">FloatImage</span><span style=3D"color:#660">;</span><span style=3D"=
color:#000"><br><br><br></span><span style=3D"color:#800">// Definition in =
another header file.</span><span style=3D"color:#000"><br></span><span styl=
e=3D"color:#008">template</span><span style=3D"color:#660"><</span><span=
style=3D"color:#008">typename</span><span style=3D"color:#000"> T</span><s=
pan style=3D"color:#660">></span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#008">class</span><span style=3D"color:#000"> </span><span=
style=3D"color:#606">CudaImage</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#660">{</span><span style=3D"color:#000"><br></span><spa=
n style=3D"color:#660">};</span><span style=3D"color:#000"><br><br></span><=
span style=3D"color:#008">using</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#606">FloatImage</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><=
span style=3D"color:#606">CudaImage</span><span style=3D"color:#080"><fl=
oat></span><span style=3D"color:#660">;</span><span style=3D"color:#000"=
><br></span></div></code></div><br><br>Godbolt:=C2=A0<a onmousedown=3D"this=
..href=3D'https://www.google.com/url?q\x3dhttps%3A%2F%2Fgodbolt.org%2Fg%=
2FmmTTeQ\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGG_TM3xx2LQXaJgPxoHe9hGxPK=
Wg';return true;" onclick=3D"this.href=3D'https://www.google.com/ur=
l?q\x3dhttps%3A%2F%2Fgodbolt.org%2Fg%2FmmTTeQ\x26sa\x3dD\x26sntz\x3d1\x26us=
g\x3dAFQjCNGG_TM3xx2LQXaJgPxoHe9hGxPKWg';return true;" href=3D"https://=
godbolt.org/g/mmTTeQ" target=3D"_blank" rel=3D"nofollow">https://godbolt.or=
g/<wbr>g/mmTTeQ</a> shows that all compilers reject this.</div><div><br></d=
iv><div>This has=C2=A0 created a fair amount of trouble for me when trying =
to refactor what was previously a FloatImage class to a generic pixel type =
template. I don't see the logic to making this</div><div>illegal as Flo=
atImage is still the name of a class, i.e. an instance of the CudaImage cla=
ss template.</div><div><br></div><div>While I can update the forward declar=
ation to:</div><div style=3D"background-color:rgb(250,250,250);border-color=
:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:break-word"=
><code><div><span style=3D"color:#800">// forward declaration in one header=
file.</span><span style=3D"color:#000"><br></span><span style=3D"color:#00=
8">template</span><span style=3D"color:#660"><</span><span style=3D"colo=
r:#008">typename</span><span style=3D"color:#000"> T</span><span style=3D"c=
olor:#660">></span><span style=3D"color:#000"> </span><span style=3D"col=
or:#008">class</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#606">CudaImage</span><span style=3D"color:#660">;</span><span style=3D"c=
olor:#000"><br></span><span style=3D"color:#008">using</span><span style=3D=
"color:#000"> </span><span style=3D"color:#606">FloatImage</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#660">=3D</span><span style=
=3D"color:#000"> </span><span style=3D"color:#606">CudaImage</span><span st=
yle=3D"color:#080"><float></span><span style=3D"color:#660">;</span><=
span style=3D"color:#000"><br></span></div></code></div><div><div><br>This =
seems to be an unnecessary leakage of implementation detail.</div><div><br>=
</div><div>so is there a technical reason preventing this from being allowe=
d or is it just an oversight that could be corrected?</div><div><br></div><=
/div></div></div></div></blockquote></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/975ab4cd-2ff0-4a09-9fac-7c37dc67cf16%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/975ab4cd-2ff0-4a09-9fac-7c37dc67cf16=
%40isocpp.org</a>.<br />
------=_Part_11176_1127489972.1530262106688--
------=_Part_11175_15024228.1530262106687--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Fri, 29 Jun 2018 08:41:10 -0700 (PDT)
Raw View
------=_Part_13432_1928334801.1530286870502
Content-Type: multipart/alternative;
boundary="----=_Part_13433_1843940901.1530286870502"
------=_Part_13433_1843940901.1530286870502
Content-Type: text/plain; charset="UTF-8"
On Friday, June 29, 2018 at 3:56:26 AM UTC-4, Bengt Gustafsson wrote:
>
> A forward declaration of a class name is currently not allowed to be
> resolved by a type alias of a class template. I don't see the logic to
> this, why is this illegal:
>
> // forward declaration in one header file.
> class FloatImage;
>
>
> // Definition in another header file.
> template<typename T> class CudaImage {
> };
>
> using FloatImage = CudaImage<float>;
>
>
OK, so you want to say that `FloatImage` is a class, then you want to say
it's a type alias. Does that not seem... incoherent to you?
Is `is_class_v<FloatImage>` supposed to be true or false? After all, you
could have done `using FloatImage = int;` later on, which would change the
result. Or you could do `using FloatImage = SomeUnionType;`, which again
changes the result.
Remember: incomplete types can be used to instantiate a lot of the type
traits. `class FloatImage` is not the same thing as "hey compiler, there's
a typename called `FloatImage`, but you can't use it for anything right
now." If you want to be able to say that, then you need a new kind of type
name. Right now, types can be complete (meaning the full definition is
available) or incomplete (meaning that the full definition is not
available, but we do know *something* about it). You want a third category,
where we no nothing more than that a name is a type.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/94a61631-75a1-4972-b30b-095e30360f55%40isocpp.org.
------=_Part_13433_1843940901.1530286870502
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Friday, June 29, 2018 at 3:56:26 AM UTC-4, Beng=
t Gustafsson wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;mar=
gin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D=
"ltr">A forward declaration of a class name is currently not allowed to be =
resolved by a type alias of a class template. I don't see the logic to =
this, why is this illegal:<div><br></div><div><div><div><div style=3D"backg=
round-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:sol=
id;border-width:1px;word-wrap:break-word"><code><div><span style=3D"color:#=
800">// forward declaration in one header file.</span><span style=3D"color:=
#000"><br></span><span style=3D"color:#008">class</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#606">FloatImage</span><span style=3D"=
color:#660">;</span><span style=3D"color:#000"><br><br><br></span><span sty=
le=3D"color:#800">// Definition in another header file.</span><span style=
=3D"color:#000"><br></span><span style=3D"color:#008">template</span><span =
style=3D"color:#660"><</span><span style=3D"color:#008">typename</span><=
span style=3D"color:#000"> T</span><span style=3D"color:#660">></span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#008">class</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#606">CudaImage</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#660">{</span><span=
style=3D"color:#000"><br></span><span style=3D"color:#660">};</span><span =
style=3D"color:#000"><br><br></span><span style=3D"color:#008">using</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#606">FloatImage</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#660">=3D</span=
><span style=3D"color:#000"> </span><span style=3D"color:#606">CudaImage</s=
pan><span style=3D"color:#080"><float></span><span style=3D"color:#66=
0">;</span><span style=3D"color:#000"><br></span></div></code></div><br></d=
iv></div></div></div></blockquote><div><br></div><div>OK, so you want to sa=
y that `FloatImage` is a class, then you want to say it's a type alias.=
Does that not seem... incoherent to you?</div><div><br></div><div>Is `is_c=
lass_v<FloatImage>` supposed to be true or false? After all, you coul=
d have done `using FloatImage =3D int;` later on, which would change the re=
sult. Or you could do `using FloatImage =3D SomeUnionType;`, which again ch=
anges the result.</div><div><br></div><div>Remember: incomplete types can b=
e used to instantiate a lot of the type traits. `class FloatImage` is not t=
he same thing as "hey compiler, there's a typename called `FloatIm=
age`, but you can't use it for anything right now." If you want to=
be able to say that, then you need a new kind of type name. Right now, typ=
es can be complete (meaning the full definition is available) or incomplete=
(meaning that the full definition is not available, but we do know <i>some=
thing</i> about it). You want a third category, where we no nothing more th=
an that a name is a type.<br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/94a61631-75a1-4972-b30b-095e30360f55%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/94a61631-75a1-4972-b30b-095e30360f55=
%40isocpp.org</a>.<br />
------=_Part_13433_1843940901.1530286870502--
------=_Part_13432_1928334801.1530286870502--
.
Author: Richard Hodges <hodges.r@gmail.com>
Date: Fri, 29 Jun 2018 18:42:53 +0200
Raw View
--000000000000bd76c3056fca8a75
Content-Type: text/plain; charset="UTF-8"
I am wondering if your motivation is an XY problem, please see inline.
On Fri, 29 Jun 2018 at 09:56, Bengt Gustafsson <
bengt.gustafsson@beamways.com> wrote:
> A forward declaration of a class name is currently not allowed to be
> resolved by a type alias of a class template. I don't see the logic to
> this, why is this illegal:
>
> // forward declaration in one header file.
> class FloatImage;
>
>
> // Definition in another header file.
> template<typename T> class CudaImage {
> };
>
> using FloatImage = CudaImage<float>;
>
>
> Godbolt: https://godbolt.org/g/mmTTeQ shows that all compilers reject
> this.
>
> This has created a fair amount of trouble for me when trying to refactor
> what was previously a FloatImage class to a generic pixel type template. I
> don't see the logic to making this
> illegal as FloatImage is still the name of a class, i.e. an instance of
> the CudaImage class template.
>
It seems to me that you previously forward-declared the class FloatImage,
which was later defined.
The might have looked like this:
class FloatImage;
// we can reference the type before definition
extern void foo(FloatImage& fi);
Later, before using a FloatImage, you would define the class.
The new code would need to look like this:
template<typename T> class CudaImage;
using FloatImage = CudaImage<float>;
// we can *still* reference the type before definition
extern void foo(FloatImage& fi);
Later, but before actually using a FloatImage, you would define the
template:
template<class T> class CudaImage
{
};
>
> While I can update the forward declaration to:
> // forward declaration in one header file.
> template<typename T> class CudaImage;
> using FloatImage = CudaImage<float>;
>
> This seems to be an unnecessary leakage of implementation detail.
>
I think the above solution resolves this leakage.
>
> so is there a technical reason preventing this from being allowed or is it
> just an oversight that could be corrected?
>
I don't think in reality that it's needed, or that the lack of the feature
is an oversight.
> --
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> To view this discussion on the web visit
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/b2fb570b-aadb-423e-9821-025cb447cf60%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/b2fb570b-aadb-423e-9821-025cb447cf60%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CALvx3hbmq1NUgE3njDeLLrmVX%3DGwAVfsUK-T7spZZFmgk_vmUg%40mail.gmail.com.
--000000000000bd76c3056fca8a75
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I am wondering if your motivation is an XY problem, please=
see inline.<br><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Fri, 29 =
Jun 2018 at 09:56, Bengt Gustafsson <<a href=3D"mailto:bengt.gustafsson@=
beamways.com">bengt.gustafsson@beamways.com</a>> wrote:<br></div><blockq=
uote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc =
solid;padding-left:1ex"><div dir=3D"ltr">A forward declaration of a class n=
ame is currently not allowed to be resolved by a type alias of a class temp=
late. I don't see the logic to this, why is this illegal:<div><br></div=
><div><div><div><div class=3D"m_-6556502269256549060prettyprint" style=3D"b=
ackground-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style=
:solid;border-width:1px;word-wrap:break-word"><code class=3D"m_-65565022692=
56549060prettyprint"><div class=3D"m_-6556502269256549060subprettyprint"><s=
pan style=3D"color:#800" class=3D"m_-6556502269256549060styled-by-prettify"=
>// forward declaration in one header file.</span><span style=3D"color:#000=
" class=3D"m_-6556502269256549060styled-by-prettify"><br></span><span style=
=3D"color:#008" class=3D"m_-6556502269256549060styled-by-prettify">class</s=
pan><span style=3D"color:#000" class=3D"m_-6556502269256549060styled-by-pre=
ttify"> </span><span style=3D"color:#606" class=3D"m_-6556502269256549060st=
yled-by-prettify">FloatImage</span><span style=3D"color:#660" class=3D"m_-6=
556502269256549060styled-by-prettify">;</span><span style=3D"color:#000" cl=
ass=3D"m_-6556502269256549060styled-by-prettify"><br><br><br></span><span s=
tyle=3D"color:#800" class=3D"m_-6556502269256549060styled-by-prettify">// D=
efinition in another header file.</span><span style=3D"color:#000" class=3D=
"m_-6556502269256549060styled-by-prettify"><br></span><span style=3D"color:=
#008" class=3D"m_-6556502269256549060styled-by-prettify">template</span><sp=
an style=3D"color:#660" class=3D"m_-6556502269256549060styled-by-prettify">=
<</span><span style=3D"color:#008" class=3D"m_-6556502269256549060styled=
-by-prettify">typename</span><span style=3D"color:#000" class=3D"m_-6556502=
269256549060styled-by-prettify"> T</span><span style=3D"color:#660" class=
=3D"m_-6556502269256549060styled-by-prettify">></span><span style=3D"col=
or:#000" class=3D"m_-6556502269256549060styled-by-prettify"> </span><span s=
tyle=3D"color:#008" class=3D"m_-6556502269256549060styled-by-prettify">clas=
s</span><span style=3D"color:#000" class=3D"m_-6556502269256549060styled-by=
-prettify"> </span><span style=3D"color:#606" class=3D"m_-65565022692565490=
60styled-by-prettify">CudaImage</span><span style=3D"color:#000" class=3D"m=
_-6556502269256549060styled-by-prettify"> </span><span style=3D"color:#660"=
class=3D"m_-6556502269256549060styled-by-prettify">{</span><span style=3D"=
color:#000" class=3D"m_-6556502269256549060styled-by-prettify"><br></span><=
span style=3D"color:#660" class=3D"m_-6556502269256549060styled-by-prettify=
">};</span><span style=3D"color:#000" class=3D"m_-6556502269256549060styled=
-by-prettify"><br><br></span><span style=3D"color:#008" class=3D"m_-6556502=
269256549060styled-by-prettify">using</span><span style=3D"color:#000" clas=
s=3D"m_-6556502269256549060styled-by-prettify"> </span><span style=3D"color=
:#606" class=3D"m_-6556502269256549060styled-by-prettify">FloatImage</span>=
<span style=3D"color:#000" class=3D"m_-6556502269256549060styled-by-prettif=
y"> </span><span style=3D"color:#660" class=3D"m_-6556502269256549060styled=
-by-prettify">=3D</span><span style=3D"color:#000" class=3D"m_-655650226925=
6549060styled-by-prettify"> </span><span style=3D"color:#606" class=3D"m_-6=
556502269256549060styled-by-prettify">CudaImage</span><span style=3D"color:=
#080" class=3D"m_-6556502269256549060styled-by-prettify"><float></spa=
n><span style=3D"color:#660" class=3D"m_-6556502269256549060styled-by-prett=
ify">;</span><span style=3D"color:#000" class=3D"m_-6556502269256549060styl=
ed-by-prettify"><br></span></div></code></div><br><br>Godbolt:=C2=A0<a href=
=3D"https://godbolt.org/g/mmTTeQ" target=3D"_blank">https://godbolt.org/g/m=
mTTeQ</a> shows that all compilers reject this.</div><div><br></div><div>Th=
is has=C2=A0 created a fair amount of trouble for me when trying to refacto=
r what was previously a FloatImage class to a generic pixel type template. =
I don't see the logic to making this</div><div>illegal as FloatImage is=
still the name of a class, i.e. an instance of the CudaImage class templat=
e.</div></div></div></div></blockquote><div><br></div><div>It seems to me t=
hat you previously forward-declared the class FloatImage, which was later d=
efined.</div><div><br></div><div>The might have looked like this:</div><div=
><br></div><div><font face=3D"monospace, monospace">class FloatImage;</font=
></div><div><div style=3D"color:rgb(0,0,0);background-color:rgb(255,255,254=
)"><div><span style=3D"color:rgb(0,128,0)"><font face=3D"monospace, monospa=
ce">// we can reference the type before definition</font></span></div><div>=
<font face=3D"monospace, monospace"><span style=3D"color:rgb(0,0,255)">exte=
rn</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(=
0,0,255)">void</span><span style=3D"color:rgb(0,0,0)"> foo(FloatImage& =
fi);</span></font></div><br></div><br></div><div>Later, before using a <fon=
t face=3D"monospace, monospace">FloatImage</font>, you would define the cla=
ss.</div><div><br></div><div>The new code would need to look like this:</di=
v><div><br></div><div><font face=3D"monospace, monospace">template<typen=
ame T> class CudaImage;</font></div><div><font face=3D"monospace, monosp=
ace">using FloatImage =3D CudaImage<float>;</font></div><div><div sty=
le=3D"color:rgb(0,0,0);text-decoration-style:initial;text-decoration-color:=
initial"><span style=3D"color:rgb(0,128,0)"><font face=3D"monospace, monosp=
ace">// we can *still* reference the type before definition</font></span></=
div><div style=3D"color:rgb(0,0,0);text-decoration-style:initial;text-decor=
ation-color:initial"><font face=3D"monospace, monospace"><span style=3D"col=
or:rgb(0,0,255)">extern</span><span style=3D"color:rgb(0,0,0)"><span>=C2=A0=
</span></span><span style=3D"color:rgb(0,0,255)">void</span><span style=3D"=
color:rgb(0,0,0)"><span>=C2=A0</span>foo(FloatImage& fi);</span></font>=
</div><br class=3D"gmail-Apple-interchange-newline"><br></div><div>Later, b=
ut before actually using a <font face=3D"monospace, monospace">FloatImage</=
font>, you would define the template:</div><div><br></div><div><div style=
=3D"color:rgb(0,0,0);background-color:rgb(255,255,254)"><div><font face=3D"=
monospace, monospace"><span style=3D"color:rgb(0,0,255)">template</span><sp=
an style=3D"color:rgb(0,0,0)"><</span><span style=3D"color:rgb(0,0,255)"=
>class</span><span style=3D"color:rgb(0,0,0)"> T> </span><span style=3D"=
color:rgb(0,0,255)">class</span><span style=3D"color:rgb(0,0,0)"> CudaImage=
</span></font></div><div><span style=3D"color:rgb(0,0,0)"><font face=3D"mon=
ospace, monospace">{</font></span></div><div><span style=3D"color:rgb(0,0,0=
)"><font face=3D"monospace, monospace"> </font></span></div><div><span s=
tyle=3D"color:rgb(0,0,0)"><font face=3D"monospace, monospace">};</font></sp=
an></div></div></div><div><br></div><div>=C2=A0</div><blockquote class=3D"g=
mail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-l=
eft:1ex"><div dir=3D"ltr"><div><div><div><br></div><div>While I can update =
the forward declaration to:</div><div class=3D"m_-6556502269256549060pretty=
print" style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,=
187);border-style:solid;border-width:1px;word-wrap:break-word"><code class=
=3D"m_-6556502269256549060prettyprint"><div class=3D"m_-6556502269256549060=
subprettyprint"><span style=3D"color:#800" class=3D"m_-6556502269256549060s=
tyled-by-prettify">// forward declaration in one header file.</span><span s=
tyle=3D"color:#000" class=3D"m_-6556502269256549060styled-by-prettify"><br>=
</span><span style=3D"color:#008" class=3D"m_-6556502269256549060styled-by-=
prettify">template</span><span style=3D"color:#660" class=3D"m_-65565022692=
56549060styled-by-prettify"><</span><span style=3D"color:#008" class=3D"=
m_-6556502269256549060styled-by-prettify">typename</span><span style=3D"col=
or:#000" class=3D"m_-6556502269256549060styled-by-prettify"> T</span><span =
style=3D"color:#660" class=3D"m_-6556502269256549060styled-by-prettify">>=
;</span><span style=3D"color:#000" class=3D"m_-6556502269256549060styled-by=
-prettify"> </span><span style=3D"color:#008" class=3D"m_-65565022692565490=
60styled-by-prettify">class</span><span style=3D"color:#000" class=3D"m_-65=
56502269256549060styled-by-prettify"> </span><span style=3D"color:#606" cla=
ss=3D"m_-6556502269256549060styled-by-prettify">CudaImage</span><span style=
=3D"color:#660" class=3D"m_-6556502269256549060styled-by-prettify">;</span>=
<span style=3D"color:#000" class=3D"m_-6556502269256549060styled-by-prettif=
y"><br></span><span style=3D"color:#008" class=3D"m_-6556502269256549060sty=
led-by-prettify">using</span><span style=3D"color:#000" class=3D"m_-6556502=
269256549060styled-by-prettify"> </span><span style=3D"color:#606" class=3D=
"m_-6556502269256549060styled-by-prettify">FloatImage</span><span style=3D"=
color:#000" class=3D"m_-6556502269256549060styled-by-prettify"> </span><spa=
n style=3D"color:#660" class=3D"m_-6556502269256549060styled-by-prettify">=
=3D</span><span style=3D"color:#000" class=3D"m_-6556502269256549060styled-=
by-prettify"> </span><span style=3D"color:#606" class=3D"m_-655650226925654=
9060styled-by-prettify">CudaImage</span><span style=3D"color:#080" class=3D=
"m_-6556502269256549060styled-by-prettify"><float></span><span style=
=3D"color:#660" class=3D"m_-6556502269256549060styled-by-prettify">;</span>=
<span style=3D"color:#000" class=3D"m_-6556502269256549060styled-by-prettif=
y"><br></span></div></code></div><div><div><br>This seems to be an unnecess=
ary leakage of implementation detail.</div></div></div></div></div></blockq=
uote><div><br></div><div>I think the above solution resolves this leakage.<=
/div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0=
0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>=
<div><div><div><br></div><div>so is there a technical reason preventing thi=
s from being allowed or is it just an oversight that could be corrected?</d=
iv></div></div></div></div></blockquote><div><br></div><div>I don't thi=
nk in reality that it's needed, or that the lack of the feature is an o=
versight.</div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"=
margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"=
ltr"><div><div><div><div></div></div></div></div></div>
<p></p>
-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" 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>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/b2fb570b-aadb-423e-9821-025cb447cf60%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/b2fb570b-aadb-=
423e-9821-025cb447cf60%40isocpp.org</a>.<br>
</blockquote></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CALvx3hbmq1NUgE3njDeLLrmVX%3DGwAVfsUK=
-T7spZZFmgk_vmUg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CALvx3hbmq1NUgE=
3njDeLLrmVX%3DGwAVfsUK-T7spZZFmgk_vmUg%40mail.gmail.com</a>.<br />
--000000000000bd76c3056fca8a75--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Fri, 29 Jun 2018 11:03:08 -0700 (PDT)
Raw View
------=_Part_14587_1248943783.1530295389029
Content-Type: multipart/alternative;
boundary="----=_Part_14588_632565338.1530295389029"
------=_Part_14588_632565338.1530295389029
Content-Type: text/plain; charset="UTF-8"
On Friday, June 29, 2018 at 12:43:07 PM UTC-4, Richard Hodges wrote:
>
> I am wondering if your motivation is an XY problem, please see inline.
>
It should also be noted that reflection will be able to see the difference
between the use of a genuine typename and a type alias.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/a6b289f4-e15f-4330-afd5-31fc3a26cc56%40isocpp.org.
------=_Part_14588_632565338.1530295389029
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Friday, June 29, 2018 at 12:43:07 PM UTC-4, Richard Hod=
ges wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left:=
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">I a=
m wondering if your motivation is an XY problem, please see inline.<br></di=
v></blockquote><div><br></div><div>It should also be noted that reflection =
will be able to see the difference between the use of a genuine typename an=
d a type alias.</div><br></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/a6b289f4-e15f-4330-afd5-31fc3a26cc56%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/a6b289f4-e15f-4330-afd5-31fc3a26cc56=
%40isocpp.org</a>.<br />
------=_Part_14588_632565338.1530295389029--
------=_Part_14587_1248943783.1530295389029--
.
Author: Brian Bi <bbi5291@gmail.com>
Date: Fri, 29 Jun 2018 14:45:10 -0700
Raw View
--0000000000001b98b9056fcec3d8
Content-Type: text/plain; charset="UTF-8"
It's not an oversight. It's a design decision that "class FloatImage;"
forward-declares a class whose *identity* is known; its true name is
FloatImage (in the same namespace). It is already known not to be identical
with CudaImage<float>. Saying that it is, later, is contradicting what you
told the compiler earlier.
As Nicol Bolas says, you need a third type of declaration to do what you
want to do.
On Fri, Jun 29, 2018 at 12:56 AM, Bengt Gustafsson <
bengt.gustafsson@beamways.com> wrote:
> A forward declaration of a class name is currently not allowed to be
> resolved by a type alias of a class template. I don't see the logic to
> this, why is this illegal:
>
> // forward declaration in one header file.
> class FloatImage;
>
>
> // Definition in another header file.
> template<typename T> class CudaImage {
> };
>
> using FloatImage = CudaImage<float>;
>
>
> Godbolt: https://godbolt.org/g/mmTTeQ shows that all compilers reject
> this.
>
> This has created a fair amount of trouble for me when trying to refactor
> what was previously a FloatImage class to a generic pixel type template. I
> don't see the logic to making this
> illegal as FloatImage is still the name of a class, i.e. an instance of
> the CudaImage class template.
>
> While I can update the forward declaration to:
> // forward declaration in one header file.
> template<typename T> class CudaImage;
> using FloatImage = CudaImage<float>;
>
> This seems to be an unnecessary leakage of implementation detail.
>
> so is there a technical reason preventing this from being allowed or is it
> just an oversight that could be corrected?
>
> --
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> To view this discussion on the web visit https://groups.google.com/a/
> isocpp.org/d/msgid/std-proposals/b2fb570b-aadb-423e-
> 9821-025cb447cf60%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/b2fb570b-aadb-423e-9821-025cb447cf60%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>
--
*Brian Bi*
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAMmfjbNwyrk7D3wFqe7xxrOwED0AVMLz5_P9m1%3DS2WunjM1Lqg%40mail.gmail.com.
--0000000000001b98b9056fcec3d8
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>It's not an oversight. It's a design decision=
that "class FloatImage;" forward-declares a class whose <i>ident=
ity</i> is known; its true name is FloatImage (in the same namespace). It i=
s already known not to be identical with CudaImage<float>. Saying tha=
t it is, later, is contradicting what you told the compiler earlier.<br><br=
></div>As Nicol Bolas says, you need a third type of declaration to do what=
you want to do. <br></div><div class=3D"gmail_extra"><br><div class=3D"gma=
il_quote">On Fri, Jun 29, 2018 at 12:56 AM, Bengt Gustafsson <span dir=3D"l=
tr"><<a href=3D"mailto:bengt.gustafsson@beamways.com" target=3D"_blank">=
bengt.gustafsson@beamways.com</a>></span> wrote:<br><blockquote class=3D=
"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding=
-left:1ex"><div dir=3D"ltr">A forward declaration of a class name is curren=
tly not allowed to be resolved by a type alias of a class template. I don&#=
39;t see the logic to this, why is this illegal:<div><br></div><div><div><d=
iv><div class=3D"m_-3720303745785001123prettyprint" style=3D"background-col=
or:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border=
-width:1px;word-wrap:break-word"><code class=3D"m_-3720303745785001123prett=
yprint"><div class=3D"m_-3720303745785001123subprettyprint"><span style=3D"=
color:#800" class=3D"m_-3720303745785001123styled-by-prettify">// forward d=
eclaration in one header file.</span><span style=3D"color:#000" class=3D"m_=
-3720303745785001123styled-by-prettify"><br></span><span style=3D"color:#00=
8" class=3D"m_-3720303745785001123styled-by-prettify">class</span><span sty=
le=3D"color:#000" class=3D"m_-3720303745785001123styled-by-prettify"> </spa=
n><span style=3D"color:#606" class=3D"m_-3720303745785001123styled-by-prett=
ify">FloatImage</span><span style=3D"color:#660" class=3D"m_-37203037457850=
01123styled-by-prettify">;</span><span style=3D"color:#000" class=3D"m_-372=
0303745785001123styled-by-prettify"><br><br><br></span><span style=3D"color=
:#800" class=3D"m_-3720303745785001123styled-by-prettify">// Definition in =
another header file.</span><span style=3D"color:#000" class=3D"m_-372030374=
5785001123styled-by-prettify"><br></span><span style=3D"color:#008" class=
=3D"m_-3720303745785001123styled-by-prettify">template</span><span style=3D=
"color:#660" class=3D"m_-3720303745785001123styled-by-prettify"><</span>=
<span style=3D"color:#008" class=3D"m_-3720303745785001123styled-by-prettif=
y">typename</span><span style=3D"color:#000" class=3D"m_-372030374578500112=
3styled-by-prettify"> T</span><span style=3D"color:#660" class=3D"m_-372030=
3745785001123styled-by-prettify">></span><span style=3D"color:#000" clas=
s=3D"m_-3720303745785001123styled-by-prettify"> </span><span style=3D"color=
:#008" class=3D"m_-3720303745785001123styled-by-prettify">class</span><span=
style=3D"color:#000" class=3D"m_-3720303745785001123styled-by-prettify"> <=
/span><span style=3D"color:#606" class=3D"m_-3720303745785001123styled-by-p=
rettify">CudaImage</span><span style=3D"color:#000" class=3D"m_-37203037457=
85001123styled-by-prettify"> </span><span style=3D"color:#660" class=3D"m_-=
3720303745785001123styled-by-prettify">{</span><span style=3D"color:#000" c=
lass=3D"m_-3720303745785001123styled-by-prettify"><br></span><span style=3D=
"color:#660" class=3D"m_-3720303745785001123styled-by-prettify">};</span><s=
pan style=3D"color:#000" class=3D"m_-3720303745785001123styled-by-prettify"=
><br><br></span><span style=3D"color:#008" class=3D"m_-3720303745785001123s=
tyled-by-prettify">using</span><span style=3D"color:#000" class=3D"m_-37203=
03745785001123styled-by-prettify"> </span><span style=3D"color:#606" class=
=3D"m_-3720303745785001123styled-by-prettify">FloatImage</span><span style=
=3D"color:#000" class=3D"m_-3720303745785001123styled-by-prettify"> </span>=
<span style=3D"color:#660" class=3D"m_-3720303745785001123styled-by-prettif=
y">=3D</span><span style=3D"color:#000" class=3D"m_-3720303745785001123styl=
ed-by-prettify"> </span><span style=3D"color:#606" class=3D"m_-372030374578=
5001123styled-by-prettify">CudaImage</span><span style=3D"color:#080" class=
=3D"m_-3720303745785001123styled-by-prettify"><float></span><span sty=
le=3D"color:#660" class=3D"m_-3720303745785001123styled-by-prettify">;</spa=
n><span style=3D"color:#000" class=3D"m_-3720303745785001123styled-by-prett=
ify"><br></span></div></code></div><br><br>Godbolt:=C2=A0<a href=3D"https:/=
/godbolt.org/g/mmTTeQ" target=3D"_blank">https://godbolt.org/<wbr>g/mmTTeQ<=
/a> shows that all compilers reject this.</div><div><br></div><div>This has=
=C2=A0 created a fair amount of trouble for me when trying to refactor what=
was previously a FloatImage class to a generic pixel type template. I don&=
#39;t see the logic to making this</div><div>illegal as FloatImage is still=
the name of a class, i.e. an instance of the CudaImage class template.</di=
v><div><br></div><div>While I can update the forward declaration to:</div><=
div class=3D"m_-3720303745785001123prettyprint" style=3D"background-color:r=
gb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-wid=
th:1px;word-wrap:break-word"><code class=3D"m_-3720303745785001123prettypri=
nt"><div class=3D"m_-3720303745785001123subprettyprint"><span style=3D"colo=
r:#800" class=3D"m_-3720303745785001123styled-by-prettify">// forward decla=
ration in one header file.</span><span style=3D"color:#000" class=3D"m_-372=
0303745785001123styled-by-prettify"><br></span><span style=3D"color:#008" c=
lass=3D"m_-3720303745785001123styled-by-prettify">template</span><span styl=
e=3D"color:#660" class=3D"m_-3720303745785001123styled-by-prettify"><</s=
pan><span style=3D"color:#008" class=3D"m_-3720303745785001123styled-by-pre=
ttify">typename</span><span style=3D"color:#000" class=3D"m_-37203037457850=
01123styled-by-prettify"> T</span><span style=3D"color:#660" class=3D"m_-37=
20303745785001123styled-by-prettify">></span><span style=3D"color:#000" =
class=3D"m_-3720303745785001123styled-by-prettify"> </span><span style=3D"c=
olor:#008" class=3D"m_-3720303745785001123styled-by-prettify">class</span><=
span style=3D"color:#000" class=3D"m_-3720303745785001123styled-by-prettify=
"> </span><span style=3D"color:#606" class=3D"m_-3720303745785001123styled-=
by-prettify">CudaImage</span><span style=3D"color:#660" class=3D"m_-3720303=
745785001123styled-by-prettify">;</span><span style=3D"color:#000" class=3D=
"m_-3720303745785001123styled-by-prettify"><br></span><span style=3D"color:=
#008" class=3D"m_-3720303745785001123styled-by-prettify">using</span><span =
style=3D"color:#000" class=3D"m_-3720303745785001123styled-by-prettify"> </=
span><span style=3D"color:#606" class=3D"m_-3720303745785001123styled-by-pr=
ettify">FloatImage</span><span style=3D"color:#000" class=3D"m_-37203037457=
85001123styled-by-prettify"> </span><span style=3D"color:#660" class=3D"m_-=
3720303745785001123styled-by-prettify">=3D</span><span style=3D"color:#000"=
class=3D"m_-3720303745785001123styled-by-prettify"> </span><span style=3D"=
color:#606" class=3D"m_-3720303745785001123styled-by-prettify">CudaImage</s=
pan><span style=3D"color:#080" class=3D"m_-3720303745785001123styled-by-pre=
ttify"><float></span><span style=3D"color:#660" class=3D"m_-372030374=
5785001123styled-by-prettify">;</span><span style=3D"color:#000" class=3D"m=
_-3720303745785001123styled-by-prettify"><br></span></div></code></div><div=
><div><br>This seems to be an unnecessary leakage of implementation detail.=
</div><div><br></div><div>so is there a technical reason preventing this fr=
om being allowed or is it just an oversight that could be corrected?</div><=
span class=3D"HOEnZb"><font color=3D"#888888"><div><br></div></font></span>=
</div></div></div></div><span class=3D"HOEnZb"><font color=3D"#888888">
<p></p>
-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank">std-proposals+unsubscribe@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/b2fb570b-aadb-423e-9821-025cb447cf60%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/b2fb=
570b-aadb-423e-<wbr>9821-025cb447cf60%40isocpp.org</a><wbr>.<br>
</font></span></blockquote></div><br><br clear=3D"all"><br>-- <br><div clas=
s=3D"gmail_signature" data-smartmail=3D"gmail_signature"><div dir=3D"ltr"><=
div><div dir=3D"ltr"><font color=3D"#c0c0c0"><i>Brian Bi</i></font><br><div=
></div><div></div><div></div></div></div></div></div>
</div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAMmfjbNwyrk7D3wFqe7xxrOwED0AVMLz5_P9=
m1%3DS2WunjM1Lqg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAMmfjbNwyrk7D3=
wFqe7xxrOwED0AVMLz5_P9m1%3DS2WunjM1Lqg%40mail.gmail.com</a>.<br />
--0000000000001b98b9056fcec3d8--
.
Author: Jake Arkinstall <jake.arkinstall@gmail.com>
Date: Fri, 29 Jun 2018 23:45:09 +0100
Raw View
--000000000000442a5e056fcf9a12
Content-Type: text/plain; charset="UTF-8"
I had a similar refactoring once, and I approached it as follows. It might
not apply, But as this does seem like an XY problem to me I thought it best
to provide a potential solution.
The real problem is that you have code that depends on a class that doesn't
exist yet. Templates are your friend here. When you need to use FloatImage,
provide it as a template parameter. You then get the upshot of being able
to use your code with something other than a FloatImage in the future.
You can also give CudaImage a "using value_type = T". That way any class
which currently uses FloatImage can be given a template parameter T (which
in your current code would be provided with FloatImage) can accept
arguments of e.g. "typename T::value_type", and you aren't necessarily
locked into using floats as arguments if someone comes along and wants a
DoubleImage or something. If you want to restrict the types, concepts come
to the rescue.
If you have an API to preserve, rename the old classes and functions as
necessary, and expose the FloatImage-specialised versions under the
original names. If this doesn't sound like a convincing approach, the Eigen
library is a beautiful example (I'm not sure whether it is the result of a
refactor or of some brilliant foresight).
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAC%2B0CCMRC5JHx4N2JFzN960xfYsBVfKVt%3D7iSN5NCws3ALHkFA%40mail.gmail.com.
--000000000000442a5e056fcf9a12
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"auto"><div><div class=3D"gmail_quote"><div dir=3D"ltr">I had a =
similar refactoring once, and I approached it as follows. It might not appl=
y, But as this does seem like an XY problem to me I thought it best to prov=
ide a potential solution.</div><div dir=3D"ltr"><br></div><div dir=3D"ltr">=
The real problem is that you have code that depends on a class that doesn&#=
39;t exist yet. Templates are your friend here. When you need to use FloatI=
mage, provide it as a template parameter. You then get the upshot of being =
able to use your code with something other than a FloatImage in the future.=
</div></div></div><div dir=3D"auto"><br></div><div dir=3D"auto">You can als=
o give CudaImage a "using value_type =3D T". That way any class w=
hich currently uses FloatImage can be given a template parameter T (which i=
n your current code would be provided with FloatImage) can accept arguments=
of e.g. "typename T::value_type", and you aren't necessarily=
locked into using floats as arguments if someone comes along and wants a D=
oubleImage or something. If you want to restrict the types, concepts come t=
o the rescue.</div><div dir=3D"auto"><br></div><div dir=3D"auto">If you hav=
e an API to preserve, rename the old classes and functions as necessary, an=
d expose the FloatImage-specialised versions under the original names. If t=
his doesn't sound like a convincing approach, the Eigen library is a be=
autiful example (I'm not sure whether it is the result of a refactor or=
of some brilliant foresight).</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAC%2B0CCMRC5JHx4N2JFzN960xfYsBVfKVt%=
3D7iSN5NCws3ALHkFA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAC%2B0CCMRC5=
JHx4N2JFzN960xfYsBVfKVt%3D7iSN5NCws3ALHkFA%40mail.gmail.com</a>.<br />
--000000000000442a5e056fcf9a12--
.
Author: Bengt Gustafsson <bengt.gustafsson@beamways.com>
Date: Fri, 29 Jun 2018 23:49:52 -0700 (PDT)
Raw View
------=_Part_19358_978929154.1530341392742
Content-Type: text/plain; charset="UTF-8"
I got one good answer: it is not possible due to name mangling having to know that FloatImage will resolve to a template instance. I used the proposed solution but it unfortunately had me change the forward declarations of FloatImage.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/a4d20e97-3563-43c3-a1f9-a7b2e57276b4%40isocpp.org.
------=_Part_19358_978929154.1530341392742--
.
Author: mihailnajdenov@gmail.com
Date: Sat, 30 Jun 2018 00:52:30 -0700 (PDT)
Raw View
------=_Part_2807_1386991573.1530345151067
Content-Type: multipart/alternative;
boundary="----=_Part_2808_1546498443.1530345151067"
------=_Part_2808_1546498443.1530345151067
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On Saturday, June 30, 2018 at 9:49:52 AM UTC+3, Bengt Gustafsson wrote:
>
> I got one good answer: it is not possible due to name mangling having to=
=20
> know that FloatImage will resolve to a template instance. I used the=20
> proposed solution but it unfortunately had me change the forward=20
> declarations of FloatImage.=20
What solution did you use?=20
Did you try the concrete class solution - it is not as na=C3=AFve as it sou=
nds,=20
not as hard as it sounds (in C++11+) and has many protentional side=20
benefits.
Otherwise the classical solution is not to forward declare a class but to=
=20
have xxxfrw.h header instead, where you can put all "leakage of=20
implementation detail".=20
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/49cde8d1-312f-4c4c-a26e-91bbb1c56a2d%40isocpp.or=
g.
------=_Part_2808_1546498443.1530345151067
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Saturday, June 30, 2018 at 9:49:52 AM UTC+3, Be=
ngt Gustafsson wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">I got one=
good answer: it is not possible due to name mangling having to know that F=
loatImage will resolve to a template instance. I used the proposed solution=
but it unfortunately had me change the forward declarations of FloatImage.=
</blockquote><div><br></div><div>=C2=A0What solution did you use?=C2=A0</d=
iv><div>Did you try the concrete class solution - it is not as na=C3=AFve a=
s it sounds, not as hard as it sounds (in C++11+) and has many protentional=
side benefits.<br></div><div><br></div><div>Otherwise the classical soluti=
on is not to forward declare a class but to have xxxfrw.h header instead, w=
here you can put all "<span style=3D"display: inline !important; float=
: none; background-color: transparent; color: rgb(34, 34, 34); font-family:=
"Arial","Helvetica",sans-serif; font-size: 13px; font-=
style: normal; font-variant: normal; font-weight: 400; letter-spacing: norm=
al; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; =
text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; =
word-spacing: 0px;">leakage of implementation detail</span>".=C2=A0</d=
iv></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/49cde8d1-312f-4c4c-a26e-91bbb1c56a2d%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/49cde8d1-312f-4c4c-a26e-91bbb1c56a2d=
%40isocpp.org</a>.<br />
------=_Part_2808_1546498443.1530345151067--
------=_Part_2807_1386991573.1530345151067--
.
Author: Bengt Gustafsson <bengt.gustafsson@beamways.com>
Date: Sat, 30 Jun 2018 13:23:41 -0700 (PDT)
Raw View
------=_Part_24170_978999686.1530390221524
Content-Type: multipart/alternative;
boundary="----=_Part_24171_587172068.1530390221525"
------=_Part_24171_587172068.1530390221525
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
In my previous response I acknowedged the explanation that this has to do=
=20
with name mangling, where ultimately the class name would be mangled=20
according to its real identity, i.e. CudaImage<float> and thus that a=20
forward declaration "class FloatImage;" would be natural to reject.
However, on second thought, FloatImage just as any class name is not an=20
entity in itself that is known to the linker. And as you can't call methods=
=20
on a class without seeing its full definition there is no risk that=20
references to erroneously mangled method names sneak in to an object module=
=20
compiled only seeing the forward declaration, right? With this in mind, is=
=20
there a technical reason that=20
my initial construct must be forbidden? I don't see that Nicol's=20
explanation holds "FloatImage turns out eventually to be a type alias and=
=20
not a class". But the very reason for having a type alias is to give a=20
class another name, so why can't it be forward declared under this=20
alternate name? Of course, if it was eventually a non-class type (or a=20
variable or a function) the forward declaration would be erroneous, but=20
that's the peril we have with allowing forward declarations at all... if=20
they are in error there is no way to catch it... until modules, I guess.
I'm also considering this in the context of the proposed extension of alias=
=20
declarations to other types of entities such as functions and variables.=20
This has been touted as a way to avoid backwards compatibility issues, but=
=20
if we can't extern declare functions and variables under their now=20
deprecated names the utility of this feature is reduced as we would in some=
=20
cases have to "tamper" with the untouchable code base that made the aliases=
=20
necessary in the first place.
This said, it seems appropriate to ask if it would be possible to make the=
=20
alias names known to the linker so that function calls to the alias name=20
(allowed by a forward declaration of the function under its old name) can=
=20
be resolved. I don't think this would be a problem with any contemporary=20
linker/object file format, but maybe the language specification's concept=
=20
of a linker does not include such facilities.
At least this consideration and a chosen strategy should be part of a=20
generalized alias declaration proposal. Either such a strategy must mandate=
=20
that the linker knows of the function/global variable under both names or=
=20
it must show why this is not important even when claiming that the main=20
motivation for the feature is being able to deprecate old names without=20
having to change code using the entities under their old names. I guess=20
this is a matter of having to compile with new headers or having to link=20
with new libraries.
Den l=C3=B6rdag 30 juni 2018 kl. 09:52:31 UTC+2 skrev mihailn...@gmail.com:
>
>
>
> On Saturday, June 30, 2018 at 9:49:52 AM UTC+3, Bengt Gustafsson wrote:
>>
>> I got one good answer: it is not possible due to name mangling having to=
=20
>> know that FloatImage will resolve to a template instance. I used the=20
>> proposed solution but it unfortunately had me change the forward=20
>> declarations of FloatImage.=20
>
>
> What solution did you use?=20
>
I did update the forward declaration to the proposed:
template<typename T> class CudaImage;
using FloatImage =3D CudaImage<float>;
=20
> Did you try the concrete class solution - it is not as na=C3=AFve as it s=
ounds,=20
> not as hard as it sounds (in C++11+) and has many protentional side=20
> benefits.
>
No, I didn't. This would have worked with some amount of boilerplate, but I=
=20
wanted to see if I could do without this extraneous class.
=20
>
> Otherwise the classical solution is not to forward declare a class but to=
=20
> have xxxfrw.h header instead, where you can put all "leakage of=20
> implementation detail".
>
Sure, that would have been a possibility.
=20
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/abdf6051-28fa-48e6-81c6-20eff0a2d4de%40isocpp.or=
g.
------=_Part_24171_587172068.1530390221525
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">In my previous response I acknowedged the explanation that=
this has to do with name mangling, where ultimately the class name would b=
e mangled according to its real identity, i.e. CudaImage<float> and t=
hus that a forward declaration "class FloatImage;" would be natur=
al to reject.<div><br>However, on second thought, FloatImage just as any cl=
ass name is not an entity in itself that is known to the linker. And as you=
can't call methods on a class without seeing its full definition there=
is no risk that references to erroneously mangled method names sneak in to=
an object module compiled only seeing the forward declaration, right? With=
this in mind, is there a technical reason that=C2=A0</div><div><div>my ini=
tial construct must be forbidden? I don't see that Nicol's explanat=
ion holds "FloatImage turns out eventually to be a type alias and not =
a class". But the very reason for having a type alias is to give a cla=
ss another name, so why can't it be forward declared under this alterna=
te name? Of course, if it was eventually a non-class type (or a variable or=
a function) the forward declaration would be erroneous, but that's the=
peril we have with allowing forward declarations at all... if they are in =
error there is no way to catch it... until modules, I guess.</div><div><br>=
</div><div>I'm also considering this in the context of the proposed ext=
ension of alias declarations to other types of entities such as functions a=
nd variables. This has been touted as a way to avoid backwards compatibilit=
y issues, but if we can't extern declare functions and variables under =
their now deprecated names the utility of this feature is reduced as we wou=
ld in some cases have to "tamper" with the untouchable code base =
that made the aliases necessary in the first place.</div><div><br></div><di=
v>This said, it seems appropriate to ask if it would be possible to make th=
e alias names known to the linker so that function calls to the alias name =
(allowed by a forward declaration of the function under its old name) can b=
e resolved. I don't think this would be a problem with any contemporary=
linker/object file format, but maybe the language specification's conc=
ept of a linker does not include such facilities.</div><div><br></div><div>=
At least this consideration and a chosen strategy should be part of a gener=
alized alias declaration proposal. Either such a strategy must mandate that=
the linker knows of the function/global variable under both names or it mu=
st show why this is not important even when claiming that the main motivati=
on for the feature is being able to deprecate old names without having to c=
hange code using the entities under their old names. I guess this is a matt=
er of having to compile with new headers or having to link with new librari=
es.</div><div><br></div><div><br></div><div><br><div><br>Den l=C3=B6rdag 30=
juni 2018 kl. 09:52:31 UTC+2 skrev mihailn...@gmail.com:<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"><br><br>On Saturday, June 30, =
2018 at 9:49:52 AM UTC+3, Bengt Gustafsson wrote:<blockquote class=3D"gmail=
_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padd=
ing-left:1ex">I got one good answer: it is not possible due to name manglin=
g having to know that FloatImage will resolve to a template instance. I use=
d the proposed solution but it unfortunately had me change the forward decl=
arations of FloatImage. </blockquote><div><br></div><div>=C2=A0What solutio=
n did you use?=C2=A0</div></div></blockquote><div>I did update the forward =
declaration to the proposed:</div><div><br></div><div><br></div><div><div s=
tyle=3D"color: rgb(136, 136, 136);"><font face=3D"monospace, monospace">tem=
plate<typename T> class CudaImage;</font></div><div style=3D"color: r=
gb(136, 136, 136);"><font face=3D"monospace, monospace">using FloatImage =
=3D CudaImage<float>;</font></div></div><div style=3D"color: rgb(136,=
136, 136);"><font face=3D"monospace, monospace"><br></font></div><div styl=
e=3D"color: rgb(136, 136, 136);"><font face=3D"monospace, monospace"><br></=
font></div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"marg=
in: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><d=
iv dir=3D"ltr"><div>Did you try the concrete class solution - it is not as =
na=C3=AFve as it sounds, not as hard as it sounds (in C++11+) and has many =
protentional side benefits.<br></div></div></blockquote><div>No, I didn'=
;t. This would have worked with some amount of boilerplate, but I wanted to=
see if I could do without this extraneous class.</div><div>=C2=A0</div><bl=
ockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border=
-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div></div><div>=
<br></div><div>Otherwise the classical solution is not to forward declare a=
class but to have xxxfrw.h header instead, where you can put all "<sp=
an style=3D"display:inline!important;float:none;background-color:transparen=
t;color:rgb(34,34,34);font-family:"Arial","Helvetica",s=
ans-serif;font-size:13px;font-style:normal;font-variant:normal;font-weight:=
400;letter-spacing:normal;text-align:left;text-decoration:none;text-indent:=
0px;text-transform:none;white-space:normal;word-spacing:0px">leakage of imp=
lementation detail</span>".</div></div></blockquote><div>Sure, that wo=
uld have been a possibility.</div><div>=C2=A0</div></div></div></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/abdf6051-28fa-48e6-81c6-20eff0a2d4de%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/abdf6051-28fa-48e6-81c6-20eff0a2d4de=
%40isocpp.org</a>.<br />
------=_Part_24171_587172068.1530390221525--
------=_Part_24170_978999686.1530390221524--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sat, 30 Jun 2018 15:04:00 -0700 (PDT)
Raw View
------=_Part_25301_676648564.1530396240632
Content-Type: multipart/alternative;
boundary="----=_Part_25302_7456484.1530396240632"
------=_Part_25302_7456484.1530396240632
Content-Type: text/plain; charset="UTF-8"
On Saturday, June 30, 2018 at 4:23:41 PM UTC-4, Bengt Gustafsson wrote:
>
> In my previous response I acknowedged the explanation that this has to do
> with name mangling, where ultimately the class name would be mangled
> according to its real identity, i.e. CudaImage<float> and thus that a
> forward declaration "class FloatImage;" would be natural to reject.
>
> However, on second thought, FloatImage just as any class name is not an
> entity in itself that is known to the linker. And as you can't call methods
> on a class without seeing its full definition there is no risk that
> references to erroneously mangled method names sneak in to an object module
> compiled only seeing the forward declaration, right?
>
With only a forward declaration, you cannot call members. Nor can you call
non-member functions that take a reference to the forward declared type
(because you would need a valid reference to a `FloatImage`). However, you
*can* get a pointer to *functions* that take such types:
void func(const FloatImage &);
using fptr = void(*)(const FloatImage&);
fptr f = func;
You can then take `f` and pass it to some API which *itself* can get
`FloatImage` objects and pass them to the given function pointer. So the
compiler needs to know how `f` works on something approaching an ABI level.
And that means knowing if `FloatImage` is an actual type or a type alias
(and if so, what it is an alias for).
Also, of course, you can call functions that take a pointer to `FloatImage`
(you can only pass nullptr, of course). Since pointers are themselves
typed, and linking needs to tell the difference, ABI name mangling needs to
know if `FloatImage` is a type or a type alias.
> With this in mind, is there a technical reason that
> my initial construct must be forbidden? I don't see that Nicol's
> explanation holds "FloatImage turns out eventually to be a type alias and
> not a class". But the very reason for having a type alias is to give a
> class another name, so why can't it be forward declared under this
> alternate name?
>
No, the reason to have a type alias is to give a *type* another name.
`class FloatImage` will always be a *class*. `using FloatImage = ...;` is
whatever `...` happens to be.
Your initial construct ought to be forbidden because it is incoherent. You
declared that there is a class named `FloatImage`. You cannot later change
your mind and decide that it is something else.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/fe3a7806-ec9f-4822-bd79-2d6d61b97c43%40isocpp.org.
------=_Part_25302_7456484.1530396240632
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Saturday, June 30, 2018 at 4:23:41 PM UTC-4, Be=
ngt Gustafsson wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr">In my previous response I acknowedged the explanation that this ha=
s to do with name mangling, where ultimately the class name would be mangle=
d according to its real identity, i.e. CudaImage<float> and thus that=
a forward declaration "class FloatImage;" would be natural to re=
ject.<div><br>However, on second thought, FloatImage just as any class name=
is not an entity in itself that is known to the linker. And as you can'=
;t call methods on a class without seeing its full definition there is no r=
isk that references to erroneously mangled method names sneak in to an obje=
ct module compiled only seeing the forward declaration, right?</div></div><=
/blockquote><div><br></div><div></div><div>With only a forward declaration,=
you cannot call members. Nor can you call non-member functions that take a=
reference to the forward declared type (because you would need a valid ref=
erence to a `FloatImage`). However, you <i>can</i> get a pointer to <i>func=
tions</i> that take such types:</div><div><br></div><div style=3D"backgroun=
d-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style=
: solid; border-width: 1px; overflow-wrap: break-word;" class=3D"prettyprin=
t"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D=
"color: #008;" class=3D"styled-by-prettify">void</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> func</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-=
prettify">FloatImage</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"><b=
r><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">usin=
g</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> fptr </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">void</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">(*)(</span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">const</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D=
"styled-by-prettify">FloatImage</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">&);</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br><br>fptr f </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> func</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">;</span></div></code></div><div><br></div><div></div><div>You c=
an then take `f` and pass it to some API which <i>itself</i> can get `Float=
Image` objects and pass them to the given function pointer. So the compiler=
needs to know how `f` works on something approaching an ABI level. And tha=
t means knowing if `FloatImage` is an actual type or a type alias (and if s=
o, what it is an alias for).</div><div><br></div><div>Also, of course, you =
can call functions that take a pointer to `FloatImage` (you can only pass n=
ullptr, of course). Since pointers are themselves typed, and linking needs =
to tell the difference, ABI name mangling needs to know if `FloatImage` is =
a type or a type alias.<br></div><div>=C2=A0</div><blockquote class=3D"gmai=
l_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;=
padding-left: 1ex;"><div dir=3D"ltr"><div>With this in mind, is there a tec=
hnical reason that=C2=A0</div><div><div>my initial construct must be forbid=
den? I don't see that Nicol's explanation holds "FloatImage tu=
rns out eventually to be a type alias and not a class". But the very r=
eason for having a type alias is to give a class another name, so why can&#=
39;t it be forward declared under this alternate name?</div></div></div></b=
lockquote><div><br></div><div>No, the reason to have a type alias is to giv=
e a <i>type</i> another name. `class FloatImage` will always be a <i>class<=
/i>. `using FloatImage =3D ...;` is whatever `...` happens to be.</div><div=
><br></div><div>Your initial construct ought to be forbidden because it is =
incoherent. You declared that there is a class named `FloatImage`. You cann=
ot later change your mind and decide that it is something else.</div><br></=
div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/fe3a7806-ec9f-4822-bd79-2d6d61b97c43%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/fe3a7806-ec9f-4822-bd79-2d6d61b97c43=
%40isocpp.org</a>.<br />
------=_Part_25302_7456484.1530396240632--
------=_Part_25301_676648564.1530396240632--
.