Daniel Keep /
Is It AFunction Or ADelegate
Difference (last edit) (Author, normal page display)
Added: 65a66,68
showType(function(){}); showType(delegate(){}); showType({}); |
Is it a Function or a Delegate?
One problem I encountered when working with D and functional programming was that there were times I would pass a pointer to (what I assumed) was a function, and instead it would pass a delegate.
Eventually, I got sick of guessing what was going on, so I went off and tested every kind of procedure I could think of in order to work out just what is a function, and what is a delegate.
Quick Summary
Below is a quick summary of the results.
If we define func as:
![]() |
|
Then what is &func (based on where it was defined)?
- Function Pointer:
- Module level
- Static class or struct method
- Delegate:
- Inner function (function in a function)
- Non-static class or struct method
The Code!
Below is the code I used to test this, so you can try it for yourself.
![]() |
|
Postscript
If you happen to find any errors in this, feel free to let me know so I can fix it—don't want to look like an idiot, now do I? :P
FolderExamples