Permalink
Browse files

Merge pull request #11 from shoo/fix_event_for_delegate_inrefence

Event supports function pointers for delegate inference.
  • Loading branch information...
2 parents 41fe4ea + 3c73639 commit 1bf6dc486e72f178db922ee9d7706c144cb2b8b7 @Rayerd Rayerd committed Jan 21, 2012
Showing with 5 additions and 4 deletions.
  1. +5 −4 win32/dfl/event.d
View
@@ -5,6 +5,7 @@
module dfl.event;
import dfl.internal.dlib;
+import std.functional;
// Create an event handler; old style.
@@ -66,14 +67,14 @@ template Event(T1, T2) // docmain
{
mixin _validateHandler!(TDG);
- addHandlerExact(cast(Handler)handler);
+ addHandlerExact(cast(Handler)toDelegate(handler));
}
/// Shortcut for addHandler().
void opCatAssign(TDG)(TDG handler)
{
- addHandler!(TDG)(handler);
+ addHandler(toDelegate(handler));
}
@@ -123,7 +124,7 @@ template Event(T1, T2) // docmain
{
mixin _validateHandler!(TDG);
- removeHandlerExact(cast(Handler)handler);
+ removeHandlerExact(cast(Handler)toDelegate(handler));
}
@@ -216,7 +217,7 @@ template Event(T1, T2) // docmain
// Thanks to Tomasz "h3r3tic" Stachowiak for his assistance.
template _validateHandler(TDG)
{
- static assert(is(TDG == delegate), "DFL: Event handler must be a delegate");
+ static assert(is(typeof(toDelegate(TDG.init))), "DFL: Event handler must be a callable");
alias ParameterTypeTuple!(TDG) TDGParams;
static assert(TDGParams.length == 2, "DFL: Event handler needs exactly 2 parameters");

0 comments on commit 1bf6dc4

Please sign in to comment.