Wishlist proposal, documenting fn arg as in or out or mod

Steven Schveighoffer schveiguy at gmail.com
Fri Jun 23 02:24:07 UTC 2023


On 6/21/23 4:51 AM, Dom DiSc wrote:
> On Tuesday, 20 June 2023 at 20:44:42 UTC, GrimMaple wrote:
> 
>> `const ref Type` makes 0 sense, because all references are `const` 
>> already (you can't change the _reference_, you can change the 
>> _referenced object_). What you probably want to mean is `ref 
>> const(Type)` instead, making it a const reference to a const `Type`.
> 
> Oops. This is really stupid. Then you are right, it should always be 
> "ref const(T)".

`const` is both a type modifier, and a storage class. When used as a 
storage class, it means the type specified is attributed with the 
`const` type modifier. In certain contexts, it also can indicate that 
the variable should be stored in ROM.

So `const ref Type` makes sense, the `const` means "apply the `const` 
type modifier to the stored type".

So `const ref Type` is the same as `ref const Type` or `ref 
const(Type)`, the canonical form.

> So the nicer syntax is simply useless and confusing?
> If anything, I would propose to change that:
> "const ref T" should be identical to "ref const(T)"

It does mean this.

-Steve


More information about the Digitalmars-d mailing list