Re: How would you implement this in D? (signals & slots)

2016-02-03 Thread Vadim Lopatin via Digitalmars-d-learn
On Monday, 1 February 2016 at 21:40:45 UTC, Enjoys Math wrote: module signals_and_slots; How do you implement this template called like: void onColorChange(in Color) { // do something with color } auto slots = Slots!(void delegate(in Color), Color); slots.connect(); auto color = Color(0.0,

Re: How would you implement this in D? (signals & slots)

2016-02-02 Thread Atila Neves via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 17:35:25 UTC, Chris Wright wrote: On Tue, 02 Feb 2016 15:59:06 +, Atila Neves wrote: [...] I've seen this sort of thing before. A blogger I used to follow, Jeremy Miller, implemented an event broker using this pattern. I don't like it. It requires a new

Re: How would you implement this in D? (signals & slots)

2016-02-02 Thread Gerald via Digitalmars-d-learn
On Monday, 1 February 2016 at 21:44:28 UTC, Enjoys Math wrote: On Monday, 1 February 2016 at 21:40:45 UTC, Enjoys Math wrote: module signals_and_slots; import std.algorithm: remove; [...] D's signals & slots: https://dlang.org/phobos/std_signals.html I looked at that and perhaps I'm not

Re: How would you implement this in D? (signals & slots)

2016-02-02 Thread Atila Neves via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 14:49:21 UTC, Gerald wrote: On Monday, 1 February 2016 at 21:44:28 UTC, Enjoys Math wrote: On Monday, 1 February 2016 at 21:40:45 UTC, Enjoys Math wrote: module signals_and_slots; import std.algorithm: remove; [...] D's signals & slots:

Re: How would you implement this in D? (signals & slots)

2016-02-02 Thread Chris Wright via Digitalmars-d-learn
On Tue, 02 Feb 2016 15:59:06 +, Atila Neves wrote: > struct String1 { string s; } > struct String2 { string s; } I've seen this sort of thing before. A blogger I used to follow, Jeremy Miller, implemented an event broker using this pattern. I don't like it. It requires a new type for each

Re: How would you implement this in D? (signals & slots)

2016-02-02 Thread Gerald via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 15:59:06 UTC, Atila Neves wrote: Slots are named: the methods are slots. Signals can be named if you use only one struct as the parameter, as above. The signals would be String1 and String2, the slots watch1 and watch2. What I meant is that the connect call

How would you implement this in D? (signals & slots)

2016-02-01 Thread Enjoys Math via Digitalmars-d-learn
module signals_and_slots; import std.algorithm: remove; struct Slots(DelegateType, ArgTypes...) { this() { } // How would you implement this? void call(ArgTypes args) { foreach (dg; delegates) dg(args); }

Re: How would you implement this in D? (signals & slots)

2016-02-01 Thread Enjoys Math via Digitalmars-d-learn
On Monday, 1 February 2016 at 21:40:45 UTC, Enjoys Math wrote: module signals_and_slots; import std.algorithm: remove; [...] D's signals & slots: https://dlang.org/phobos/std_signals.html