function(pointer) as template argument, explicit template instantiation

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Dec 31 12:36:46 UTC 2021


On Fri, Dec 31, 2021 at 11:52:21AM +0000, kdevel via Digitalmars-d-learn wrote:
[...]
> That is what I want to do. The function template lyr shall be
> (explicitly) instantiated in order to put the resulting function
> pointer into an AA. The call signature of lyr!(foo) and foo must be
> the same.
> 
> In C++ this looks like this:
[...]

--------
struct R {}

void lyr(alias Fn)(ref R r)
{
	Fn(r);
}

void foo(ref R r) { }

static immutable void function(ref R)[string] reg;
shared static this() {
	// workaround for lack of CT AA initialization
	reg = [
		"foo": &foo,
		"lfoo": &lyr!foo,
	];
}
--------


T

-- 
Why waste time reinventing the wheel, when you could be reinventing the engine? -- Damian Conway


More information about the Digitalmars-d-learn mailing list