home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!olivea!spool.mu.edu!agate!agate!matt
- From: matt@physics.berkeley.edu (Matt Austern)
- Newsgroups: comp.lang.c++
- Subject: Re: Proposal: Subscripting with multiple arguments
- Message-ID: <MATT.92Sep14161955@physics.berkeley.edu>
- Date: 14 Sep 92 23:19:55 GMT
- References: <1992Sep14.182942.1986@athena.mit.edu>
- Reply-To: matt@physics.berkeley.edu
- Organization: Lawrence Berkeley Laboratory (Theoretical Physics Group)
- Lines: 40
- NNTP-Posting-Host: physics.berkeley.edu
- In-reply-to: mrhagger@athena.mit.edu's message of 14 Sep 92 18:29:42 GMT
-
- In article <1992Sep14.182942.1986@athena.mit.edu> mrhagger@athena.mit.edu (Michael R Haggerty) writes:
-
- > I have been using C++ for numerical work, and one of the changes which would
- > be most useful would be to allow the subscription operator to take multiple
- > parameters. This would make it much simpler to define classes for multi-
- > dimensional matrices without the nuisance of having to define a helper class.
- > The concept should not be such a shock to anyone, as the subscript operator
- > is already allowed to take non-integer arguments so is already significantly
- > extended from the C subscript operator.
-
- I've also occasionally wished that I could define, say,
- operator[](int,int,int),
- and for the same reason: multi-dimensional arrays. I haven't wished
- for it very often, though, because that isn't really the syntax that I
- want for a multi-dimensional array anyway; I would much rather access
- an array element using the syntax A[i][j] than using the syntax
- A[i,j]. After all, the A[i][j] syntax is what you would use if you
- were using built-in data types instead of classes, and it's nice to
- keep some things the same when defining a class. (For that matter,
- there isn't really anything wrong with the syntax A(i,j), either.)
-
- Of course, if you want to use the A[i][j] syntax then you have to
- define a helper class, but that's not too horrible a burden: you
- really shouldn't be defining array classes very often anyway, but
- should just do it once, and do it right.
-
- What I find to be a bigger problem, actually, is designing an array
- class that works for arrays with an arbitrary number of dimensions.
- There's no problem with defining the classes Array1, Array2,
- Array3,..., and that's exactly what I've done, but it's annoying and
- inelegant. Has anyone out there come up with a good definition for
- arrays with an arbitrary number of dimensions? ("Good," in this
- context, means specifically that array reference is sufficiently well
- optimized that an intelligent programmer wouldn't mind using this
- class in an inner loop.)
- --
- Matthew Austern Just keep yelling until you attract a
- (510) 644-2618 crowd, then a constituency, a movement, a
- austern@lbl.bitnet faction, an army! If you don't have any
- matt@physics.berkeley.edu solutions, become a part of the problem!
-