opImplicitCast/opImplicitCastFrom

Simen Kjaeraas simen.kjaras at gmail.com
Mon Oct 27 08:43:38 PDT 2008


On Mon, 27 Oct 2008 15:25:32 +0100, bearophile <bearophileHUGS at lycos.com>  
wrote:

> KennyTM~:
>> The Bounded!() (originally Positive!()) template suggested by Andrei
>> earlier?
>
> No, I mean something built-in, and generally invisible. See  
> ObjectPascals.
>
>
>> When a programmer cares for integer overflow one can use  
>> Bounded!(T.min, T.max).
>
> Nope. It has to be the other way round: when a programmer doesn't care  
> of avoiding some integer-related bugs he/she/shi can add a "-release" to  
> the compilation arguments. Forcing the programmer to use an ugly and  
> long syntax everywhere in the program isn't a way to avoid that class of  
> bugs in most D programs.
>
> Bye,
> bearophile

So make all the normal built-in types (uint, int, float, etc) throw  
exceptions, and give access to lower-level types marked as unsafe.
Basically, rename uint to 'uint_unsafe', and provide 'uint' as a typedef  
of Bounded!(uint_unsafe.min, uint_unsafe.max).
I feel uint_unsafe is too long a name, but I'm sure something could be  
worked out (_uint?).

I do believe this would eliminate some bugs, and having programmed quite a  
lot in ObjectPascal, I agree its nice to have.

-- 
Simen



More information about the Digitalmars-d mailing list