Topic: What is a full-expression?


Author: "John Hickin" <hickin@nortelnetworks.com>
Date: 1999/10/24
Raw View
Darin Adler wrote:
>

> No. There's nothing that would copy the temporary X in your example.
>

That's what I thought. OTOH, some modifications could generate a
temporary and therefore it might be wise, as someone pointed out in a
private correspondence to me that propmted my primary question, to equip
X with destructive copy semantics in order to preserve the locking
properties:

  extern X fout();
  #define COUT() cout << fout()

Regards, John.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: Darin Adler <darin@bentspoon.com>
Date: 1999/10/22
Raw View
John D. Hickin <hickin@Hydro.CAM.ORG> wrote:

> The example that prompts my question is:
>
> #inlcude <iostream>
> using namespace std;
>
> struct X { X() ~X(); };
>
> ostream& operator<<( ostream& str , const X& x ) { return str; }
>
> cout << X() << something << somethingElse;
>
> I'm rather hoping that ~X() is called at the end of the full-expression
> in which the temporary is created (see 12.2 subsection 5) and that, in
> this case, the full-expression extends to the semi-colon.

That's right.

> As a secondary question, are there situations in this example in which
> the temporary X could be copied and therefore destroyed before I'm
> wanting it to be destroyed?

No. There's nothing that would copy the temporary X in your example.

    -- Darin
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "John D. Hickin" <hickin@Hydro.CAM.ORG>
Date: 1999/10/21
Raw View
The example that prompts my question is:

  #inlcude <iostream>
  using namespace std;

  struct X { X() ~X(); };

  ostream& operator<<( ostream& str , const X& x ) { return str; }

  cout << X() << something << somethingElse;

I'm rather hoping that ~X() is called at the end of the full-expression
in which the temporary is created (see 12.2 subsection 5) and that, in
this case, the full-expression extends to the semi-colon.

As a secondary question, are there situations in this example in which
the temporary X could be copied and therefore destroyed before I'm
wanting it to be destroyed?

In real life X() acquires a lock and ~X() releases it. Depending on how
op<<() is implemented, ~X() could also flush the stream and the output
could be redirected away from that referenced by str.

TIA, John.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]