Re: templatized delegate

2017-05-23 Thread Alex via Digitalmars-d-learn
On Tuesday, 23 May 2017 at 16:38:14 UTC, Stanislav Blinov wrote: Ah, now I think I get it. You want to store a single delegate that could be called with different sets of arguments? No, you can't do that: you need an actual delegate instance, and for that, you need to know the signature, at

Re: templatized delegate

2017-05-23 Thread Alex via Digitalmars-d-learn
On Tuesday, 23 May 2017 at 18:14:34 UTC, ag0aep6g wrote: Something like this: import core.vararg; import std.meta: AliasSeq, staticMap; import std.traits: isCopyable; struct A { void delegate(...) dg; auto fun(T, U ...)(T t, auto ref U u) { template

Re: templatized delegate

2017-05-23 Thread ag0aep6g via Digitalmars-d-learn
On 05/23/2017 01:30 PM, Alex wrote: And no, I can't pass it by adress, as I don't know apriori, whether the very parameter which gets the random generator is already a part of the variadic parameters, or a well defined ref parameter. A (run-time) variadic delegate isn't flexible like that.

Re: templatized delegate

2017-05-23 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 23 May 2017 at 11:45:13 UTC, Alex wrote: On Tuesday, 23 May 2017 at 11:05:09 UTC, Stanislav Blinov wrote: void variadic(Args...)(auto ref Args args) { /* ... */ } This infers whether you pass lvalues or rvalues. If passing further down the chain of such calls is needed, one can

Re: templatized delegate

2017-05-23 Thread Alex via Digitalmars-d-learn
On Tuesday, 23 May 2017 at 11:05:09 UTC, Stanislav Blinov wrote: void variadic(Args...)(auto ref Args args) { /* ... */ } This infers whether you pass lvalues or rvalues. If passing further down the chain of such calls is needed, one can use std.functional : fowrard : yes... void

Re: templatized delegate

2017-05-23 Thread Alex via Digitalmars-d-learn
On Tuesday, 23 May 2017 at 10:42:54 UTC, Nicholas Wilson wrote: On Tuesday, 23 May 2017 at 10:30:56 UTC, Alex wrote: On Monday, 22 May 2017 at 21:44:17 UTC, ag0aep6g wrote: With that kind of variadics, you're not dealing with a template. A (run-time) variadic delegate is an actual delegate,

Re: templatized delegate

2017-05-23 Thread 9il via Digitalmars-d-learn
On Tuesday, 23 May 2017 at 10:30:56 UTC, Alex wrote: On Monday, 22 May 2017 at 21:44:17 UTC, ag0aep6g wrote: With that kind of variadics, you're not dealing with a template. A (run-time) variadic delegate is an actual delegate, i.e. a value that can be passed around. But the variadic stuff is

Re: templatized delegate

2017-05-23 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 23 May 2017 at 10:42:54 UTC, Nicholas Wilson wrote: On Tuesday, 23 May 2017 at 10:30:56 UTC, Alex wrote: On Monday, 22 May 2017 at 21:44:17 UTC, ag0aep6g wrote: With that kind of variadics, you're not dealing with a template. A (run-time) variadic delegate is an actual delegate,

Re: templatized delegate

2017-05-23 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 23 May 2017 at 10:30:56 UTC, Alex wrote: On Monday, 22 May 2017 at 21:44:17 UTC, ag0aep6g wrote: With that kind of variadics, you're not dealing with a template. A (run-time) variadic delegate is an actual delegate, i.e. a value that can be passed around. But the variadic stuff is

Re: templatized delegate

2017-05-23 Thread Alex via Digitalmars-d-learn
On Monday, 22 May 2017 at 21:44:17 UTC, ag0aep6g wrote: With that kind of variadics, you're not dealing with a template. A (run-time) variadic delegate is an actual delegate, i.e. a value that can be passed around. But the variadic stuff is a bit weird to use, and probably affects performance.

Re: templatized delegate

2017-05-22 Thread Alex via Digitalmars-d-learn
On Monday, 22 May 2017 at 21:44:17 UTC, ag0aep6g wrote: On 05/22/2017 11:04 AM, Alex wrote: [...] Not only is a template not an lvalue, it's not any kind of value at all. It doesn't have a type. You can't have a variable holding a template. You can't pass it as an argument. But a template

Re: templatized delegate

2017-05-22 Thread ag0aep6g via Digitalmars-d-learn
On 05/22/2017 11:04 AM, Alex wrote: 3. Now the hard stuff comes. I want to templatize my delegate. struct A(alias dg) { auto fun(T, U...)(T t, U u) { return dg!(T, U)(t, u); } } struct C { A!dlgptr a; /* static? */ template dlgptr(T, U...) { /*

Re: templatized delegate

2017-05-22 Thread Alex via Digitalmars-d-learn
On Monday, 22 May 2017 at 20:38:27 UTC, Dukc wrote: On Monday, 22 May 2017 at 09:04:15 UTC, Alex wrote: 2. Now, I want to store the delegate in another struct. If I want to do this, I have to define the pointer as static. This is not intended at the beginning, but it's ok, as I know, that the

Re: templatized delegate

2017-05-22 Thread Dukc via Digitalmars-d-learn
On Monday, 22 May 2017 at 09:04:15 UTC, Alex wrote: 2. Now, I want to store the delegate in another struct. If I want to do this, I have to define the pointer as static. This is not intended at the beginning, but it's ok, as I know, that the delegate would be the same across all instances of

templatized delegate

2017-05-22 Thread Alex via Digitalmars-d-learn
Hi, all I have a question, how to handle a templated delegate. However, I'm not sure, if I'm going in the right direction, so I have three examples, and my question is about the third. 1. Here, a struct with an alias is defined and on its creation the delegate get known to the struct.