Annoyance with function template unwrapping

solidstate1991 laszloszeremi at outlook.com
Sat Jan 16 22:09:48 UTC 2021


In one of my projects, I want to use function pointers that I get 
from a function template that has overloads. Easily reproducable 
example:

void func(ubyte b)(int i)
{
     writeln(__PRETTY_FUNCTION__);
}

void func(ubyte b)(float f)
{
     writeln(__PRETTY_FUNCTION__);
}
void main()
{
     void function(float) fp = &func!(5); // Error: template 
onlineapp.func matches more than one template declaration
}

However defining the function templates this way works:

template func(ubyte b) {
     void func(int i) {
         writeln(__PRETTY_FUNCTION__);
     }
     void func(float i) {
         writeln(__PRETTY_FUNCTION__);
     }
}

I might change my project CPUblit to fit to the latter, and then 
add unittests to ensure that it works, but I don't know whether 
it's a bug, some odd behavior, or something DIP-worthy.


More information about the Digitalmars-d mailing list