any news on const/invariant?

Derek Parnell derek at nomail.afraid.org
Mon Nov 26 22:39:31 PST 2007


On Tue, 27 Nov 2007 10:48:42 +0900, Bill Baxter wrote:

> 0ffh wrote:
>> Derek Parnell wrote:
>>> I am under the impression that this is a fairly common way of doing 
>>> things.
>>>
>>>    byte[] bitmap;
>>>
>>>    bitmap = LoadBitMapFromFile("worldroadmap.bmp");
>>>    GammaAdjust(bitmap, 0.20);
>> 
>> void GammaAdjust(ref byte[] bitmap,float gamma) ?
> 
> byte[] bitmap;
> bitmap = LoadBitMapFromFile("worldroadmap.bmp");
> byte[] same_bitmap = bitmap;
> GammaAdjust(bitmap, 0.20);
> assert(bitmap.ptr is same_bitmap.ptr, "Error GammaAdjust not supposed to 
> change the bitmap pointer");

Okay, I get it. We don't actually need const/invariant at all. Instead we
just sprinkle our code with asserts to catch these compile-time errors at
run-time. Neat.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
27/11/2007 5:37:49 PM



More information about the Digitalmars-d mailing list