In reply to dave_59:
If you are referring to my C++ example, you are right. There it does not make sense to use a template. I maybe shouldn’t have placed this example, I just put this to explain the kind of syntax I was looking for.
The rest of the example code makes more sense. To be more specific this is the application that I would like to use this for:
We have a bunch of classes to represent datatypes. E.g. We have a class Complex that stores a complex number (e.g. members Re and Im), we have a class Polar that stores a polar number. They also contain some meta data about the sample. These classes are parameterized, e.g. to set the sample word length. In the example this is the parameterized T class.
On the other hand we have a bunch of classes that can do stuff on numbers. For example we have a class to plot waveforms. This is quite a big class with a lot of members and methods that has been inherited from our old C++ testbench. It for example has a method
function void add_Y_data (const ref real data[], input int x_delta, input int x_start, input string label);
For sure such a thing must be possible, it would be quite restrictive if we can’t pass parameterized classes to another class’ s method.
This will store the data to be plotted in the plotting class, define an x axis, label, etc…
It has several add_data methods, e.g. plotting for real, for plotting real[2],… and similarly for plotting XY plots.
When the .plot() method is called it will plot all the registered waveforms on top of eachother.
We often need to plot an array of Complex, or an array of Polar, etc…
So it would be ideal if we could have methods in the plotter class:
function void add_Y_data (const ref Complex#(W) data[], input int x_delta, input int x_start, input string label);
function void add_Y_data (const ref Polar#(W) data[] input string label);
etc...
Inside those methods I would just call $itor() on for example data[i].Re in case of complex. The issue is being able to pass the parameterized Complex number into the plotter class method.