Topic: Template expansion does not match argument


Author: maxtal@Physics.usyd.edu.au (John Max Skaller)
Date: Fri, 3 Mar 1995 06:12:16 GMT
Raw View
In article <MECKLEN.95Feb27164022@oops.cs.utah.edu>,
Robert Mecklenburg <mecklen@oops.cs.utah.edu> wrote:
>Borland C++ 4.5 will not match a "T" to a "const T &" in a template
>expansion.  I have other compilers which will.  Who is right?

 No one. The Working Paper is vague.

>template< class T >
>void
>f( const T & t );
>
>struct A {};
>void
>foo()
>{
>    A a;
>    /* Could not find a match for 'f(A)' in function foo() */
>   f( a );
>}

This should work. But it is not a bug in Borland but in the WP.

--
        JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
 Maxtal Pty Ltd,
        81A Glebe Point Rd, GLEBE   Mem: SA IT/9/22,SC22/WG21
        NSW 2037, AUSTRALIA     Phone: 61-2-566-2189




Author: jason@cygnus.com (Jason Merrill)
Date: 28 Feb 1995 06:41:21 GMT
Raw View
>>>>> Robert Mecklenburg <mecklen@oops.cs.utah.edu> writes:

> Borland C++ 4.5 will not match a "T" to a "const T &" in a template
> expansion.  I have other compilers which will.  Who is right?

The compilers which will.

  14.9.2  Template argument deduction                      [temp.deduct]

1 Template  arguments that can be deduced from the function arguments of
  a call need not be explicitly specified.  For example,

          void f(vector<complex>& cv, vector<int>& ci)
          {
              sort(cv);   // call sort(vector<complex>)
              sort(ci);   // call sort(vector<int>)
          }
  and
          void g(double d)
          {
                  int i = convert<int>(d);   // call convert<int,double>(double)
                  int c = convert<char>(d);  // call convert<char,double>(double)
          }

2 A template type argument T or a template non-type argument  i  can  be
  deduced from a function argument composed from these elements:
          T
          cv-list T
          T*
          T&
          T[integer-constant]
          class-template-name<T>
          type(*)(T)
          type T::*
          T(*)()
          T(*)(T)
          type[i]
          class-template-name<i>
  where (T) includes argument lists with more than one argument where at
  least one argument contains a T, and where () includes argument  lists
  with arguments that do not contain a T.

Jason




Author: ronnie@wirrah.tusc.com.au (Ronnie Braverman)
Date: 01 Mar 1995 02:58:10 GMT
Raw View
:In article <MECKLEN.95Feb27164022@oops.cs.utah.edu> mecklen@oops.cs.utah.edu (Robert Mecklenburg) writes:
:
:   Borland C++ 4.5 will not match a "T" to a "const T &" in a template
:   expansion.  I have other compilers which will.  Who is right?
:
:   template< class T >
:   void
:   f( const T & t );
:
:   struct A {};
:   void
:   foo()
:   {
:       A a;
:       /* Could not find a match for 'f(A)' in function foo() */
:      f( a );
:   }
:
:   Thanks,
:   Robert Mecklenburg
:   University of Utah
:   http://www.cs.utah.edu/~mecklen
:

Borland 4.5 is, I think. The rule (the last time I checked) was that
template expansion parameters must match EXACTLY - obviously a
const T& is not the same as T&. However, many compilers will allow
it.

Ronnie Braverman




Author: jason@cygnus.com (Jason Merrill)
Date: 01 Mar 1995 07:03:46 GMT
Raw View
>>>>> Ronnie Braverman <ronnie@wirrah.tusc.com.au> writes:

> Borland 4.5 is, I think. The rule (the last time I checked) was that
> template expansion parameters must match EXACTLY

This is no longer the case.  Please see my earlier posting.

Jason




Author: mecklen@oops.cs.utah.edu (Robert Mecklenburg)
Date: 27 Feb 1995 23:40:22 GMT
Raw View
Borland C++ 4.5 will not match a "T" to a "const T &" in a template
expansion.  I have other compilers which will.  Who is right?

template< class T >
void
f( const T & t );

struct A {};
void
foo()
{
    A a;
    /* Could not find a match for 'f(A)' in function foo() */
   f( a );
}

Thanks,
Robert Mecklenburg
University of Utah
http://www.cs.utah.edu/~mecklen