home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12724 < prev    next >
Encoding:
Internet Message Format  |  1992-08-21  |  2.2 KB

  1. Path: sparky!uunet!ogicse!mintaka.lcs.mit.edu!ai-lab!life.ai.mit.edu!tmb
  2. From: tmb@arolla.idiap.ch (Thomas M. Breuel)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: destruction of temporaries
  5. Message-ID: <TMB.92Aug21160625@arolla.idiap.ch>
  6. Date: 21 Aug 92 20:06:25 GMT
  7. Article-I.D.: arolla.TMB.92Aug21160625
  8. References: <1992Aug17.073500.24115@ericsson.se> <23466@alice.att.com>
  9.     <TMB.92Aug19113657@arolla.idiap.ch>
  10.     <1992Aug20.092752.29529@mole-end.matawan.nj.us>
  11. Sender: news@ai.mit.edu
  12. Reply-To: tmb@idiap.ch
  13. Organization: IDIAP (Institut Dalle Molle d'Intelligence Artificielle
  14.     Perceptive)
  15. Lines: 47
  16. In-reply-to: mat@mole-end.matawan.nj.us's message of 20 Aug 92 09:27:52 GMT
  17.  
  18. From: tmb@arolla.idiap.ch (Thomas M. Breuel)
  19. Newsgroups: comp.lang.c++
  20. Subject: Re: destruction of temporaries
  21. Date: 21 Aug 92 18:45:56 GMT
  22. Reply-To: tmb@idiap.ch
  23. Organization: IDIAP (Institut Dalle Molle d'Intelligence Artificielle
  24.     Perceptive)
  25. In-reply-to: mat@mole-end.matawan.nj.us's message of 20 Aug 92 09:27:52 GMT
  26.  
  27. In article <1992Aug20.092752.29529@mole-end.matawan.nj.us> mat@mole-end.matawan.nj.us writes:
  28.  
  29.    In article <TMB.92Aug19113657@arolla.idiap.ch>, tmb@arolla.idiap.ch (Thomas M. Breuel) writes:
  30.    Here's a thought.  There was, at one time, a suggestion for an `operator
  31.    void()' that describes the action of throwing away a value.  It gets used
  32.    for anything except the intialization of an object.  Would the `operator
  33.    void()' concept describe the point at which the temporary must be
  34.    discarded?
  35.  
  36. Under either rule, expressions can already be rewritten to obtain the
  37. desired lifetime. For example:
  38.  
  39.     X result = x.a().b().c().d();
  40.  
  41. Language: early destruction, Wanted: late destruction:
  42.  
  43.     X a = x.a();
  44.     X b = a.b();
  45.     X c = b.c();
  46.     X result = c.d();
  47.  
  48. Language: late destruction, Wanted: early destruction:
  49.  
  50.     X a = x.a();
  51.     X b = a.b();
  52.     destroy(a);
  53.     X c = b.c();
  54.     destroy(b);
  55.     X result = c.d();
  56.     destroy(c);
  57.  
  58. The question is: what should be the default. I don't think that
  59. mandatory late destruction solves anything, because if you start
  60. relying on the persistence of temporaries in expressions, the next
  61. step is that you'll get confused about why they don't hang around for
  62. the whole block.
  63.  
  64.                     Thomas.
  65.