Hi all,
I whipped up a quick class to represent a matrix for use with LAPACK.
It's a template class so it can support the 4 data types supported by
LAPACK (single/double x complex/real). I added a conversion operator
to automatically convert the object to a pointer of the appropriate
type. This makes using LAPACK in C++ a lot easier.
Unfortunately, it does not work well for the complex data types. The
reason is that LAPACK (or, more specifically, f2c) defines its own
complex types, complex and doublecomplex. I could just use LAPACK's
types, but they don't provide any operators for them, making them a
real pain. Instead, I would much prefer to use std::complex.
This is where the problem is. The conversion operator in my matrix
class returns a T* where T is the underlying data type. For complex
data types, it needs to return a pointer to an LAPACK type,
specifically a complex* or doublecomplex*. I thought template
specialization would help me out, but it's turned out to be a real
pain.
Here's the code in question:
template<typena me T>
class LAPACK_Matrix
{
public:
operator T*() { return &m_Data[0]; }
/* other operators */
private:
std::vector<Tm_ Data;
};
So I thought I would just provide a specialized version for the complex
data types:
template<>
class LAPACK_Matrix<s td::complex<dou ble
{
public:
operator doublecomplex*( ) { return &m_Data[0]; }
};
I thought this would be sufficient, but (as I'm sure you all know), the
specialized class does not "inherit" anything from the unspecialized
class. So in order to make this work, I would have to re-implement all
my other operators in the specialized class. That doesn't seem like a
good solution to me.
So I've been coming up with a reasonable way to avoid having to rewrite
a bunch of code and I'm just stumped. I thought maybe inheritance
could solve my problem, but I don't see how. I thought about trying to
combine templates and in heritance, but I'm not sure how that would
work, either.
If anyone has any suggestions, I'd love to hear them.
Thanks in Advance,
Bill