template <int parameter> class MyClass
is the above a template specialization? I don't think so but I'm unsure of it, I didn't know templates could receive arguments as functions.. where do their arguments get stored?
template <int parameter> class MyClass
is the above a template specialization? I don't think so but I'm unsure of it, I didn't know templates could receive arguments as functions.. where do their arguments get stored?
Template parameters do not necessarily need to be type names: they can be numbers as well. For example, std::array
takes a parameter of type size_t
for the array size.
In your case, the class template takes a parameter of type int
, which is entirely OK. Here is an example of how you can use such a parameter:
template <int param> struct MyClass {
int array[param]; // param is a compile-time constant.
};
int main() {
MyClass<5> m;
m.array[3] = 8; // indexes 0..4 are allowed.
return 0;
}
Their arguments are stored within their type information.
No, that is not a template specialization. Have a look at this:
template <int, int> class MyClass; // <-- primary template
template <int> class MyClass<int, 4>; // <-- partial specialization
template <> class MyClass<5, 4>; // <-- specialization