Taking a function or delegate as argument.

Stewart Gordon smjg_1998 at yahoo.com
Tue Jan 10 17:05:37 PST 2012


On 10/01/2012 19:56, Jacob Carlborg wrote:
<snip>
> A template parameter with a template constraint will accept any callable type. Function
> pointer, delegate, struct/class overloading the call operator and so on.

Indeed, this is done in the C++ STL quite a lot.

The drawback is that templated methods lose their virtuality, because it cannot be known 
in advance on what types the template will be instantiated in order to populate the vtable.

FWIW my utility library includes a delegate wrapper:
http://pr.stewartsplace.org.uk/d/sutil/

(dgwrap works in both D1 and D2, though other bits of the library need updating to current D2)

Stewart.


More information about the Digitalmars-d-learn mailing list