Latest const expansion

Regan Heath regan at netmail.co.nz
Wed Sep 12 01:20:26 PDT 2007


Janice Caron wrote:
> On 9/11/07, Bill Baxter <dnewsgroup at billbaxter.com> wrote:
>> So for that reason another
>> keyword is preferable I think.  Like 'final'.  Or maybe headconst or
>> 'hconst'.
> 
> We've had the keyword final for some time in D2.0, specifically for
> the purpose of head-constness, so if it's deemed that we need it,
> final would be as good a keyword as any.
> 
> But do we need it? Is there a need for head const at all?
> 
> Walter seems to have concluded that it's not needed. And every use
> case I can think of could be done by other means, so I think I agree.
> 
> In every single circumstance I can think of,
> headconst(T) x;
> 
> could simply be replaced by
> T x;
> 
> and nothing would fall over. What is gained by the head-constness?
> It's totally local.

Local to the body of a class, for example.  Local to the global scope of 
the program also.

I think it's useful in that it provides a guarantee that a 
reference/pointer itself will never change, which is a boon for 
multithreaded work for example.  Allowing reads using that 
reference/pointer without locking (in some cases).

Regan



More information about the Digitalmars-d mailing list