Dictionary of Templated Functions

frame frame86 at live.com
Sat Sep 10 22:13:01 UTC 2022

On Saturday, 10 September 2022 at 00:24:11 UTC, jwatson-CO-edu 
> Hello,
> I'm trying to create a dictionary of templated function 
> pointers.  The functions should return `bool` and take a 
> differently-typed dynamics arrays `T[]` as an argument.

This won't work as you might expect. Your container would need to 
support multiple types and may need overloads of operators to 
become that magic.

But lets begin with a simple type. Consider your example fixed:

alias FuncDict(T) = bool function(T[])[string]; // alias needs T 
as parameter too...

FuncDict!(string) lookup; // ...so we can instantiate a FuncDict 
with T = string

void main()
     lookup["foo"] = function bool(string[] args) { return true; };

As you can see `T` is bound to `string` here and cannot be 
something else.

More information about the Digitalmars-d-learn mailing list