Re: delegate with optional parameters
On Monday, 3 April 2017 at 05:00:15 UTC, Inquie wrote: Yes, but they are really not any different. They only look different. A field can be a function just like a method because they look exactly the same except on is in a vtable and the other is in the fields memory. But both point functions. It should be possible to create a wrapper struct around your 'overloads' with an opDispatch which selects the right delegate.
Re: delegate with optional parameters
On Monday, 3 April 2017 at 03:08:22 UTC, Ali Çehreli wrote: On 04/02/2017 03:24 PM, Inquie wrote: >> Show a usage, someone certainly propose a pattern that does the job. > > int delegate() f; > void delegate(int) f; That won't work because both of those are variables and variables don't have overloading. > These are effectively overload methods, but my guess is that D won't > support it like overloads. > e.g., > > int f(); > void f(int); Yep, both 'f' are functions there. I'm having difficulty understanding your actual need as well. :/ A guess: It is possible to determine delegate parameter list at compile time like std.concurrency.receive does. Ali Yes, but they are really not any different. They only look different. A field can be a function just like a method because they look exactly the same except on is in a vtable and the other is in the fields memory. But both point functions. The only difference is that we can't write to the vtable to overwrite a value easily but we can to a delegate(no hackery). So, it would be nice to be able to overload them. Effectively we can extend the vtable out in to the fields. (it would require a bit of work to make it work identical to a class, but it could, the outside world would know no difference). If one wants: It essentially allows for methods to be modifiable at run time(something that classes can't do without unsafely hacking the vtable) and that is exactly why I have used it, but overloading causes a problem because only the name collides yet it works with the methods case but not the field delegates(a field delegate is essentially a method, is the point(for functional usage)).
Re: delegate with optional parameters
On 04/02/2017 03:24 PM, Inquie wrote: >> Show a usage, someone certainly propose a pattern that does the job. > > int delegate() f; > void delegate(int) f; That won't work because both of those are variables and variables don't have overloading. > These are effectively overload methods, but my guess is that D won't > support it like overloads. > e.g., > > int f(); > void f(int); Yep, both 'f' are functions there. I'm having difficulty understanding your actual need as well. :/ A guess: It is possible to determine delegate parameter list at compile time like std.concurrency.receive does. Ali
Re: delegate with optional parameters
On Sunday, 2 April 2017 at 21:47:55 UTC, Basile B. wrote: On Sunday, 2 April 2017 at 20:48:09 UTC, Inquie wrote: On Sunday, 2 April 2017 at 20:02:56 UTC, Basile B. wrote: On Sunday, 2 April 2017 at 19:24:14 UTC, Inquie wrote: is it possible to create a delegate that takes an optional number of parameters and/or return type? T delegate(S...)(S) special_delegate; I guess this is impossible? alias Dg(Return, Params...) = Return delegate(Params); Dg!(int,float, string) myDg; What I mean is that I want to be able to overload delegates like one can do with normal members. Show a usage, someone certainly propose a pattern that does the job. int delegate() f; void delegate(int) f; These are effectively overload methods, but my guess is that D won't support it like overloads. e.g., int f(); void f(int);
Re: delegate with optional parameters
On Sunday, 2 April 2017 at 20:48:09 UTC, Inquie wrote: On Sunday, 2 April 2017 at 20:02:56 UTC, Basile B. wrote: On Sunday, 2 April 2017 at 19:24:14 UTC, Inquie wrote: is it possible to create a delegate that takes an optional number of parameters and/or return type? T delegate(S...)(S) special_delegate; I guess this is impossible? alias Dg(Return, Params...) = Return delegate(Params); Dg!(int,float, string) myDg; What I mean is that I want to be able to overload delegates like one can do with normal members. Show a usage, someone certainly propose a pattern that does the job.
Re: delegate with optional parameters
On Sunday, 2 April 2017 at 20:02:56 UTC, Basile B. wrote: On Sunday, 2 April 2017 at 19:24:14 UTC, Inquie wrote: is it possible to create a delegate that takes an optional number of parameters and/or return type? T delegate(S...)(S) special_delegate; I guess this is impossible? alias Dg(Return, Params...) = Return delegate(Params); Dg!(int,float, string) myDg; What I mean is that I want to be able to overload delegates like one can do with normal members.
Re: delegate with optional parameters
On Sunday, 2 April 2017 at 19:24:14 UTC, Inquie wrote: is it possible to create a delegate that takes an optional number of parameters and/or return type? T delegate(S...)(S) special_delegate; I guess this is impossible? alias Dg(Return, Params...) = Return delegate(Params); Dg!(int,float, string) myDg;
delegate with optional parameters
is it possible to create a delegate that takes an optional number of parameters and/or return type? T delegate(S...)(S) special_delegate; I guess this is impossible?