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

Janice Caron caron800 at googlemail.com
Sat Mar 8 23:52:44 PST 2008


On 09/03/2008, Yigal Chripun <yigal100 at gmail.com> wrote:
>  also perhaps it's worth considering to remove the const T syntax from
>  the language and always require parens.

The bad news is, that would also disallow

    const x = 3;

and

    const
    {
        int x = 3;
        int y = 4;
    }

The problem here is that "const" is an "attribute" in the grammar, and
therefore can be used anywhere "public", "static", "auto",
"version(X)", and so on can be used. Changing that would be a major
upheaval.

The simplest route to re-assignable const reference is probably a
template solution. In fact, if you look at the change log for D2.012,
you'll see that it says: "std.typecons: added undocumented Rebindable
in preparation for opImplicitCast." So, that sounds to me like as the
language permits (as soon as we have opImplicitCast) we'll also have
Rebindable!(T) - a rebindable class reference. We just need to hang on
a little bit longer.



More information about the Digitalmars-d mailing list