DMD 0.160 release
Jarrett Billingsley
kb3ctd2 at yahoo.com
Sun Jun 4 13:08:10 PDT 2006
"Jarrett Billingsley" <kb3ctd2 at yahoo.com> wrote in message
news:e5ved4$2bod$1 at digitaldaemon.com...
> Operator overloading of "in"? Cool, but I can't seem to get it to work; I
> don't know what argument and return types are allowed, as it's listed in
> the Operator Overloading specs but has no documentation. I tried:
>
> class A
> {
> int* opIn(char[] name)
> {
> return null;
> }
> }
>
> void main()
> {
> A a = new A();
> int* i = ("hi" in a);
> }
>
> And all it said was that the rvalue of an InExpression must be an AA. I
> tried a few different return types to no avail; I thought maybe it wanted
> a pointer type (as that's what in returns for AAs) but it obviously
> doesn't work.
Oh dear. I saw Kirk's post, and thought "oh no." Sure enough, this works:
class A
{
bool opIn(char[] name)
{
if(name == "hi")
return true;
else
return false;
}
}
void main()
{
A a = new A();
writefln(a in "hi");
writefln(a in "bye");
}
Notice that the expressions for 'in' are reversed. It looks like I'm
checking to see if the object 'a' exists in the strings "hi" and "bye".
Bug #1... ;)
More information about the Digitalmars-d-announce
mailing list