Const correctness revisited (proposal)

Oliver Dathe o.dathe at gmx.de
Mon Mar 24 02:56:01 PDT 2008


Walter Bright wrote:
> The reason there is no clean way to do this is because it is a 
> fundamentally unsound operation to do it. Doing so violates the 
> const-ness contract of the function. Please see my posts in the "const 
> debacle" thread. In other words,
> 
>    T[] f(const(T)[] t)
>    {
>     return t;
>    }
> 
> is wrong, wrong, wrong, and must not compile.

I completely agree on that.

That's right what pushed me to think about tail constness regarding 
parameters. You could have the cont-ness contract without touching the type.

   T[] f(T[] t const) {
     return t;
   }

It is a transient const-ness not a reflexive. It does not creep into 
types or out of the function. It is transitive in the way that it has to 
creep down subsequent calls within f() to functions that take t as 
paramter. That's all pretty sound isn't it? It as well avoids /polution/ 
of types at the same time.



More information about the Digitalmars-d mailing list