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.
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
- Inner function (function in a function)
- Non-static class or struct method
Below is the code I used to test this, so you can try it for yourself.
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