I have a function template
template<typename T>
void output(T& value)
{
}
Is there a way to create specialization for output std::array objects? Yes, I know, that arrays of different sizes are different types. ) I just hope that there is a way in c++11
You can’t specialize it for all arrays, that would require a “partial specialization” of the template. A full specialization of a template pins down the values of all template parameters (in this case there is only one,
T, so a full specialization only covers one type in place ofT). A partial specialization covers multiple possible values of the template parameters (in this case we want to cover anystd::array<U,N>in place ofT), so a partial specialization has template parameters of its own.C++ permits partial specialization of class templates but not of function templates.
Instead, you can overload it. You define another function template with the same name and different parameters: