Friends don't let friends use inout with scope and -dip1000
Steven Schveighoffer
schveiguy at gmail.com
Mon Aug 20 13:41:32 UTC 2018
On 8/20/18 5:43 AM, Nicholas Wilson wrote:
> On Monday, 20 August 2018 at 09:31:09 UTC, Atila Neves wrote:
>> On Friday, 17 August 2018 at 13:39:29 UTC, Steven Schveighoffer wrote:
>>>> // used to be scope int* ptr() { return ints; }
>>>> scope inout(int)* ptr() inout { return ints; }
>>>
>>> Does scope apply to the return value or the `this` reference?
>>
>> I assumed the return value. I think I've read DIP1000 about a dozen
>> times now and I still get confused. As opposed to `const` or
>> `immutable`, `scope(T)` isn't a thing so... I don't know?
A type constructor affects the type of something. So const(int) is an
int that is const.
const int is actually NOT a type constructor, but a storage class. It's
main effect is to make the int actually const(int), but can have other
effects (e.g. if it's a global, it may be put into global storage
instead of thread-local).
scope is not a type constructor, ever. So how do you specify the return
type is scope? How do you specify a difference between the scope of the
'this' pointer, and the scope of the return value?
I'm super-confused as to what dip1000 actually is doing, and how to use it.
>>
> What usually happens is that qualifiers to the left of the name apply to
> the return type and those to the right apply `this`. Not that that
> _should_ make any difference since lifetime ints == lifetime this
>
No:
const int* foo() const { return null; }
Error: redundant const attribute.
Up until 2.080, this was a deprecation, and the result was int *
>>> What happens if you remove the return type? (i.e. scope auto)
>>
>> And write what instead?
>>
>
> scope ptr() inout { return ints; } ?
Yes, this is what I was thinking.
-Steve
More information about the Digitalmars-d
mailing list