The next iteration of scope
Nick Treleaven via Digitalmars-d
digitalmars-d at puremagic.com
Mon Mar 16 05:21:17 PDT 2015
On 15/03/2015 19:11, "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm at gmx.net>"
wrote:
> On Sunday, 15 March 2015 at 17:31:17 UTC, Nick Treleaven wrote:
>> I too want a scope attribute e.g. for safe slicing of static arrays,
>> etc. I'm not sure if it's too late for scope by default though, perhaps.
>
> If we get @safe by default, we automatically get scope by default, too.
I don't follow that. In @safe code parameters could still default to
escaping, causing compiler errors when passing things that can't be
allowed to escape.
I do see that scope parameters by default would probably cause less
churn than having to put `scope` on non-template function parameters in
order to be usable by non-GC-heap memory.
>> scope T payload;
>>
>> ^ This is a nice way to help enforce the correctness of @safe wrapper
>> types.
>
> Yes, it's an exception to the general rule of "scope only in function
> signatures", but it's so useful I think it's worth it.
We already have scope on local delegates (at least it's accepted by dmd):
Object obj;
scope del = ()=>obj;
Also, what would be the 'type' of a static array slice without `scope`
applying to locals?
int[2] arr = [1, 2];
scope int[] s = arr;
I suppose `scope` can be inferred for s, I'm just pointing out that it
can apply to locals.
More information about the Digitalmars-d
mailing list