const debacle
Janice Caron
caron800 at googlemail.com
Wed Mar 26 11:54:48 PDT 2008
On 26/03/2008, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
> The complication comes with "Oh God, I now have 3 const types, which one do
> I choose?!" But I think this is answered in one paragraph (inout is only
> available as a function parameter, so that is the only time where this
> becomes an issue):
Well, technically speaking, you /could/ declare a variable with inout
constancy - even at global scope. (Forbidding it would be more
complicated than allowing it).
inout T x;
However, doing so would be pointless, since nothing implicitly casts
to inout, so you couldn't even assign it (except from another inout)
without an explicit cast!
inout T x = anything; /*error*/
(I'm just being pedantic for the hell of it now! It's just so I can be
sure I have a good grasp of the basics).
> Really, the most complicated part of this is the implementation of it in the
> compiler.
Oddly, I think that will be relatively easy, since the rules are plain
and straightforward. By and large, inout(T) behaves just like
const(T), except that it is a distinct type and there are rules about
what will implicitly cast into what. The triple-lookup at call-time
can't be /that/ hard, I wouldn't have thought.
I think we're onto a winner here.
More information about the Digitalmars-d
mailing list