structs are now lvalues - what is with "auto ref"?

Jonathan M Davis jmdavisProg at gmx.com
Mon Dec 24 12:56:56 PST 2012


On Monday, December 24, 2012 21:42:09 monarch_dodra wrote:
> Side question, is this legal?
> 
> "int a = min(min(1,2), min(3,4));"
> 
> How long do those temps last? I like this piece of code, because
> the previous had that fishy "const int&", which raises eyebrows,
> but I think this example could blindsind even the most careful
> programmer.
> 
> EDIT: In this specific example, those might be statics, so the
> code would be legal, but what if we replace those ints with
> "foo()"s ?

As I understand it, temporaries last for the duration of the statement that 
they're used it. So, the example would be legal and completely safe.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list