scope ref const(T) --> error?!

Jonathan M Davis jmdavisProg at gmx.com
Thu May 3 17:29:09 PDT 2012


On Friday, May 04, 2012 00:43:14 Tove wrote:
> But nevertheless... the actual implemented semantics is the same
> for parameters as for the deprecated function body case, at the
> end of the function the parameter goes out of scope too! i.e.
> destructor should be called.

No, it's not the same semantics. scope on parameters is all about preventing 
escaping - and in the case of delegates, provides the the additional benefit of 
indicating that allocating a closure is unnecessary. If you did something like

MyClass foo(scope MyClass c)
{
 ...
}

c would _not_ have its destructor called. Rather, the compiler would guarantee 
that no reference to c had escaped the function (e.g. by being returned). This 
is _completely_ different from doing

void foo()
{
 scope c = new MyClass;
}

which is being replaced by std.typecons.scoped.

- Jonathan M Davis


More information about the Digitalmars-d mailing list