What is the case against a struct post-blit default constructor?

Jonathan M Davis jmdavisProg at gmx.com
Fri Oct 12 00:25:26 PDT 2012


On Friday, October 12, 2012 06:42:23 Simen Kjaeraas wrote:
> Anyways, is there a reason you cannot use @disable this() for SysTime?
> That way,
> you have rather explicitly marked .init as invalid.

Disabling init does a lot to make a type unusable such that it really doesn't 
make sense to use it unless you need to. It's not that you can't have init. 
It's that you need to make sure that you actually set it to a valid value 
before calling any functions on it. If init were disabled, then you couldn't 
do stuff like

SysTime[12] times;

which should be perfectly fine as long as you make sure to set them all before 
actually calling any functions on them, e.g.

foreach(i, ref t; times)
    t  = calcTime(i);

Think of it like NaN or null. You can have variable set to them, and it's not 
a problem. It's only once you try to use functions or operators on them that 
they blow up.

- Jonathan M Davis


More information about the Digitalmars-d mailing list