is() syntax (Re: operator new(): struct v. class)

Kirk McDonald kirklin.mcdonald at gmail.com
Mon Aug 20 18:09:43 PDT 2007


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.

-- 
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org



More information about the Digitalmars-d mailing list