C++ class size template deduction
Solution 1:
You should arrange your template parameters so that the ones that need to be explicitly specified are at the beginning, and the ones that can be deduced from the arguments are at the end:
template <uint8_t N3, uint8_t N1, uint8_t N2>
Shape<N3> func(const Shape<N1> &shape1, const Shape<N2> &shape2)
{
return ...;
}
Shape<3> shape1 = {1, 2, 3};
Shape<2> shape2 = {4, 5};
Shape<4> shape3 = func<4>(shape1, shape2);
Here, N3
is explicitly specified as 4 while N1
and N2
are deduced from the argument types, so all template parameters have values and the code compiles. If you leave N3
at the end, then you will be forced to explicitly specify N1
and N2
in order to explicitly specify N3
.