Taking a function or delegate as argument.
doob at me.com
Tue Jan 10 23:22:49 PST 2012
On 2012-01-11 02:21, Stewart Gordon wrote:
> On 10/01/2012 19:56, Jacob Carlborg wrote:
>> 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.
I've been doing the same thing myself.
More information about the Digitalmars-d-learn