D does have head const (but maybe it shouldn't)

John Colvin john.loughran.colvin at gmail.com
Tue Dec 29 19:42:28 UTC 2020


On Tuesday, 29 December 2020 at 17:56:51 UTC, H. S. Teoh wrote:
> On Tue, Dec 29, 2020 at 05:13:48PM +0000, Petar via 
> Digitalmars-d wrote:
>> [...]
> [...]
>> > [...]
> [...]
>> [...]
>
> I don't see why this is considered head const, nor why this 
> should be considered a bug. In the proposed solution `y` is not 
> a value type but a delegate that wraps the reference to *x.  
> Since x itself is non-const, this is perfectly valid, and the 
> `const` in `const y` refers to the immutability of the delegate 
> reference, not to the immutability of the wrapped reference.
>
>
> T

It's a const variable that contains a mutable reference. It's 
head-const.


More information about the Digitalmars-d mailing list