home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13639 < prev    next >
Encoding:
Internet Message Format  |  1992-09-14  |  2.8 KB

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