setDelegate

Sets the context and the function of a delegate.

void
setDelegate
(
T
FT
)
(
ref T t
,
void* context
,
FT code
)
if (
is(T == delegate) &&
is(FT == typeof(T.funcptr))
)

Parameters

T

The type of the delegate.

t
Type: T

The delegate to set.

context
Type: void*

The context pointer, e.g a pointer to a struct or a class instance.

code
Type: FT

The pointer to the static function.

Examples

1 struct Foo
2 {
3     bool fun(){return true;}
4 }
5 Foo foo;
6 bool delegate() atFun;
7 atFun.setDelegate(&foo, &Foo.fun);
8 assert(atFun());

Meta