I have have the following code using templates and array dimension as template non-type parameter
template<int n> double f(double c[n]);
...
double c[5];
f<5>(c); // compiles
f(c); // does not compile
should not the compiler to be able to instantiate the second f without explicit template parameter? I am using g++4.1
Template classes and functions can make use of another kind of template parameter known as a non-type parameter. A template non-type parameter is a template parameter where the type of the parameter is predefined and is substituted for a constexpr value passed in as an argument.
C++ Templates: Templates with Multiple Parameters | C++ Tutorials for Beginners #65.
A template argument for a template template parameter is the name of a class template. When the compiler tries to find a template to match the template template argument, it only considers primary class templates. (A primary template is the template that is being specialized.)
8. Why we use :: template-template parameter? Explanation: It is used to adapt a policy into binary ones.
It works when using references:
template<size_t n> double f(double (&c)[n]);
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