Why the need for an only const ref?

Derek Parnell derek at psych.ward
Fri Nov 30 22:49:27 PST 2007


On Sat, 1 Dec 2007 06:17:16 +0000, Janice Caron wrote:

> On 11/30/07, Jesse Phillips <jessekphillips at gmail.com> wrote:
>> What is the need for a X const x which lets you change the object in x
>> but not reassign it to another X?
> 
> It's not needed at all. What you're describing is "head const", and
> Walter just ditched it.
> 
> Head-constness is a purely local thing. It's always possible to do without it.

What is a D code example that catches inadverant reallocations at compile
time?

   char[] Buffer = new char[MAXBUFSIZE];
   . . . 
   Buffer ~= "abc";   // Oops. This is not allowed because
                      // the designer wanted to avoid
                      // excess memory allocations.
   . . .



-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell



More information about the Digitalmars-d mailing list