home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!spool.mu.edu!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!mrhagger
- From: mrhagger@athena.mit.edu (Michael R Haggerty)
- Subject: Proposal: Subscripting with multiple arguments
- Message-ID: <1992Sep14.182942.1986@athena.mit.edu>
- Sender: news@athena.mit.edu (News system)
- Nntp-Posting-Host: m16-034-17.mit.edu
- Organization: Massachusetts Institute of Technology
- Date: Mon, 14 Sep 1992 18:29:42 GMT
- Lines: 46
-
- Hi,
-
- 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.
-
- The only way of getting around this deficiency and also avoiding a matrix_row
- helper class is to making subscripting an operation that uses the function call
- operator; i.e.
-
- Matrix2d M(10, 10);
- M(4, 5) = 15.0;
-
- rather than the (in my opinion) much more natural
-
- M[4, 5] = 15.0;
-
- which would require a definition like
-
- double &Matrix2d::operator[] (int i, int j) {...}
-
- As a benefit, I think that it should be easier to generate good code from the
- two-argument version than from the version which uses a helper class. In
- numerical work, efficiency is everything.
-
- Of course there is a slight drawback: the proposed notation is presently
- seen as a usage of the comma operator within a (single argument) subscript.
- Correct me if I'm wrong, but I believe that this is a rather rare construct
- and could be effected by
-
- M[(4,5)] = 15.0;
-
- that is, the extra parenthesis are necessary to force the internal expression to
- be seen as a comma operator.
-
- Am I being naive to suppose that the change could be made without stepping on
- too many people's toes? Has this change been considered before? What does it
- take to get a proposal like this seen by the powers-that-be?
-
- Yours,
- Michael Haggerty
- mrhagger@athena.mit.edu
-