Is my understanding below correct? Does any documentation need updating?

Operator precedence table lists !in as an operator:

  http://wiki.dlang.org/Operator_precedence

Operator overloading documentation does not mention it:

  http://dlang.org/operatoroverloading.html#binary

However, 'a !in b' seems to be lowered to '!(a in b)'. It is possible to define "!in" but it is never called:

struct S
{
    bool opBinaryRight(string op)(int i) const
        if (op == "in")
    {
        import std.stdio;
        writeln("in");
        return true;
    }

    bool opBinaryRight(string op)(int i) const
        if (op == "!in")
    {
        // Never called
        assert(false);
        return false;
    }
}

void main()
{
    auto s = S();
    assert(42 in s);
    assert(!(42 !in s));
}

The "in" overload gets called twice:

in
in

Ali
  • !in operator Ali Çehreli via Digitalmars-d-learn

Reply via email to