equality operators on types

Dmitry Olshansky dmitry.olsh at gmail.com
Fri Jun 15 06:58:34 PDT 2012


On 15.06.2012 16:56, Timon Gehr wrote:
> 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)(
> ...
>

Well that looks unnatural, noobs would have a reason to suspect something.

>> 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.
Except that type switch "usually" (if they could be counted as usual at 
all) followed by a cast to the said type. Think trash quality polymorphism.

-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list