DIP69 - Implement scope for escape proof references
Walter Bright via Digitalmars-d
digitalmars-d at puremagic.com
Tue Dec 9 14:24:52 PST 2014
On 12/8/2014 3:14 PM, Dicebot wrote:
> On Monday, 8 December 2014 at 21:12:47 UTC, Walter Bright wrote:
>> On 12/8/2014 12:54 PM, Dicebot wrote:
>>> struct ByLine
>>> {
>>> scope string front();
>>> // ...
>>> }
>>>
>>> auto byLine(File file)
>>> {
>>> return ByLine(file);
>>> }
>>>
>>> scope /* ref */ string foo(scope /* ref */ string input)
>>> {
>>> return input[1..$];
>>> }
>>>
>>> void main()
>>> {
>>> auto r = file.byLine.map!foo;
>>> string s = r.front; // this should not compile
>>> string s = r.front.dup; // this should compile
>>>
>>> // how foo signature should look like for this to work?
>>> }
>>
>> front() should return a 'scope ref string'.
>
> That seems to contradict your other statement:
>
>> A 'scope ref' parameter may not be returned as a 'ref' or a 'scope ref'.
Just make it a 'ref' parameter.
> Please check `foo()` once more - it needs to accept scope (ref) to be able to
> accept ByLine.front as an argument. And it also needs to pass it down the call
> chain - but returning `input` by reference is illegal according to
> abovementioned rule.
It can still be passed down as a 'ref' parameter.
More information about the Digitalmars-d
mailing list