home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13631 < prev    next >
Encoding:
Text File  |  1992-09-14  |  2.1 KB  |  58 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!spool.mu.edu!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!mrhagger
  3. From: mrhagger@athena.mit.edu (Michael R Haggerty)
  4. Subject: Proposal: Subscripting with multiple arguments
  5. Message-ID: <1992Sep14.182942.1986@athena.mit.edu>
  6. Sender: news@athena.mit.edu (News system)
  7. Nntp-Posting-Host: m16-034-17.mit.edu
  8. Organization: Massachusetts Institute of Technology
  9. Date: Mon, 14 Sep 1992 18:29:42 GMT
  10. Lines: 46
  11.  
  12. Hi,
  13.  
  14. I have been using C++ for numerical work, and one of the changes which would
  15. be most useful would be to allow the subscription operator to take multiple
  16. parameters.  This would make it much simpler to define classes for multi-
  17. dimensional matrices without the nuisance of having to define a helper class.
  18. The concept should not be such a shock to anyone, as the subscript operator
  19. is already allowed to take non-integer arguments so is already significantly
  20. extended from the C subscript operator.
  21.  
  22. The only way of getting around this deficiency and also avoiding a matrix_row
  23. helper class is to making subscripting an operation that uses the function call
  24. operator; i.e.
  25.  
  26. Matrix2d M(10, 10);
  27. M(4, 5) = 15.0;
  28.  
  29. rather than the (in my opinion) much more natural
  30.  
  31. M[4, 5] = 15.0;
  32.  
  33. which would require a definition like
  34.  
  35. double &Matrix2d::operator[] (int i, int j) {...}
  36.  
  37. As a benefit, I think that it should be easier to generate good code from the
  38. two-argument version than from the version which uses a helper class.  In
  39. numerical work, efficiency is everything.
  40.  
  41. Of course there is a slight drawback: the proposed notation is presently
  42. seen as a usage of the comma operator within a (single argument) subscript.
  43. Correct me if I'm wrong, but I believe that this is a rather rare construct
  44. and could be effected by
  45.  
  46. M[(4,5)] = 15.0;
  47.  
  48. that is, the extra parenthesis are necessary to force the internal expression to
  49. be seen as a comma operator.
  50.  
  51. Am I being naive to suppose that the change could be made without stepping on
  52. too many people's toes?  Has this change been considered before?  What does it
  53. take to get a proposal like this seen by the powers-that-be?
  54.  
  55. Yours,
  56. Michael Haggerty
  57. mrhagger@athena.mit.edu
  58.