RE: OONSTD: Element Ordering 2D Arrays

Geoffrey M. Furnish (furnish@xdiv.lanl.gov)
Thu, 9 Jul 1998 05:14:38 GMT

E. Robert Tisdale writes:
> I believe that a C++ Matrix class should define
> a subscripting operator [] which is consistent with C.
> The argument should be a zero based index
> and it should return a reference to a row of the matrix.

This results in the production of proxy objects for multidimensional
arrays. These cost you in both space and time. I think it is far
better to stick to operator() for numeric indexing in C++, since this
is both more efficient (through avoidance of "proxy object
proliferation mania") and familiar in the culture of numeric
programming. IMO, this is one misfeature of C we should do without.

> Another operator or a member function might be defined to accept
> one based indices and to return a reference to a particular element.

Okay, in this model you suggest:
1) operator[] plus proxies implement 0 based indexing
2) operator() implements 1 based indexing
???

So 1) is familiar to C programmers, and 2) is familiar to Fortran
programmers. That's cute, but has flaws:
A) How do you represent arrays with specified bounds? The
Fortran syntax dimension A(-4:4,-10:10).
B) Makes for lots of extra work for the container author.

I'd much rather see:
1) operator() emerge as the prefered indexing technique, at
least for dense matrices.
2) Algorithms templated on client container type
2) Algorithm's use traits (or at least documented constraints)
to discern array bounds.

-- 
Geoffrey Furnish                    email: furnish@lanl.gov
LANL XTM Radiation Transport/POOMA  phone: 505-665-4529     fax: 505-665-5538

"Software complexity is an artifact of implementation." -Dan Quinlan