is() syntax (Re: operator new(): struct v. class)
Don Clugston
dac at nospam.com.au
Tue Sep 4 00:28:51 PDT 2007
Kirk McDonald wrote:
> Bill Baxter wrote:
>> And why do we even need is() to do basic type comparisons anyway?
>> What's ambiguous about
>> static if( MyType == OtherType ) {
>> ...
>> }
>> ?
>> I guess you could define a static opEquals, but A) that's useless
>> enough that it could be outlawed B) it wouldn't take a type as an
>> argument so it still wouldn't be ambiguous.
>>
>> --bb
>
> It is ambiguous. Both sides of a comparison must be an expression, and
> types are not expressions. Allowing that would mean you couldn't
> determine whether 'MyType' is an expression or a type until after the
> syntactic pass. This would break some cardinal rules about the ease with
> which you can parse D code.
Ideally, I think, we'd have a merge between is() and typeof()/typeid()
static if (typeid(MyType)==typeid(OtherType)) {
}
There are quite a few cases where we have syntax which is completely different
at run-time compared to compile compile-time, yet which do exactly the same
thing. __traits and typeinfo seem to be awfully similar, for example.
If they were unified, CTFE could grab even more territory from templates.
More information about the Digitalmars-d
mailing list