Const sucks

Janice Caron caron800 at googlemail.com
Mon Sep 10 15:52:20 PDT 2007


On 9/10/07, Walter Bright <newshound1 at digitalmars.com> wrote:
> Think of a struct which was your own implementation of arrays:
>
> struct Array(T)
> {
>      T[] a;
> }
>
> To create a tail const array, instead of const(T)[], we'd do
> Array!(const(T)).

While that does make sense, I guess what we really want to know is why
we won't be able to do this:

 struct MyArray
 {
     int[] p;
 }

and then make a tail const version with some magic keyword like

 tailconst(MyArray)

That is, tailconst(T) could be some built-in keyword which created a
new type which was just like T except that all its pointers would be
const.

Are you saying this is such a rare thing to want to do that it's not
worth supporting generically? I can't say I've ever needed it up to
now.



More information about the Digitalmars-d mailing list