[Issue 9857] UFCS for struct opCall

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Apr 2 10:11:01 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9857



--- Comment #2 from bearophile_hugs at eml.cc 2013-04-02 10:11:00 PDT ---
(In reply to comment #1)
> That seems like a stretch.. why would you need this?

1) I am using UFCS often in D, for functions, higher order functions, etc. A
struct with an opCall method is usable like a function with state. So for
uniformity with the other functions I'd like to use it with UFCS. When you have
a long UFCS chain you don't want to break it, if it's possible.


2) Both struct constructors, struct implicit constructors and struct static
opCall support UFCS, so I don't see a good reason for the normal struct opCall
to not support it:


struct Foo {
    static int opCall(int x) {
        return x * 2;
    }
}
struct Bar {
    int x;
    this(int y) {
        x = y * 2;
    }
}
struct Spam {
    int x;
}
void main() {
    assert(10.Foo == 20);
    assert(10.Bar.x == 20);
    assert(10.Spam.x == 10);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list