<div dir="ltr">UFCS should just work only for 'functions'. <div class="gmail_extra">'foo' is not a function, rather it is a functor. So this is proper behavior.</div><div class="gmail_extra"><br></div><div class="gmail_extra">
Kenji Hara<br><br><div class="gmail_quote">2013/4/9 bearophile <span dir="ltr"><<a href="mailto:bearophileHUGS@lycos.com" target="_blank">bearophileHUGS@lycos.com</a>></span><br><blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
On request by Maxim Fomin I ask an opinion here. This is a very small enhancement request, that for me is borderline bug report (so originally I didn't plan in showing it in the main D newsgroup):<br>
<br>
<a href="http://d.puremagic.com/issues/show_bug.cgi?id=9857" target="_blank">http://d.puremagic.com/issues/<u></u>show_bug.cgi?id=9857</a><br>
<br>
<br>
<br>
Maybe this should be valid:<br>
<br>
<br>
struct Foo {<br>
    int opCall(bool b) {<br>
        return 0;<br>
    }<br>
}<br>
void main() {<br>
   Foo foo;<br>
   auto b1 = foo(true); // OK<br>
   auto b2 = true.foo;  // Error<br>
}<br>
<br>
<br>
dmd 2.063alpha gives:<br>
<br>
temp.d(9): Error: no property 'foo' for type 'bool'<br>
<br>
<br>
Explanation:<br>
<br>
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.<br>

<br>
<br>
2) Both struct constructors, struct implicit constructors and struct static opCall support UFCS, so I don't see a good reason for just the normal struct opCall to not support it:<br>
<br>
<br>
struct Foo {<br>
    static int opCall(int x) {<br>
        return x * 2;<br>
    }<br>
}<br>
struct Bar {<br>
    int x;<br>
    this(int y) {<br>
        x = y * 2;<br>
    }<br>
}<br>
struct Spam {<br>
    int x;<br>
}<br>
void main() {<br>
    assert(10.Foo == 20);<br>
    assert(10.Bar.x == 20);<br>
    assert(10.Spam.x == 10);<br>
}<br>
<br>
<br>
Jonathan Davis doesn't like this. For more information I suggest to take a look at the thread in Bugzilla.<br>
<br>
- - - - - - - - - - -<br>
<br>
Regarding UFCS, currently this doesn't work, I don't know if this should be considered a bug or not (I think the answer is positive):<br>
<br>
<br>
struct Node {}<br>
void foo(Node* p) {}<br>
void main() {<br>
    auto p = new Node();<br>
    foo(p); // OK<br>
    p.foo;  // Error: no property 'foo' for type 'Node'<br>
}<br>
<br>
<br>
Bye,<br>
bearophile<br>
</blockquote></div>'</div></div>