Choosing between generic and specific fn

2020-07-19 Thread spip
Though they look like functions, templates are strange beasts... It seems that your template looks at the symbols it knows when it is instantiated, and it will select the most specific in the known symbols at that time. If both procs have been parsed by the compiler when invoked, it will choose

Choosing between generic and specific fn

2020-07-19 Thread HashBackupJim
Thanks for the detailed answer! I have a lot to learn... :)

Choosing between generic and specific fn

2020-07-19 Thread solo989
Yes. If you want the template to match the other function mix it in. template temp(a) = mixin x x(a) Run Or define another function or template before temp proc x[T:not int](i: T) = echo "generic x 2" Run It doesn't have

Choosing between generic and specific fn

2020-07-19 Thread HashBackupJim
When a generic fn is defined before a template, and a specific fn is defined after the template, the template always uses the generic fn: proc x[T](i: T) = echo "generic x" template temp(a) = x(a) proc x(i: int) = echo "specific x" temp(1