Topic: Relaxing requirements on template template parameter matching.


Author: Bengt Gustafsson <bengt.gustafsson@beamways.com>
Date: Tue, 1 Sep 2015 08:57:03 -0700 (PDT)
Raw View
------=_Part_2659_10553727.1441123023184
Content-Type: multipart/alternative;
 boundary="----=_Part_2660_1069004150.1441123023184"

------=_Part_2660_1069004150.1441123023184
Content-Type: text/plain; charset=UTF-8

Today a template template parameter can only be matched by a template class
with exactly the same set of template parameters. Default parameters or
variadic parameters are ignored.

Example:

template<template<typename> class TPL> class X {
 TPL<int> mVar;
};

template<typename A, typename B = int> struct Y {
};

X<Y> fee;   // ERROR: Y has too many template parameters, even though one
has a default.

template<typename... Ts> struct A {
};

X<A> foo;    // ERROR: A has wrong template parameters, although A can be
instantiated with one type, just as X will do.


Does anyone know what the rationale is behind this restriction?

One problem this would solve is that today if you want to be able to
replace a container which could default to std::vector, the replacement
container must also have two template parameters (the second being the
allocator).

Another problem it would solve is that you actually have to know that
vector has two template parameters and basic_string has three when
modelling a template template parameter where they are to be possible
candidates.

The other problem is that this rule forbids the designers of the standard
library to generalize class templates by adding more template parameters
with defaults, as some developer out there may have used the
class template in a template template parameter situation.

This argument was used against me when I suggested that std::array could be
made n-dimensional like this:

template<typename T, size_t... dims> class array;

NO NO: That's not backwards compatible, what if someone has done this:

template<template<typename T, size_t> class> class ArrayHolder {};

ArrayHolder<std::array> my_holder;  // Breaks with new std::array
definition...

--

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

<div dir=3D"ltr">Today a template template parameter can only be matched by=
 a template class with exactly the same set of template parameters. Default=
 parameters or variadic parameters are ignored.<div><br></div><div>Example:=
</div><div><br></div><div class=3D"prettyprint" style=3D"border: 1px solid =
rgb(187, 187, 187); word-wrap: break-word; background-color: rgb(250, 250, =
250);"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">template</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">template</span><span style=3D"colo=
r: #080;" class=3D"styled-by-prettify">&lt;typename&gt;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">class</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> TPL</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">class</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> X </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=
=A0TPL</span><span style=3D"color: #080;" class=3D"styled-by-prettify">&lt;=
int&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> mV=
ar</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-prettify">};</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">template</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">typename</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 style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">typename</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> B </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">struct</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> Y </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br><br>X</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">Y</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> fee</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> =C2=A0 </span><span style=3D"color:=
 #800;" class=3D"styled-by-prettify">// ERROR: Y has too many template para=
meters, even though one has a default.</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">template</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">typename</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">...</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">=
Ts</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> A </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">};</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br><br>X</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify">A</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> foo=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> =C2=A0 =C2=A0</spa=
n><span style=3D"color: #800;" class=3D"styled-by-prettify">// ERROR: A has=
 wrong template parameters, although A can be instantiated with one type, j=
ust as X will do.</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br><br></span></div></code></div><div><br></div><div>Does anyone kn=
ow what the rationale is behind this restriction?</div><div><br></div><div>=
One problem this would solve is that today if you want to be able to replac=
e a container which could default to std::vector, the replacement container=
 must also have two template parameters (the second being the allocator).</=
div><div><br></div><div>Another problem it would solve is that you actually=
 have to know that vector has two template parameters and basic_string has =
three when modelling a template template parameter where they are to be pos=
sible candidates.</div><div><br></div><div>The other problem is that this r=
ule forbids the designers of the standard library to generalize class templ=
ates by adding more template parameters with defaults, as some developer ou=
t there may have used the</div><div>class template in a template template p=
arameter situation.</div><div><br></div><div>This argument was used against=
 me when I suggested that std::array could be made n-dimensional like this:=
</div><div><br></div><div>template&lt;typename T, size_t... dims&gt; class =
array;</div><div><br></div><div>NO NO: That&#39;s not backwards compatible,=
 what if someone has done this:</div><div><br></div><div>template&lt;templa=
te&lt;typename T, size_t&gt; class&gt; class ArrayHolder {};</div><div><br>=
</div><div>ArrayHolder&lt;std::array&gt; my_holder; =C2=A0// Breaks with ne=
w std::array definition...</div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_2660_1069004150.1441123023184--
------=_Part_2659_10553727.1441123023184--

.