Why can't we define re-assignable const reference variable?

Janice Caron caron800 at googlemail.com
Wed Feb 20 13:47:08 PST 2008


On 20/02/2008, Sergey Gromov <snake.scaly at gmail.com> wrote:
> Modifying a slice which points i-dont-know-where feels unsafe to me.  I
>  won't use this feature as long as I can.

    string s = "hello world";
    s = s[6..$];

In what way is this unsafe?

>  > How could you declare
>  >
>  >     const(int[][][])[][][] x;
>  >
>  > without the brackets?
>
> This use of "partial const", in addition to "full const" and "tail
>  const", is specific to multi-dimentional arrays.  No other types can
>  make use of it.

Sure they can

    const(int***)*** x;

or, perhaps more usefully

    int[const(int)[]] map;

There are an infinity of possible examples.


>  With arrays, you probably can do with aliasing:
>
>         alias const int[][][] constArr;
>         constArr[][][] x;

And this to you would be a good thing?



More information about the Digitalmars-d mailing list