Const Ideas

Janice Caron caron800 at googlemail.com
Sat Dec 1 11:44:04 PST 2007


On 12/1/07, Janice Caron <caron800 at googlemail.com> wrote:
> On 12/1/07, Bill Baxter <dnewsgroup at billbaxter.com> wrote:
> > Pointers can be stacked like T***.  References cannot.
>
> You are completely correct, of course. T&& is the same type as T& (or
> indeed, T&&&&&&&).
>
> Honestly, I don't mind if we end up with a syntax of
>
>     ref const(X) x; // mutable reference to const data
>
> instead of
>
>     const(X)& x; // mutable reference to const data
>
> Either will make me happy.

Actually, the "ref" way is better than the "&" way. (Do I get to
change my mind again?) Here's why. Imagine a time in the future when
we have references to things that aren't classes - say, ints, structs,
whatever. When that day comes, we'll need a way to distinguish between
"assign the reference" and "assign the data". Well, the obvious syntax
for that is

    x = y; // assign the data
    x ref= y; // assign the reference

Obviously, &= is already taken! :-)



More information about the Digitalmars-d mailing list