Don Clugston
Posts: 1
Nickname: clugston
Registered: Dec, 2004
|
|
Re: Your C++ Wish List (Editorial)
|
Posted: Dec 20, 2004 3:15 PM
|
|
Add some support for delegation.
Ideally, something like Borland's __closure, but with support for static functions, with better integration into the type system, and with the full set of operations.
------------------------ Bare minimum proposal ------------------------ Modify section 5.2.10/9 to state that when a member function pointer(MFP) a of class X is converted using reinterpret_cast<> to another MFP b of a class Y __of incomplete type__ but the same signature, and a pointer p to X is converted to a pointer q to Y using static_cast<>, then invoking (q->*b)() is equivalent to (p->*a)().
This works on every C++ compiler ever made. It allows creation of optimally efficient delegates. Here's an example implementation:
http://www.codeproject.com/cpp/FastDelegate.asp
Unfortunately, this code is not legal (even though it works on all compilers, albeit with some nasty tricks for the non-standard MFPs used by Microsoft/Intel). But with that trivial change to the standard, it could be made legal retrospectively.
The proposal has no side effects on other areas of the language. All extant compilers are automatically compliant. And it adds a significant new concept to the language. (In one of Herb's recent blogs, he mentioned that he drools over C# delegates. These are better, because they work with templates).
I doubt you'll find anything with a better "bang for your buck".
Of course it would be nice to have full language integration, especially with better error messages, and a defined ABI for delegate structures -- but please consider this kind of zero-cost option if a full implementation doesn't make the list.
|
|