Stepping back and looking at constness from another angle.

Don Clugston dac at nospam.com.au
Wed Jun 6 23:40:46 PDT 2007


Reiner Pope wrote:
> Another problem with const by default came to mind. Consider the 
> following code, with const-not-by-default:
> 
> void foo( ref const(char)[] c)
> {
>     c = c[1..$];
> }
> 
> I would hate to see this in const-by-default, which would try to wrap a 
> const( ) around the whole type. To counter that, you would probably have 
> to write some mess like
> 
> void foo ( mutable( ref const(char)[] ) c )
> {
>     c = c[1..$];
> }
> 
>   -- Reiner

I would expect 'ref' be implicitly non-const. Especially since 'ref' is a 
synonym for 'inout' at present.



More information about the Digitalmars-d mailing list