@@ -221,7 +221,7 @@ assert(i == 4);
221221
222222 $(BEST_PRACTICE Use a $(DDSUBLINK spec/function, ref-params,
223223 `ref` function parameter) or a $(DDSUBLINK spec/declaration, ref-variables,
224- `ref` local variable) when the address doesn't escape.
224+ `ref` local variable) when the address doesn't escape.)
225225
226226
227227$(H2 $(LEGACY_LNAME2 User Defined Types, user-defined-types, User-Defined Types))
@@ -698,27 +698,43 @@ $(P See $(DDSUBLINK spec/function, function-pointers, Function Pointers).)
698698
699699$(H3 $(LNAME2 delegates, Delegates))
700700
701- $(P Delegates are an aggregate of two pieces of data, either:)
701+ $(P Delegates are an aggregate of two pieces of data, a *context pointer* and
702+ a *function pointer*. A valid delegate holds either:)
703+
702704* An object reference and a pointer to a non-static
703705 $(DDSUBLINK spec/class, member-functions, member function).
704- * A pointer to a closure and a pointer to a
705- $(DDSUBLINK spec/function, nested, nested function).
706- The object reference forms the `this` pointer when the function is called.)
706+ The object reference forms the `this` pointer when the function is called.
707+ * A pointer to a $(DDSUBLINK spec/function, closures, closure)
708+ and a pointer to a $(DDSUBLINK spec/function, nested, nested function).
709+
710+ $(P The $(D .ptr) property of a delegate will return the
711+ $(I context pointer) value as a $(D void*).
712+ )
713+
714+ $(P The $(D .funcptr) property of a delegate will return the
715+ $(I function pointer) value as a function type.
716+ )
707717
708718$(P Delegates are declared and initialized similarly to function pointers:)
709719
710720$(SPEC_RUNNABLE_EXAMPLE_COMPILE
711721-------------------
722+ int func(int);
723+ int function(int) fp; // fp is a function pointer
712724int delegate(int) dg; // dg is a delegate to a function
713725
714726class OB
715727{
716728 int member(int);
717729}
718730
719- void f(OB o )
731+ void main( )
720732{
721- dg = &o.member; // dg is a delegate to object o and member function member
733+ OB o = new OB;
734+
735+ fp = &func; // fp points to function `func`
736+ dg = &o.member; // dg is a delegate to object `o` and member function `member`
737+ dg = (int i) => o.member(i); // dg is a delegate to main's context and a delegate literal
722738}
723739-------------------
724740)
@@ -735,6 +751,11 @@ fp(3); // call func(3)
735751dg(3); // call o.member(3)
736752-------------------
737753
754+ $(P See:)
755+
756+ * $(DDSUBLINK spec/function, closures, Delegates and Closures)
757+ * $(DDSUBLINK spec/function, method-delegates, Method Delegates)
758+
738759 $(P The equivalent of member function pointers can be constructed
739760 using $(DDSUBLINK spec/expression, function_literals, anonymous lambda functions):)
740761
0 commit comments