In the code
template < template<class TTP> class TP > ... // whatever
is TTP
usable anywhere at all then? Can't find any reference to what happens with these names in the Standard.
In the code
template < template<class TTP> class TP > ... // whatever
is TTP
usable anywhere at all then? Can't find any reference to what happens with these names in the Standard.
[basic.scope.temp]/p1:
It can be used inside that list, and that's it. For instance,
You can access it, you just have to be slightly indirect about it.
More precisely, if you have an object of type
vector<int>
and you pass it tofoo
above, thenfoo
can access the relevant type parameters:When
bar(v)
is called, thenbar
"knows" the first parameter, which (I think?) is your goal.I'm not saying the other answers are incorrect, it's just that you asked slightly the wrong question.
To understand the answer I've given, it's probably easier to forget about the
template
line and instead look at:The type of
x
, the parameter tofoo
, is of typecontainer_tmpl<value_t>
. Wherecontainer_tmpl
is something likevector
orlist
, andvalue_t
is something likeint
orstd::string
. Once you write this signature, it's obvious thatvalue_t
is simple a type (and hence becomestypename value_t
in the template introduction) and thatcontainer_tmpl
is a template taking (at least) one type parameter.In this context,
value_t
andcontainer_tmpl
are defined insidebar
.If you don't understand why I have
typename ...
, then remember thatvector
actually takes two type args, not one. Anyway, the basic idea is that you must provide names for these template args outside where you would expect to get them. E.g. if you have a template that takes three arguments, two type parameters and an integer.No. It's a template parameter for TP<>, not the outer template function.