I've written a C++ matrix template class. It's parameterized by its dimensions and by its datatype:
template<int NRows, int NCols, typename T>
struct Mat {
typedef Mat<NRows, NCols, T> MyType;
typedef T value_type;
typedef const T *const_iterator;
typedef T *iterator;
enum { NumRows = NRows };
enum { NumCols = NCols };
T m_data[NRows * NCols];
// ... Lot's of operations and functions ...
// Some overloads
typedef Mat<2, 1, int> Vec2i;
typedef Mat<2, 1, float> Vec2f;
typedef Mat<3, 1, float> Vec3f;
typedef Mat<4, 1, unsigned char> Vec4ub;
typedef Mat<4, 4, float> Mat44f;
typedef Vec3f Vector;
typedef Vec4ub Color;
typedef Vec2f LonLat;
It's a fantastic little class that handles lots of vector arithmetic and linear algebra. Also, it is able to interface easily with both low level code (OpenGL) and high level code (PID and Kalman filters).
Its design seems sound to me, but that's not what this question is about. This class has one dreadful flaw: it is a dread to use in the debugger.
Because it is a struct that contains an array, there is always that one annoying level of indirection when examining variables in Xcode (and I assume in VisualStudio). This is further aggravated by the fact that Xcode sometimes fails to follow chains of pointers correctly and I can't examine the values at all. This happens if I have, say, a vector
of these objects.
I realize that I could perhaps customize the debugger to somehow work with my type. But I was wondering if there is perhaps
a different way to store the data of my Matrix so that it has better "debugability"?
This is more of a "use your imagination" type question than one looking for a best-practices design. I'm just curious what alternative class layouts could be used while still maintaining the generic nature of the code.