Why can't I give a function's return type the scope storage class?
Meta
jared771 at gmail.com
Tue Mar 19 02:22:08 UTC 2019
On Tuesday, 19 March 2019 at 02:03:12 UTC, Walter Bright wrote:
> On 3/18/2019 10:20 AM, Meta wrote:
>> So to be clear, you *can* add scope to the return type of a
>> function, and it will propagate the shortest lifetime among
>> any parameters marked with `return` or `return scope` to the
>> return value?
>
> No. Adding scope as the storage class of the function means it
> is attached to the 'this' parameter, if any.
Ah, I misinterpreted what you meant when you said "Scope on
function return values comes from the scope of any arguments
passed to the function marked as 'return scope'."
I pictured this:
scope T* doSomething(return scope T*);
Where the `scope` is attached to the T* return value, not to the
function, but I think what you meant was this:
T* doSomething(return scope T*);
scope val = doSomething(someOtherVal);
Right?
> Any 'return scope' parameter to the function will constrict the
> lifetime of the return value to that of the smallest lifetime
> of such arguments.
Yes, I've got it now. Thank you.
>> Also, I'd like to echo the request that you document this
>> stuff. What's already there is fairly useful, but obviously
>> it's not complete.
>
> It can be improved. But my focus at the moment is getting
> Phobos to compile with -dip1000.
Once I get a feel for DIP1000, I can hopefully help with that a
bit.
More information about the Digitalmars-d
mailing list