Spec#, nullables and more

Simen kjaeraas simen.kjaras at gmail.com
Sat Nov 6 03:30:29 PDT 2010


Simen kjaeraas <simen.kjaras at gmail.com> wrote:

> bearophile <bearophileHUGS at lycos.com> wrote:
>
>> Simen kjaeraas:
>>
>>> Not sure. This way is more explicit, and errors will be caught at
>>> compile-time.
>>
>> I see. But if a syntax is ugly and too much heavy, people (rightly)  
>> don't use it... (This is why bounded values are good as builtins).
>
> Of course. Now, aliases help a bit here, turning that into something
> like:
>
> alias Bounded!(int, 1, 5) myInt;
>
> myInt[] myArr;
> myArr ~= myInt( 1 );
>
>
> I believe using an alias would be a good idea in most such cases, as
> one's bound to write Bounded!(int,1,6) in a long program, and
> wonder why it doesn't compile.

Worth adding too: myInt(648492) is of course not catchable at compile
time, while such would be easy with builtin bounded integers.


-- 
Simen


More information about the Digitalmars-d mailing list