"is" operator for structures?
Gor Gyolchanyan
gor.f.gyolchanyan at gmail.com
Wed May 9 03:30:23 PDT 2012
I've stumbled upon a case, where I discovered, that what I did
actually isn't allowed:
struct SomeFancyPointer
{
public:
bool opBinary(string op : "is")(typeof(null))
{
return _address is null;
}
private:
void* _address;
}
unittest
{
assert(SomeFancyPointer.init is null);
}
After I got a message about SomeFancyPointer being incompatible with
typeof(null) of "is" comparison, I looked up at dlang.org the operator
overloading page and discovered, that "is" operator is not allowed to
be overloaded.
Granted, this limitation makes perfect sense for classes (just as
opAssign's limitation makes sense), but struct types are not reference
types, so an intrinsic "is" operator is usesless for them.
My question is, why not allow is operator to be overloadable for structures?
--
Bye,
Gor Gyolchanyan.
More information about the Digitalmars-d
mailing list