I want to do something like this:
template<template<int d, class>
class container,
int dim = d, typename content_data_type>
class MyClass {
};
My Compiler tells me that this is not possible because “d” is not defined outside of:
template<int d, class> class container
Is there maybe another way of doing this ?
Thanks in advance for any help on this topic.
UPDATE:
@ Rook: i want to access the “dim” and “content_data_type” parameters later on in a specialization
e.g.
General class:
template<template<int d, class>
class container>
class MyClass {
};
Spec. class:
template<>
class MyClass<vec> {
vec c; // Error: vec needs template parameters
};
This gave me an error because i used my template class “vec” whitout template parameters, i expected the compiler to deduce the template parameters, e.g. when i use
MyClass<vec<3, float> >
then variable “c” should have the type
vec<3, float>
Because this didn’t work, I thought i can create two excplicit template paramters “dim” and “content_data_type” which i can access in the specialization class like this:
template<template<int d, class t>
class container,
int dim = d, typename content_data_type = t>
class MyClass<vec> {
vec<dim, content_data_type> c;
};
… and sorry again for not being specific enough with the initial question 🙂
I don’t think what you’re doing makes sense, so the answer is “no”.
The template parameter
containeris a class template, not a class. WhenMyClassis instantiated, its argument is the whole template, not just one instantiation of it. So it’s not possible to default the dimension ofMyClassto “the dimension ofcontainer“, becausecontainerdoesn’t have values for its own template parameters. Your classMyClasscan create and use one or more instantiations ofcontainerwith different values ofd, but it isn’t given any one of them in particular, it’s given the template.By analogy, suppose you pass a pointer-to-function
fas a parameter to a functiong. You can’t then use “the arguments passed tof” in the definition ofg. The functiongcan callfone or more times with different arguments, but it isn’t given any one call in particular, it’s given the function.From your update:
You don’t use
MyClass<vec<3, float> >, there’s no such thing. As I say,MyClasstakes a template not a class.vecis a template,vec<3, float>is a class. It sounds like maybe you don’t need a template as a template parameter at all.