Templated functions: explicit and implicit instantiation at the same time?

Jarrett Billingsley kb3ctd2 at yahoo.com
Tue Oct 30 20:59:00 PDT 2007


This is driving me up the wall.  I want to have a function like this:

R func(R = int, T)(T t)
{

}

Where R can be specified but defaults to int, and T can be any type inferred 
from the parameter.  Of course this function signature doesn't work, and 
neither does anything else I've tried.  I want to be able to do:

    func(5); // R is int, T is typeof(5)
    func!(float)(5); // R is float, T is typeof(5)

The problem is that explicit instantiation disables IFTI making it 
impossible to derive T, and if I have multiple templates named 'func' and 
some of them are function templates and some aren't, it won't work with 
IFTI.

It seems that I can get one or the other, but not both.  Is there a 
solution? 




More information about the Digitalmars-d-learn mailing list