Topic: Can this be deduced?
Author: Ron Natalie <ron@sensor.com>
Date: 1999/03/05 Raw View
scott douglass wrote:
>
> Given:
> template <class T> void g(T, T) { /* ... */ }
> void f(int& ri, int i) { g(ri, i); }
>
> Can 'g' be implicitly instantiated? I believe the answer is no because for one
> argument we deduce T == int& and for the other T == int.
>
> On the other hand both g(int&,int&) and g(int,int) would be callable here.
Under what conditions would T ever match int& in your example?
The expression ri has type int.
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: James Kuyper <kuyper@wizard.net>
Date: 1999/03/06 Raw View
Ron Natalie wrote:
>
> scott douglass wrote:
> >
> > Given:
> > template <class T> void g(T, T) { /* ... */ }
> > void f(int& ri, int i) { g(ri, i); }
> >
> > Can 'g' be implicitly instantiated? I believe the answer is no because for one
> > argument we deduce T == int& and for the other T == int.
> >
> > On the other hand both g(int&,int&) and g(int,int) would be callable here.
>
> Under what conditions would T ever match int& in your example?
> The expression ri has type int.
No, it has the type 'int&', which has a trivial conversion to 'int'.
That's why it's safe to use 'ri' in most circumstances where an 'int' is
required, but it's still a different type. Because it's a trivial
conversion, g<int>(ri,i) and g<int&>(ri,i) are both perfectly legal
expressions. The rules for template instantiation don't favor one over
the other, so the implicit instantiation would be ambiguous, and would
therefore fail.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: scott douglass <sdouglass%_%junk@_.arm.com>
Date: 1999/03/05 Raw View
Given:
template <class T> void g(T, T) { /* ... */ }
void f(int& ri, int i) { g(ri, i); }
Can 'g' be implicitly instantiated? I believe the answer is no because for one
argument we deduce T == int& and for the other T == int.
On the other hand both g(int&,int&) and g(int,int) would be callable here.
Thanks,
--scott
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]