Should out/ref parameters require the caller to specify out/ref like in C#?

Ola Fosheim Grøstad via Digitalmars-d digitalmars-d at puremagic.com
Mon May 29 02:17:31 PDT 2017


On Monday, 29 May 2017 at 08:41:05 UTC, Jonathan M Davis wrote:
> With C++, if you have const T&, it will accept both lvalues and 
> rvalues. A number of folks (particularly those writing games) 
> want an equivalent to that in D where they can then pass both 
> lvalues and rvalues without incurring a copy.

Mmm. But it sounds more like a compiler hint on const value types 
could work? Except when the making of a copy creates 
side-effects... so you would have to guard against that.

The whole thing with temporaries in C++ in part lead to && move 
semantics. So this is a slippery slope, perhaps.

> solution that he'd be okay with (particularly with some of the 
> improvements that come with DIPs 25 and 1000). Ethan Watson has 
> expressed interest in writing a DIP on the matter, so I expect 
> that we'll see one at some point here.

I think D is going the wrong way with all this special casing. 
Memory management is hard enough as it is. At some point Rust's 
type system will look easier...

Much better if you can get away with using a compiler hint and 
give the compiler a flag that turns that hint into an absolute 
for the game-programmers.

It could also be an annotation on a type, that isn't part of the 
type. (This type should aways be passed as const-ref)



More information about the Digitalmars-d mailing list