On the richness of C++

Edward Diener eddielee_no_spam_here at tropicsoft.com
Wed Apr 16 13:22:06 PDT 2008


Bill Baxter wrote:
> 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.

I totally agree with what you say here. When a D non-member function can 
be assigned to a delegate, we have delegate as our D equivalent of 
boost::function. This is essentially the way C++/CLI and C# uses its 
delegate.




More information about the Digitalmars-d mailing list