www.digitalmars.com         C & C++   DMDScript  

c++.beta - template function argument deduction

Working through function template compatabilty for boost compressed_pair and
call_traits templates. The maintainer of these libs and the author of the regex
lib, John Maddox <John_Maddock compuserve.com> replied to my request on this
issue that he was uncertain of the exact standard reference for template
parameter deduction for structs and added:

<Quote>

One thing I can say: that particular partial specialisation is accepted by all
the compilers I have access to: VC7.1, Borland C++, and gcc.  Likewise things
like:

template <class T>
struct is_member_pointer
{
/*details*/
};

template <class T, class U>
struct is_member_pointer<T U::*>
{
/*details*/
};

</Quote>

The items below don't work from the standard indicated in 14.8.2.4

template <class Z> void h(Z, Z*);
int main()
{
h<const int>(1,0);
// Error: no match for function 'h(int ,int )'
}

and

template<int i> void f1(int a[10][i]);
template<int i> void f3(int (&a)[i][20]);

void g()
{
int v[10][20];
f1(v);
// Error: no match for function 'f1(int (*)[20])'
// NOTE: i should be deduced as 20
f3(v);
// Error: no match for function 'f3(int (*)[20])'
// NOTE: i should be deduced as 10
}

void main() { }

Richard
Jan 15 2003