equality operators on types
Timon Gehr
timon.gehr at gmx.ch
Sat Jun 16 04:26:20 PDT 2012
On 06/16/2012 07:19 AM, Bernard Helyer wrote:
> On Friday, 15 June 2012 at 12:56:49 UTC, Timon Gehr wrote:
>> On 06/15/2012 02:19 PM, bearophile wrote:
>>> Timon Gehr:
>>>
>>>> Why not allow equality operators to operate on types?
>>>
>>> That's nice, of course. But is it possible?
>>>
>>
>> Yes, certainly.
>
> Not without losing the context insensitivity of the D grammar (because
> now we can't say for certain what "T == J" is
It is a comparison. That suffices for the parser. The grammar stays
completely context-independent.
> until we semantically
> understand the program, but as it is now we understand it as comparing
> two values).
As it is now we don't know what it will do.
import some.other.module;
S a, b;
bool c = a == b;
///////
module some.other.module
struct S{ bool opEquals(){ hardDrive.format(); assert(0); } }
> That's a big thing to throw away,
T[2] foo;
auto b = foo[1]; // is this legal?
> and this doesn't justify the change.
>
> -Bernard.
I don't think this argument is valid.
More information about the Digitalmars-d
mailing list