www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Do D's std.signals check for already-connected slot and simply ignore

reply Enjoys Math <enjoysmath gmail.com> writes:
If they don't, I have to wrap it like so:

import std.signals;

class Signal(T) {
protected:
    mixin Signal!(T);
};

class Changed(T) : Signal!T {
protected:
    void delegate(T)[] slots;

public:
    override void connect(void delegate(T) slot) {
       foreach (s; slots) {
          if (s == slot)
             return;
       }
       slots ~= slot;
       super.connect(slot);
    }

    override void disconnect(void delegate(T) slot) {
        import std.algorithm;

        foreach (s; slots) {
           if (s == slot) {
              slots.remove(s);
              super.disconnect(slot);
              break;
           }
        }
    }

    override void disconnectAll() {
         super.disconnectAll();
    }
}

??
Oct 16 2018
parent Enjoys Math <enjoysmath gmail.com> writes:
Answer: they don't connect uniquely, you have to manage that 
yourself.
Oct 17 2018