Hi everyone. I would like to consider the following problem: I want to
provide the ability to store and manipulate numeric container classes
that provide
1) element wise access
2) size
but maybe not with the same interface. For example
MatrixType1 provides [i][j] element access, and size1() and size2() for
size access. MatrixType2 provide (i,j) element access.
Now, these matrix classes might contain doubles, floats, integers,
complex numbers, whatever... The way I currently have things
implemented, I store maps of each different possiblity, like this:
class WrapperClass{
public:
....
private:
std::map<string, MatrixType1<double> m_doubleMatrix1s;
std::map<string, MatrixType2<double> m_doubleMatrix2s;
std::map<string, MatrixType1<complex> m_complexMatrix1s;
std::map<string, MatrixType2<complex> m_complexMatrix2s;
....
}
As you can imagine there's a whole lot of code duplication, becuase I
have to provide an overloaded add_matrix(string, Matrixtype) member, not
to mention overloaded members that do the kind of output I'm interested
in for each of these matrix types.
I'd like to do this instead via templating, but the problem I have is
storing the different matrix types. It would even be sufficient if I
could reduce the above example down to something like:
class WrapperClass{
public:
....
private:
std::map<string, MatrixType1<numeric_type> m_Matrix1s;
std::map<string, MatrixType2<numeric_type> m_Matrix2s;
}
where numeric_type can be double, float, int, or complex.
Unfortunately the only way I can think of to do something like this
would be to cast the container types to types of void*, which seems like
bad programming style to me.
does anyone know of a clever solution to this? Have I made my proble clear?
Thanks for your time.
Glen