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

Sergey Gromov snake.scaly at gmail.com
Thu Feb 21 06:25:23 PST 2008


Janice Caron <caron800 at googlemail.com> wrote:
> 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?

This is Ok.  It's changing the .length directly which I don't like, and 
which is actually unpredictable.

> 
> >  > 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.

Ok I see.

Rounding up our discussion, all the argument was because I misunderstood 
the type system.  And, judging from this syntax is discussed often and 
even was supported in the compiler for some time, I'm not alone in my 
misunderstanding.  Seems like an educational problem.

-- 
SnakE



More information about the Digitalmars-d mailing list