I'd like to write a template, that takes a different default value depending on the type of a variable. I tried this, but it doesn't work:

void main()
{
   double a = 1e-8;
   double b = 1e-10;
   float c = 1e-4;
   float d = 1e-6;

   assert(!test(a));
   assert(test(b));
   assert(!test(c));
   assert(test(d));
}

auto test(T, U)(T value, U limit=1e-9)
{
   return value<limit;
}

auto test(T:float)(T value)
{
   return test(value, 1e-5);
}

Although being called with a double in the first two tests, the second overload is always used and therefore the first test fails. And without this overload, the last test obviously doesn't pass.

Is there a way, to provide default values for template parameters depending on the type of an other parameter?

Reply via email to