Taking a function or delegate as argument.

Stewart Gordon smjg_1998 at yahoo.com
Tue Jan 10 17:21:25 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.

Moreover, if you want to save the callback for later use, you need to distinguish the cases.

But it really just boils down to:
- if it's a global or static function, wrap it in a delegate
- if it's a type with static opCall, wrap class.opCall in a delegate
- if it's an object with an opCall, just use &obj.opCall

I've just had a look at std.functional.toDelegate and it seems it does this straight off. 
  But the way it wraps a static function in a delegate is a lot more complicated than what 
my library does - is this just in order to support non-D linkage?

And I see it has the same limitation of not supporting variadics.

Stewart.


More information about the Digitalmars-d-learn mailing list