On the richness of C++

Edward Diener eddielee_no_spam_here at tropicsoft.com
Wed Apr 16 13:57:11 PDT 2008


Walter Bright wrote:
> Sean Kelly wrote:
>> Sure, but templates don't suit every situation.  It's not uncommon for
>> APIs to have to overload on accepting a function and a delegate for
>> flexibility.
> 
> The only way to merge function pointers with delegates is to have the 
> compiler generate trampolines. This isn't very runtime efficient - the 
> template approach will be faster.

The template approach means that one has to write a template for each 
function signature, uniting D function pointers and D delegates, which 
one wants to use as a callback or event in one's own code, unless of 
course one does the equivalent of boost::function in D for nn parameters 
as a generalized template solution.

Finally if a delegate in D is the equivalent of an object pointer and a 
member function pointer, why would allowing a null pointer for the 
object pointer part not allow a delegate to encompass both a non-member 
function pointer and an object's member function pointer ? If it would, 
then is it really that much slower checking if the object pointer is 
null to decide internally in code how the delegate is called ?



More information about the Digitalmars-d mailing list