www.digitalmars.com         C & C++   DMDScript  

c++.beta - template argument deduction

#include <stdio.h>

template <class T> void f(void(T::*)(void))
// Error: 'T' must be a class name preceding '::'
{
  printf("1\n");
}

template <class T> void f(...)
{
  printf("2\n");
}

struct A
{ };

int main()
{
  f<A>(0);
  f<int>(0);

  return 0;
}

See 14.8.2 Template argument deduction [temp.deduct], paragraph 2: "... If a
substitution in a template parameter or in the function type of the function
template results in an invalid type, type deduction fails. ..." and 14.8.3
Overload resolution [temp.over]: "... If, for a given function template,
argument deduction fails, no such function is added to the set of candidate
functions for that template. ..."

Extracted from Boost's type_traits library.


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Jun 15 2003