auto storage class - infer or RAII?

Bill Baxter wbaxter at gmail.com
Mon Nov 13 09:14:30 PST 2006


Andrey Khropov wrote:
> JC wrote:
> 
> 
>>void drawBox(Rectangle rect, Colour colour) {
>> scope (DrawingContext dc = createDrawingContext()) {
>>   scope (Pen pen = new Pen(colour)) {
>>     dc.drawRectangle(pen, rect);
>>   } // pen is freed here
>> } // dc is freed here
>>}
>>
>>Used this way, 'scope' as the RAII keyword makes sense.
> 
> 
> Heh, that's exactly how 'using' is used in C#.
> I prefer usual C++ - like RAII style.

Ugh yes.  Please don't force any more extra indentation levels on us! 
Its bad enough with 'with' already.
If you want a new indentation level for every single scoped variable 
then feel free to make scopes for them all,

void drawBox(Rectangle rect, Colour colour) {
   { scope DrawingContext dc = createDrawingContext();
     { scope Pen pen = new Pen(colour);
       dc.drawRectangle(pen, rect);
     } // pen is freed here
   } // dc is freed here
}

but don't force everyone to do that.

--bb



More information about the Digitalmars-d mailing list