DIP69 - Implement scope for escape proof references

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Thu Dec 11 08:26:57 PST 2014


On 12/11/14 8:55 AM, "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm at gmx.net>" 
wrote:
> On Thursday, 11 December 2014 at 12:48:05 UTC, Manu via Digitalmars-d
> wrote:
>> On 8 December 2014 at 07:29, Walter Bright via Digitalmars-d
>> <digitalmars-d at puremagic.com> wrote:
>>> On 12/7/2014 6:12 AM, Dicebot wrote:
>>>>
>>>> But from existing cases it doesn't seem working good enough. For
>>>> example,
>>>> not
>>>> being able to represent idiom of `scope ref int foo(scope ref int x) {
>>>> return x;
>>>> }` seems very limiting.
>>>
>>>
>>>   scope ref int foo(ref int x);
>>>
>>> will do it.
>>
>> Will it? It looks like foo can't be called with scope data?
>
> This is a point that most people don't seem to understand yet, and which
> wasn't obvious for me either, at the beginning:
>
> * A `ref` parameter means that it cannot escape the function, _except_
> by return.
> * A `scope ref` parameter means that it cannot escape the function
> _ever_, not even by return.
> * A `scope ref` return means that it cannot leave the current statement.
>
> Therefore, a `scope ref` return value can be passed on to the next
> function as a `ref` argument. If that function again returns a reference
> (even if not explicitly designated as `scope`), the compiler will treat
> it as if it were `scope ref`.

Please, put this in the DIP! This is exactly the thing I had been asking 
for here: http://forum.dlang.org/post/m5sitd$1ki0$1@digitalmars.com

Thanks, I'll re-read the proposal with this in mind.

-Steve


More information about the Digitalmars-d mailing list