Re: What is the correct way to forward method calls to the struct field?

2014-06-22 Thread monnoroch via Digitalmars-d-learn
Cool! Only this does not show me where the error was. __FILE__ and __LINE__ is not any help here, because it's a template. Any other way to find out where the actual error was?

Re: What is the correct way to forward method calls to the struct field?

2014-06-22 Thread monnoroch via Digitalmars-d-learn
Nah, this gives me lots of compiler crap, like .empty and others, when compiler tries to compile them.

Re: What is the correct way to forward method calls to the struct field?

2014-06-22 Thread Philippe Sigaud via Digitalmars-d-learn
On Sun, Jun 22, 2014 at 5:02 PM, monnoroch via Digitalmars-d-learn wrote: > Thanks a lot! > There is a problem though: when i pass incorrect parameters to > such a method, it says, that S has no such field, which is a > misleading error message. You can test the mixin with static if, like this:

Re: What is the correct way to forward method calls to the struct field?

2014-06-22 Thread Philippe Sigaud via Digitalmars-d-learn
On Sun, Jun 22, 2014 at 5:04 PM, monnoroch via Digitalmars-d-learn wrote: > There is also a problem: when i declare opDispatch to be private, > i still have access to this forwarding from another package. Is > it a bug or what? I don't know. I never used private in conjunction with a template. Le

Re: What is the correct way to forward method calls to the struct field?

2014-06-22 Thread monnoroch via Digitalmars-d-learn
Thanks a lot! There is a problem though: when i pass incorrect parameters to such a method, it says, that S has no such field, which is a misleading error message.

Re: What is the correct way to forward method calls to the struct field?

2014-06-22 Thread monnoroch via Digitalmars-d-learn
There is also a problem: when i declare opDispatch to be private, i still have access to this forwarding from another package. Is it a bug or what?

Re: What is the correct way to forward method calls to the struct field?

2014-06-21 Thread Philippe Sigaud via Digitalmars-d-learn
You can use 'auto' to let the compiler deduce the return type. Here I use 'foo' which returns an int and 'bar', which returns void. struct SomeT { int foo(double d) { return 0;} void bar(double d) { return;} } struct S { auto /* here */ opDispatch(string name, Args...)(Args arg

Re: What is the correct way to forward method calls to the struct field?

2014-06-21 Thread monnoroch via Digitalmars-d-learn
On Saturday, 21 June 2014 at 18:16:17 UTC, monnoroch wrote: Actyaly, last variant didn't work either: i was testing it inside S like "ifc.foo(1)", so UFCS kiked in, not alias this. Oh, my bad, "alias impl this;" actually did work. But the first argument problem still holds.

Re: What is the correct way to forward method calls to the struct field?

2014-06-21 Thread monnoroch via Digitalmars-d-learn
Actyaly, last variant didn't work either: i was testing it inside S like "ifc.foo(1)", so UFCS kiked in, not alias this.

What is the correct way to forward method calls to the struct field?

2014-06-21 Thread monnoroch via Digitalmars-d-learn
I tried this: struct S { R opDispatch(string name, R, Args...)(Args args) { return mixin("(*iface)." ~ name)(iface, args); } SomeT ** iface; } But then val.foo(1, 2) gives me "no property 'foo' for type 'S'". I've seen the template solution: struct S {