Topic: Default template parameters and template argument deduction


Author: austern (Matt Austern)
Date: 1996/02/07
Raw View
Section 14.7 of the WP [temp.param] appears to allow default template
parameters in the declaration of template functions; there's nothing
that explicitly forbids them, anyway.  It's not clear, though, just
what the default parameters mean in the case of a function template.

Paragraph 2 of 14.10.2 [temp.deduct] begins "Type deduction is done
for each parameter of a function template that contains a reference to
a template parameter that is not explicitly specified."  I couldn't
find any mention in 14.10.2 of how, or whether, default template
parameters are used in the type deduction process.

Here are a couple of examples where I can't tell just what's supposed
to happen.  There are lots more cases like this, of course.

template<class T1, class T2=double> void f(T1 t1, T2 t2) { /* ... */ }
template<class T1, class T2=int> void g(T1 t1, T2 = 1) { /* ... */ }


void a()
{
  f(3, 4);                  // f<int,int>(3,4), or f<int,double>(3,4)?
}

void b()
{
  g(1);                     // Is this illegal, or does it call
}                           //  g<int,int>(1,1)?



I can't find anything that says how default template parameters in
template functions get applied.  Have I missed something obvious?
--
Matt Austern
SGI: MTI Compilers Group
austern@isolde.mti.sgi.com
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy is
  in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]