I am learning D, and I am especially excited for it. General programming features. The delegates are wonderful, and apparently they completely replaced the member-member-function pointers, so I got stuck when I wanted to implement something like the following:
template <typename T> void DispatchMethodForAll(std::vector<T*> & container, void (T::* func)(void)) { for(typename std::vector<T*>::iterator it = container.begin(); it != container.end(); ++it) (*it)->*func(); }
According to what I learned about function pointers and delegates in D, is that none of them can do this, because pointers to objects can only be declared for global functions, and delegates must be bound to an object, there is no "partial delegate" that I can find. As you can see here, I cannot use a delegate, because there is no single object that can be bound to a method that needs to be called.
I know that I could do this with mixins and essentially make it a macro. However, it really doesnโt look like D-like, and I decided that there should be a โright wayโ
Ramon Zarazua B.
source share