Hello,

I would like to make a function with a varaiable number of template arguments which is, itself, in a template class.

The code is shown in the sample below.

If you look at the template classes in the sample below, the only difference in each template class specialization "OrderN_Calculation" is the templated subroutine "Calculation". Writing the whole class "OrderN_Calculation" with a ctor, etc is getting tiresome. Is there any way to just write the specialized, templated subroutine and avoid writing the entire class each time?

Code:
template<const unsigned int N>
class OrderN_Calculation
{
private:

  double x;

public:

  OrderN_Calculation(const double& val = 0.0) : x(val) { }

  double Calculation(void);
};

template<>
class OrderN_Calculation<0u>
{
private:

  double x;

public:

  OrderN_Calculation(const double& val = 0.0) : x(val) { }

  template<const unsigned int C0>
  double Calculation(void)
  {
    return static_cast<double>(C0);
  }
};

template<>
class OrderN_Calculation<1u>
{
private:

  double x;

public:

  OrderN_Calculation(const double& val) : x(val) { }

  template<const unsigned int C0,
           const unsigned int C1>
  double Calculation(void)
  {
    return     C0
            + (x * C1);
  }
};

template<>
class OrderN_Calculation<2u>
{
private:

  double x;

public:

  OrderN_Calculation(const double& val) : x(val) { }

  template<const unsigned int C0,
           const unsigned int C1,
           const unsigned int C2>
  double Calculation(void)
  {
    return     C0
           +  (x * C1)
           + ((x * x) * C2);
  }
};


int main(int, char**)
{
  const double d0 = OrderN_Calculation<0u>(1.23).Calculation<2u>();
  const double d1 = OrderN_Calculation<1u>(1.23).Calculation<2u, 3u>();
  const double d2 = OrderN_Calculation<2u>(1.23).Calculation<2u, 3u, 4u>();
}