Changeset 1556
- Timestamp:
- 05/26/10 05:59:40 (15 years ago)
- Files:
-
- trunk/phobos/std/functional.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/phobos/std/functional.d
r1528 r1556 538 538 * void runDelegate(void delegate() myDelegate) { 539 539 * myDelegate(); 540 540 * } 541 541 * 542 542 * auto delegateToPass = toDelegate(&doStuff); 543 543 * runDelegate(delegateToPass); // Calls doStuff, prints "Hello, world." 544 544 * --- 545 545 * 546 546 * Bugs: Doesn't work properly with ref return. (See DMD bug 3756.) 547 547 */ 548 auto reftoDelegate(F)(auto ref F fp) if (isCallable!(F)) {548 auto toDelegate(F)(auto ref F fp) if (isCallable!(F)) { 549 549 550 550 static if (is(F == delegate)) 551 551 { 552 552 return fp; 553 553 } 554 554 else static if (is(typeof(&F.opCall) == delegate) 555 555 || (is(typeof(&F.opCall) V : V*) && is(V == function))) 556 556 { 557 557 return toDelegate(&fp.opCall); 558 558 }
