www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9603] New: Signals must work with closure delegates

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9603

           Summary: Signals must work with closure delegates
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: major
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: verylonglogin.reg gmail.com


--- Comment #0 from Denis Shelomovskij <verylonglogin.reg gmail.com> 2013-02-27
13:37:47 MSK ---
Without this ability signals are very inconvenient to use as closures are very
common delegates and are an official way to reorder/ignore function parameters.

Also current implementation is very dangerous as passing a closure results in
undefined behavior.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 27 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9603



--- Comment #1 from Denis Shelomovskij <verylonglogin.reg gmail.com> 2013-02-27
13:41:07 MSK ---
This issue will be automatically solved e.g. once Issue 9601 and Issue 9602 are
implemented.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 27 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9603



--- Comment #2 from Denis Shelomovskij <verylonglogin.reg gmail.com> 2013-02-27
20:08:09 MSK ---
This code will work once the issue will be fixed:
---
import std.signals;

extern(C) void rt_finalize2(void* p, bool det = true, bool resetMemory = true);

class MyObject
{
    mixin Signal!int actionDone;

    // ...
}

class Observer
{
    void watch(int i) { /* ... */ }
    void watchNo() { /* ... */ }
    void watchSq(int i) { /* ... */ }

    void connectSignals(MyObject obj)
    {
        obj.actionDone.connect(&watch);
        obj.actionDone.connect(i => watch(i)); // should behave as previous one
        obj.actionDone.connect(i => watchNo());
        obj.actionDone.connect(i => watchSq(i * i));
    }
}

void main()
{
    auto obj = new MyObject;
    auto o = new Observer();
    o.connectSignals(obj);
    // ...
    rt_finalize2(cast(void*) o);
    assert(obj.actionDone.slots_idx == 0);
}
---

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 27 2013