digitalmars.D.learn - delegate with optional parameters
- Inquie (4/4) Apr 02 2017 is it possible to create a delegate that takes an optional number
- Basile B. (3/7) Apr 02 2017 alias Dg(Return, Params...) = Return delegate(Params);
- Inquie (3/12) Apr 02 2017 What I mean is that I want to be able to overload delegates like
- Basile B. (3/17) Apr 02 2017 Show a usage, someone certainly propose a pattern that does the
- Inquie (8/26) Apr 02 2017 int delegate() f;
- =?UTF-8?Q?Ali_=c3=87ehreli?= (8/16) Apr 02 2017 That won't work because both of those are variables and variables don't
- Inquie (18/38) Apr 02 2017 Yes, but they are really not any different. They only look
- Rene Zwanenburg (3/7) Apr 03 2017 It should be possible to create a wrapper struct around your
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?
Apr 02 2017
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;
Apr 02 2017
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:What I mean is that I want to be able to overload delegates like one can do with normal members.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;
Apr 02 2017
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:Show a usage, someone certainly propose a pattern that does the job.On Sunday, 2 April 2017 at 19:24:14 UTC, Inquie wrote:What I mean is that I want to be able to overload delegates like one can do with normal members.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;
Apr 02 2017
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: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);On Sunday, 2 April 2017 at 20:02:56 UTC, Basile B. wrote:Show a usage, someone certainly propose a pattern that does the job.On Sunday, 2 April 2017 at 19:24:14 UTC, Inquie wrote:What I mean is that I want to be able to overload delegates like one can do with normal members.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;
Apr 02 2017
On 04/02/2017 03:24 PM, Inquie wrote:That won't work because both of those are variables and variables don't have overloading.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);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
Apr 02 2017
On Monday, 3 April 2017 at 03:08:22 UTC, Ali Çehreli wrote:On 04/02/2017 03:24 PM, 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. 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)).the job.Show a usage, someone certainly propose a pattern that doesint 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 thatD won'tsupport 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
Apr 02 2017
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.
Apr 03 2017