Hi!

I'm trying to remove an item from an array of objects. But I get error messages when compiling (see below) which I do not understand. I figured I had to override opEquals for it to work, but no.
How do I get this to work?

Regards



    class A
    {
        this(string si, uint ui) { s = si; u = ui; }
        string s;
        uint u;

        override bool opEquals(Object obj)
        {
            A o = cast(A)obj;
            return (s == o.s) && (u == o.u);
        }
    }

    int main(string[] argv)
    {
        import std.stdio: writeln;
        import std.algorithm: remove;
        A a = new A("a", 1);
        A b = new A("b", 2);
        A[] as = [a, b];
        as.remove(a);
        writeln(as);

        return 0;
    }


Error:

/usr/include/dmd/phobos/std/algorithm/mutation.d(1503): Error: template std.range.primitives.popFrontExactly cannot deduce function from argument types !()(A[], A), candidates are: /usr/include/dmd/phobos/std/range/primitives.d(1791): std.range.primitives.popFrontExactly(Range)(ref Range r, size_t n) if (isInputRange!Range) /usr/include/dmd/phobos/std/algorithm/mutation.d(1504): Error: template std.range.primitives.popFrontExactly cannot deduce function from argument types !()(A[], A), candidates are: /usr/include/dmd/phobos/std/range/primitives.d(1791): std.range.primitives.popFrontExactly(Range)(ref Range r, size_t n) if (isInputRange!Range) /usr/include/dmd/phobos/std/algorithm/mutation.d(1505): Error: cannot implicitly convert expression (from) of type dummy.A to ulong dummy.d(21): Error: template instance std.algorithm.mutation.remove!(cast(SwapStrategy)2, A[], A) error instantiating

Reply via email to