Given that I want to perform filtering on some data, how can I avoid generating this data at runtime, but I maintain the flexibility of resizing and distributing the data of these filters, while also maintaining a nice clean reusable code. I know that I can use templates to do something like the following:
template <int x> class Filter { static const float f; static const Filter<x-1> next; inline float* begin(const Filter<x>& el){ return &f; } inline float* end(const Filter<x>& el) { return (&f)+x+1; } }; template <> class Filter<0> { static const float f; inline float* begin(const Filter<0>& el){ return &f; } inline float* end(const Filter<0>& el) { return (&f)+1; } }; template <int x> const float Filter<x>::f = someDistribution(x); template <> const float Filter<0>::f = someDistribution(0);
This will actually generate data in my filter according to the index x in the filter object according to someDistribution (...). However, there are some drawbacks to my use ...
1) I think that I am right in saying that although this data is not generated when the object is built, it is generated once when the program starts. - I could tolerate this, although I would prefer that the filter be computed in comiletime and baked then and there (is this even possible for floating-point data?)
2) The filter will not create an instance of the "next" element if there is no member function (called somewhere!) That traverses the length of the structure, i.e.
// inside template<int x> class Filter inline void instantiate() const { next.instantiate(); }; // then inside template<> class Filter<0> inline void instantiate() const { };
I have to do it wrong in order to require the plunging installation function, and this does not allow to execute the easily supported sentence.
edit: the reason I care here is because I would like to make sure the next members are created, so I can traverse the static "array" using the start and end functions.
So, firstly, how can I fix problem 2 and get rid of the instance function, and secondly, I can fix problem 1 so that this data is dynamically generated during compilation and supported.
(NB I, for similar problems, I used python pre-compilation scripts to generate source files containing filter data, but I do not want to use this here, since this is his own fish maker!)