DMD 1.017 release
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Tue Jun 26 21:38:50 PDT 2007
Stewart Gordon wrote:
> "Walter Bright" <newshound1 at digitalmars.com> wrote in message
> news:f5s1k1$iuk$1 at digitalmars.com...
>> Chris Nicholson-Sauls wrote:
>>> Valid logic, but what about the common case of 'int f = 42;'? Maybe
>>> the rule should be that .init is either a /literal/ initializer's
>>> value, or a CTF initializer's value, or else the type's .init value.
>>> (I can recall having once or twice relied on a variable's .init being
>>> something particular.)
>>
>> How about, if it isn't a compile time constant, then using .init is an
>> error?
>
> Good idea. It would also enable
>
> is(typeof(x.init))
>
> to be used to test whether x's initializer is a compile-time constant.
> Don't know what practical use this would have though....
I think it would be useful in relation to what you mention below...
>> I think that if CTFE fails, having it silently revert to the
>> type.init, would be frustratingly obscure behavior.
>
> Agreed. Moreover, if they want the initializer of x's type, they can
> use typeof(x).init. So changing x.init to do the same not only alters
> the behaviour of existing code, but gains no real benefit in the process.
>
> Stewart.
Bingo. So it gets my vote. And to explain the first comment:
template TInit (alias var) {
static if (is(typeof(var.init))) { const TInit = var .init; }
else { const TInit = typeof(var).init; }
}
For those occasions where you want the old-style behavior for whatever
reason. :)
-- Chris Nicholson-Sauls
More information about the Digitalmars-d-announce
mailing list