An alternative to .init

Walter Bright newshound1 at digitalmars.com
Tue Sep 9 19:43:44 PDT 2008


Andrei Alexandrescu wrote:
> I hear you. I brought up the same exact design briefly with Bartosz last 
> week. We called it T.invalid. He argued in favor of it. I thought it 
> brings more complication than it's worth and was willing to go with 
> T.init for simplicity's sake. Why deal with two empty states instead of 
> one.
> 
> One nagging question is, what is T.fail for integral types? For pointers 
> fine, one could be found. For chars, fine too. But for integrals I'm not 
> sure that e.g. T.min or T.max is a credible fail value.

The T.init value should be that. That's why, for floats, float.init is a 
NaN. But for many types, there is no such thing as an invalid value, so 
it really doesn't work for generic code.


More information about the Digitalmars-d-announce mailing list