RE: OONSTD: Element Ordering 2D Arrays

Gabriel Dos Reis (Gabriel.Dos-Reis@dptmaths.ens-cachan.fr)
Thu, 9 Jul 1998 13:57:18 +0200 (MET DST)

>>>>> «Geoffrey», Geoffrey M Furnish <furnish@xdiv.lanl.gov> wrote:

Geoffrey> 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.

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

I do agree with you. One should always evaluate the cost of a feature
before using it. I can't see any benefits in overloading operator[]. I
can only see desavantages.

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

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

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

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

Again, 100% agree.

-- Gaby