equality operators on types

Timon Gehr timon.gehr at gmx.ch
Fri Jun 15 05:56:28 PDT 2012


On 06/15/2012 02:18 PM, Dmitry Olshansky wrote:
> On 15.06.2012 16:11, Timon Gehr wrote:
>> Why not allow equality operators to operate on types?
>>
>> is(==) expressions tend to create bracket noise and treat the two
>> arguments non-uniformly.
>>
>> This would suggest a little parser update, so that eg. 'int', '(int*)'
>> and 'int[]' are accepted as valid expressions. (this also potentially
>> improves compiler error messages.)
>>
>> void foo(T)(T arg){
>> static if(T==int){
>> ...
>> }else{
>> ...
>> }
>>
>
> Now one day some n00b uses run-time if-chains to create type-switch
> (that doesn't work because it would CT-defined):
> ...
> if( typeof(a) == Foo)
> ...
> else if(typeof(a) == Bar)
> ...
>

...
if(is(typeof(a) == Foo))
...
else if(is(typeof(a) == Bar)(
...

> Though "code is unreachable" warning might help with it.

Or any of the other compile time errors that is generated in the
unreachable code because it cannot compile with the given parameters.


More information about the Digitalmars-d mailing list