On the richness of C++

Bill Baxter dnewsgroup at billbaxter.com
Tue Apr 15 18:39:45 PDT 2008


Edward Diener wrote:

>>> Function collapses *all* the various function types into one easy to
>>> use form.  D has both function and delegate, so some 3rd party
>>> utility is still needed.
>>
>> I'm not sure that's such a big deal.
> 
> It is only a big deal in the sense that proving a single callback 
> signature or a single event signature, rather than two of each because 
> of the presumed need to support both delegates and function pointers, is 
> a big deal. In other words it is much cleaner to present a single 
> callable interface in a language, ala boost::function, Python callables, 
> C# delegates etc etc. The callback or event does not care if the 
> callable is a delegate or function pointer as long as the signature 
> matches, so it is a PITA if a language can not fold both into a single 
> callable concept. That is the issue and I think if you think about it 
> you will realize why it is better from both a clarity and ease of use 
> perspective to have a single callable representing both. There is no 
> sense in a language as rich as D to have to move backward from what 
> other other good languages are able to represent.


I think all that's needed is a way to automatically promote a function 
to a delegate, right?

Then D's delegates basically are the universal callable you're asking for.

D needs the function type to be able to interop with C, but there's no 
reason as far as I know to make it illegal to assign a function to a 
delegate.  It's just that the language doesn't currently allow it.  The 
context pointer inside the delegate would just become null, because the 
function doesn't need it.

--bb



More information about the Digitalmars-d mailing list