Skip to content

Commit 0f5ca86

Browse files
committed
Move .ptr and .funcptr example code to type.dd
1 parent 9eb1e9b commit 0f5ca86

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

spec/function.dd

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3379,9 +3379,6 @@ void main()
33793379
{
33803380
Foo f = {7};
33813381
int delegate() dg = &f.get; // bind to an instance of Foo and a method
3382-
assert(dg.ptr == &f);
3383-
assert(dg.funcptr == &Foo.get);
3384-
33853382
int i = add1(dg);
33863383
assert(i == 8);
33873384

spec/type.dd

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -717,24 +717,28 @@ $(I function pointer) value as a function type.
717717

718718
$(P Delegates are declared and initialized similarly to function pointers:)
719719

720-
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
720+
$(SPEC_RUNNABLE_EXAMPLE_RUN
721721
-------------------
722-
int func(int);
723-
int function(int) fp; // fp is a function pointer
724-
int delegate(int) dg; // dg is a delegate to a function
722+
void func(int) {}
723+
void function(int) fp; // fp is a function pointer
724+
void delegate(int) dg; // dg is a delegate to a function
725725

726726
class OB
727727
{
728-
int member(int);
728+
void member(int) {}
729729
}
730730

731731
void main()
732732
{
733733
OB o = new OB;
734734

735735
fp = &func; // fp points to function `func`
736+
736737
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
738+
assert(dg.ptr == cast(void*) o);
739+
assert(dg.funcptr == &OB.member);
740+
741+
dg = (int i) { o.member(i); }; // dg holds a delegate literal with main's execution context
738742
}
739743
-------------------
740744
)

0 commit comments

Comments
 (0)