I am comfortable with templating functions and classes but I didn't know what to make of this when I saw it. I am sure its probably everyday syntax to most but I would like to get a well clarified explanation if anyone has one for me. What does the second uint32-t max mean and how is it used in the templated type?
Heres the syntax:
template <typename T, uint32_t max>
Thanks in advance.
It's a second parameter to the template. And template parameters don't have to be types. They can be constants or templates as well. Thus, given
template <typename T, uint32_t max> class TC {};
you would instantiate it:
TC< MyClass, 42 > t;
(for example.) Similarly, if it is a function template:
template <typename T, uint32_t max> void tf( T (&array)[max] );
type deduction can be used to determine the (numeric) value of max
.
Such value templates cannot have just any type; it must be an integral type or a pointer or reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With