On Sun, May 30, 2010 at 17:04, bearophile <bearophileHUGS@lycos.com> wrote:
struct Foo(T) {
   this(T x) {}
   void opCall(U)(U y) {}
}
void main() {
   auto foo = Foo!int(1);
   foo(1.5);
}

I've had this one too. I think it's a bug, because foo is already constructed when foo(1.5) is used. So the compiler should know it's an opCall and not a constructor call.
The only solution I found was a kludge:


struct Foo(T)
{
   void initialize(T)(T x) {} // in my case, their was some data initialization there.
   void opCall(U)(U y) {}
}

Foo!T foo(T)() { Foo!T f; f.initialize(); return f;}

void main() {
    auto f = foo(1);
   f(1.5);
}


Philippe