DIP1000: Scoped Pointers (Discussion)

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Mon Aug 15 06:36:00 PDT 2016


On 8/15/2016 5:17 AM, Dicebot wrote:
> On 08/15/2016 02:52 PM, Walter Bright wrote:
>> On 8/15/2016 2:32 AM, Kagamin wrote:
>>> On Sunday, 14 August 2016 at 20:02:35 UTC, Walter Bright wrote:
>>>> auto r = range;
>>>
>>> You said that if a value (range in this case) is returned by scope,
>>> its lifetime
>>> is restricted to its expression, hence it can't be assigned to a
>>> variable,
>>> because the variable outlives the expression.
>>
>> A very good question. If the functions parameters are 'return scope',
>> that means the returned value has the (smallest) scope if its 'return
>> scope' parameters. If there are no 'return scope' parameters, the scope
>> of the return value is limited to the expression.
>
> Does that mean that a scope return in aggregate method will bind to
> aggregate lifetime if method itself is annotated with scope too? For
> example:
>
> struct Container
> {
>     scope Range asRange ( ) scope
>     {
>         return Range(&this.data);
>     }
> }

If the method is annotated with scope, the scope applies to the 'this' pointer.



More information about the Digitalmars-d mailing list