Topic: Treating variable template as a type-template
Author: Dale Weiler <weilercdale@gmail.com>
Date: Tue, 5 May 2015 09:30:23 -0700 (PDT)
Raw View
------=_Part_2679_1456002192.1430843423776
Content-Type: multipart/alternative;
boundary="----=_Part_2680_452683379.1430843423777"
------=_Part_2680_452683379.1430843423777
Content-Type: text/plain; charset=UTF-8
C++14s notion of variable templates has some special edge cases that make
them incompatible with templates.
Consider a template-template like such
template <template <typename> class A, typename T>
struct wrap {
static constexpr T value = A<T>;
};
instantiated as such
template <typename T>
static constexpr T foo = T(5);
wrap<foo, int>::value;
This unfortunately does not work as variable-templates are not treated as
type-templates.
I believe variable templates should be treated as type-templates, where by
that following example is understood
by the compiler to mean something like.
template <template <typename> class A, typename T>
struct wrap {
static constexpr T _unspecified_value = A<T>::_unspecified;
};
template <typename T>
struct _unspecified_foo {
static constexpr T _unspecified = T(5);
};
auto foo = wrap<_unspecified_foo, int>::_unspecified_value;
--
---
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_2680_452683379.1430843423777
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">C++14s notion of variable templates has some special edge =
cases that make them incompatible with templates.<br><br>Consider a templat=
e-template like such<br><div class=3D"prettyprint" style=3D"background-colo=
r: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: soli=
d; border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><=
div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">template</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: #008;" class=3D"styled-by-prettify">templ=
ate</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #080;" class=3D"styled-by-prettify"><typename>=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">class</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> A</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">typename</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">></span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">struct</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
wrap </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> &n=
bsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">stati=
c</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">constexpr</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> T value </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> A</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">T</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">>;</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br></span></div></code></div><br>instantiated as such<br><div class=
=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-colo=
r: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: b=
reak-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span=
style=3D"color: #008;" class=3D"styled-by-prettify">template</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: =
#008;" class=3D"styled-by-prettify">typename</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> T</span><span style=3D"color: #660;" cla=
ss=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">static</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>constexpr</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
T foo </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D=
</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 styl=
e=3D"color: #066;" class=3D"styled-by-prettify">5</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br>wrap</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify"><</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">foo</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">i=
nt</span><span style=3D"color: #660;" class=3D"styled-by-prettify">>::</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">value</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></code></=
div><br>This unfortunately does not work as variable-templates are not trea=
ted as type-templates.<br><br>I believe variable templates should be treate=
d as type-templates, where by that following example is understood<br>by th=
e compiler to mean something like.<br><div class=3D"prettyprint" style=3D"b=
ackground-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); bord=
er-style: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"=
prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">template</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify"><</span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">template</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #080;" class=3D"styled-by-prettify">&l=
t;typename></span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">class=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> A</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">typename</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"><br></span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">struct</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> wrap </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-p=
rettify">static</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">cons=
texpr</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> T _u=
nspecified_value </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
A</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">T</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">>::</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">_unspecified</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">};</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">template</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-=
prettify"><</span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">typename</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"><br></span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> _unspecified_foo </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br> </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">static</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">constexpr</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> T _unspecified </span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #066;"=
class=3D"styled-by-prettify">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: #660;" class=3D"styled-by-pre=
ttify">};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> foo </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> wrap</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">_unspecified_foo</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">int</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">>::</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify">_unspecified_value</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br></span></div></code></div><br><br></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_2680_452683379.1430843423777--
------=_Part_2679_1456002192.1430843423776--
.
Author: David Krauss <potswa@gmail.com>
Date: Wed, 6 May 2015 08:39:00 +0800
Raw View
--Apple-Mail=_5032BC24-BC07-40C2-ADA8-E105D28F72A0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
> On 2015=E2=80=9305=E2=80=9306, at 12:30 AM, Dale Weiler <weilercdale@gmai=
l.com> wrote:
>=20
> C++14s notion of variable templates has some special edge cases that make=
them incompatible with templates.
>=20
> Consider a template-template like such
> template <template <typename> class A, typename T>
> struct wrap {
> static constexpr T value =3D A<T>;
> };
This is ill-formed. The syntax is invalid before it=E2=80=99s ever instanti=
ated. A<T> is not a class or typename, it=E2=80=99s a variable. Perhaps tem=
plate <typename> decltype(auto) A would make more sense. I can=E2=80=99t th=
ink of another way to indicate that A<T> might be an object, lvalue referen=
ce, or rvalue reference.
> instantiated as such
> template <typename T>
> static constexpr T foo =3D T(5);
> wrap<foo, int>::value;
>=20
> This unfortunately does not work as variable-templates are not treated as=
type-templates.
It=E2=80=99s been suggested here before, but it can be unintuitive when obj=
ects behave like types, not to mention likely a pain to implement.
int o;
template< typename >
int vt;
int & r =3D vt< int >;
template< int & obj >
struct blah {};
template< typename foo >
struct blah< vt< foo > > {};
blah< o > a; // primary template
blah< r > b; // specialization
Do you have a real use-case? Why not just implement the _unspecified_foo yo=
urself =E2=80=94 no capability is lost versus the variable template, and yo=
u can still have a variable-template interface into it.
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--Apple-Mail=_5032BC24-BC07-40C2-ADA8-E105D28F72A0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9305=
=E2=80=9306, at 12:30 AM, Dale Weiler <<a href=3D"mailto:weilercdale@gma=
il.com" class=3D"">weilercdale@gmail.com</a>> wrote:</div><br class=3D"A=
pple-interchange-newline"><div class=3D""><div dir=3D"ltr" class=3D"">C++14=
s notion of variable templates has some special edge cases that make them i=
ncompatible with templates.<br class=3D""><br class=3D"">Consider a templat=
e-template like such<br class=3D""><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"><span style=3D"color: #008;" class=3D"styled-by-prettify">templat=
e</span> <span style=3D"color: #660;" class=3D"styled-by-prettify"><</sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">template</span=
> <span style=3D"color: #080;" class=3D"styled-by-prettify"><typename>=
;</span> <span style=3D"color: #008;" class=3D"styled-by-prettify">class</s=
pan> A<span style=3D"color: #660;" class=3D"styled-by-prettify">,</span> <s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">typename</span> T<s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">></span><br clas=
s=3D""><span style=3D"color: #008;" class=3D"styled-by-prettify">struct</sp=
an> wrap <span style=3D"color: #660;" class=3D"styled-by-prettify">{</span>=
<br class=3D""> <span style=3D"color: #008;" class=3D"styled-b=
y-prettify">static</span> <span style=3D"color: #008;" class=3D"styled-by-p=
rettify">constexpr</span> T value <span style=3D"color: #660;" class=3D"sty=
led-by-prettify">=3D</span> A<span style=3D"color: #660;" class=3D"styled-b=
y-prettify"><</span>T<span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">>;</span><br class=3D""><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">};</span><br class=3D""></code></div></div></div></blockqu=
ote><div><br class=3D""></div><div>This is ill-formed. The syntax is invali=
d before it=E2=80=99s ever instantiated. <font face=3D"Courier" class=3D"">=
A<T></font> is not a <font face=3D"Courier" class=3D"">class</font> o=
r <font face=3D"Courier" class=3D"">typename</font>, it=E2=80=99s a variabl=
e. Perhaps <font face=3D"Courier" class=3D"">template <typename>=
decltype(auto) A</font> would make more sense. I can=E2=80=99t think =
of another way to indicate that <font face=3D"Courier" class=3D"">A<T>=
;</font> might be an object, lvalue reference, or rvalue reference.</div><b=
r class=3D""><blockquote type=3D"cite" class=3D""><div class=3D""><div dir=
=3D"ltr" class=3D"">instantiated as such<br class=3D""><div class=3D"pretty=
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"prettyprint"><span style=3D"color: #008;" class=3D"styled-=
by-prettify">template</span> <span style=3D"color: #660;" class=3D"styled-b=
y-prettify"><</span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">typename</span> T<span style=3D"color: #660;" class=3D"styled-by-pret=
tify">></span><br class=3D""><span style=3D"color: #008;" class=3D"style=
d-by-prettify">static</span> <span style=3D"color: #008;" class=3D"styled-b=
y-prettify">constexpr</span> T foo <span style=3D"color: #660;" class=3D"st=
yled-by-prettify">=3D</span> T<span style=3D"color: #660;" class=3D"styled-=
by-prettify">(</span><span style=3D"color: #066;" class=3D"styled-by-pretti=
fy">5</span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</s=
pan><br class=3D"">wrap<span style=3D"color: #660;" class=3D"styled-by-pret=
tify"><</span>foo<span style=3D"color: #660;" class=3D"styled-by-prettif=
y">,</span> <span style=3D"color: #008;" class=3D"styled-by-prettify">int</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">>::</span=
>value<span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><br=
class=3D""></code></div><br class=3D"">This unfortunately does not work as=
variable-templates are not treated as type-templates.<br class=3D""></div>=
</div></blockquote><div><br class=3D""></div><div>It=E2=80=99s been suggest=
ed here before, but it can be unintuitive when objects behave like types, n=
ot to mention likely a pain to implement.</div><div><br class=3D""></div><d=
iv><div><font face=3D"Courier" class=3D"">int o;</font></div><div><font fac=
e=3D"Courier" class=3D""><br class=3D""></font></div><div><font face=3D"Cou=
rier" class=3D"">template< typename ></font></div><div><font face=3D"=
Courier" class=3D"">int vt;</font></div><div class=3D""><font face=3D"Couri=
er" class=3D""><br class=3D""></font></div></div><div><font face=3D"Courier=
" class=3D"">int & r =3D vt< int >;</font></div><div><font face=
=3D"Courier" class=3D""><br class=3D""></font></div><div><font face=3D"Cour=
ier" class=3D"">template< int & obj ></font></div><div><font face=
=3D"Courier" class=3D"">struct blah {};</font></div><div><font face=3D"Cour=
ier" class=3D""><br class=3D""></font></div><div><font face=3D"Courier" cla=
ss=3D"">template< typename foo ></font></div><div><font face=3D"Couri=
er" class=3D"">struct blah< vt< foo > > {};</font></div><div><f=
ont face=3D"Courier" class=3D""><br class=3D""></font></div><div><font face=
=3D"Courier" class=3D"">blah< o > a; // primary template</font></div>=
<div><font face=3D"Courier" class=3D"">blah< r > b; // specialization=
</font></div><div><br class=3D""></div><div>Do you have a real use-case? Wh=
y not just implement the <span style=3D"font-family: monospace; backgr=
ound-color: rgb(250, 250, 250);" class=3D"">_unspecified_foo</span> yo=
urself =E2=80=94 no capability is lost versus the variable template, and yo=
u can still have a variable-template interface into it.</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 />
--Apple-Mail=_5032BC24-BC07-40C2-ADA8-E105D28F72A0--
.