Q:

Template non-type argument constant restriction Filter library

I am working with a DSP Filter library 
http://www.linux-usb-daq.co.uk/howto2/filter/
That uses template non-type argument to initialize filter object. This is how a filter object is created and used.
    const int order = 3;
    Iir::Butterworth::LowPass<order> f;
    const float samplingrate = 1000; // Hz
    const float cutoff_frequency = 50; // Hz
    f.setup (order, samplingrate, cutoff_frequency);
    f.reset ();
    FILE *fimpulse = fopen("lp.dat","wt");

// let's generate an input signal and filter it
    // instantly!
    for(int i=0;i<1000;i++) 
    {
            float a=0;
            if (i==10) a = 1; // delta pulse at t=10
            float b = f.filter(a);
            fprintf(fimpulse,"%f\n",b);
    }

Now if I want to use this library in my code for IIR filtering for different orders of filter like 3,4,5 etc. How should I proceed without having to rewrite the whole code ? 
Because order is a compile-time constant 
const int order = 3;
Iir::Butterworth::LowPass<order> f;

Is there any hack by which I can write this code for different orders without rewriting every thing ?
Thanks,

A:

If I understood correctly your question you need two things: a template function like this
template <int order>
void my_filtering_function(...)
{
    Iir::Butterworth::LowPass<order> f;
    const float samplingrate = 1000; // Hz
...
}

And probably also some kind of run-time selection, like this
void exec_filter(int order)
{
    switch (order)
    {
    case 3: my_filtering_function<3>() ;
            break ;
    case 4: my_filtering_function<4>() ;
            break ;
     // othr cases?
    }
}

Some metaprogramming can auto,ate the switch for .eg. a range of integers. But has to be done with care. You do not want to instatiate your template function a billion times...

