home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / std / cplus / 1551 < prev    next >
Encoding:
Internet Message Format  |  1992-11-12  |  3.5 KB

  1. Xref: sparky comp.std.c++:1551 comp.lang.c++:16158
  2. Newsgroups: comp.std.c++,comp.lang.c++
  3. Path: sparky!uunet!sun-barr!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!darwin.sura.net!Sirius.dfn.de!Urmel.Informatik.RWTH-Aachen.DE!kaa!dak
  4. From: dak@kaa.informatik.rwth-aachen.de (David Kastrup)
  5. Subject: PROPOSAL: Allow static member operators
  6. Message-ID: <dak.721580710@kaa>
  7. Summary: Proposal to remove nonstatic restriction for member operators
  8. Keywords: static operator
  9. Sender: news@Urmel.Informatik.RWTH-Aachen.DE (Newsfiles Owner)
  10. Nntp-Posting-Host: kaa
  11. Organization: Rechnerbetrieb Informatik  /  RWTH Aachen
  12. Date: 12 Nov 92 15:05:10 GMT
  13. Lines: 62
  14.  
  15. I have already proposed this to Dr. Stroustrup, but received a nolo volens
  16. because of possible confusion of users. I do not agree with his point
  17. of view.
  18.  
  19. I do not know why operators should only be nonstatic member functions.
  20. They would be handy especially in the case of fake classes or
  21. angels (Thomas von Aquin argued that since angels lack physical manifestation,
  22. they are not a manifestation of a principle, but the principle itself,
  23. and so every angel as a mere spiritual being has its own, unique class).
  24.  
  25. One use of angels are function templates with nontype arguments. Since
  26. the usual function templates do not support nontype arguments, one has
  27. to implement them using angels. And the most natural choice for an
  28. angel to behave as a function is operator(), which is there exactly
  29. for that purpose. (In ARM, the use of angels for this purpose is
  30. suggested, however with a non-operator syntax).
  31. example:
  32. template <some template arguments> class example {
  33.     static operator()(parameters) { ... };
  34. };
  35.  
  36. example <actual template arguments> instant;
  37.  
  38. After that you can call
  39. instant(actual parameters);
  40.  
  41. The implementation of static operators would be strictly analogous to
  42. other static member functions: they would be passed no this-pointer, thus
  43. receiving no information of their first operand apart from its type
  44. (because they would not have been called was the type wrong). And in
  45. the special case of angels, there would be no more information to pass
  46. anyway.
  47.  
  48. Another choice for angels would be, say in complex arithmetic, a special
  49. angel called i, or maybe complexi because i is so common. Then you
  50. could provide conversion to complex, but also special multiplication
  51. operators making multiplication with complexi much more efficient than
  52. the usual complex multiplication.
  53.  
  54. So implementation of special constants in special number classes is an
  55. obvious argument for angels with operator syntax.
  56.  
  57. To talk about physical manifestations (the "this" pointer) of angels is
  58. obviously senseless, therefore they should only have static member
  59. functions. It is ugly to have to use nonstatic operators, especially
  60. as most compilers could implement static operators by simply leaving
  61. out the operator specific test for prohibiting static.
  62.  
  63. Dr Stroustrup argued that you could use nonstatic operators to the
  64. same effect, and that the compiler might optimize the "this" away.
  65. But the  same argument would obviate static member functions, and
  66. they seem to have enough importance to include them in C++.
  67.  
  68. Another suggestion was using constructors for a similar syntax for
  69. function calls of angels. But this is a hack, is much more
  70. difficult to keep track of, mixes function call semantics (clearly
  71. provided by operator()) with copying of objects and temporary
  72. instantiation. In short, it is far more dangerous.
  73.  
  74. So let's hear it for static operators. If static member functions have
  75. a purpose, and overloadable operators have, then obviously the combination
  76. will also have a purpose.
  77.