Topic: [Q] Fully specified template functions
Author: Martin von Loewis <loewis@informatik.hu-berlin.de>
Date: 1998/09/09 Raw View
"Gabor Greif" <gabor.greif@no.drsolomon.com> writes:
> I am wondering if functions obtained from function templates by
> fully specifying the argument types still count as a group of
> overloaded functions?
I would expect that a template-id has a specific type according to the
actual template parameters, and not a the 'overloaded' type.
So I'd say your example is well-formed.
Regards,
Martin
[ 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: "Gabor Greif" <gabor.greif@no.drsolomon.com>
Date: 1998/09/09 Raw View
I am wondering if functions obtained from function templates by fully
specifying the
argument types still count as a group of overloaded functions?
The example I stumbled over is this:
##########################
template <typename T, typename P>
void foo(const T& c, P p);
template <typename T>
void bar1(const T& vi);
static bool bar2(int);
template <typename T>
void bar(const T& vi)
{
/* legal? */ foo(vi, bar1< T >);
/* legal? */ foo(vi, bar1< int >);
foo(vi, bar2);
}
int main()
{
bar(int(1));
}
##########################
I was said that the two explicitly parametrized instances of the bar1
function template
are not allowed in the above context because of these lines of the draft:
>14.8.2.4 - Deducing template arguments from a type [temp.deduct.type]
>
> [...]
>
>-16- A template-argument can be deduced from a pointer to function or
>pointer to member function argument if the set of overloaded functions
>does not contain function templates and at most one of a set of overloaded
>functions provides a unique match. [Example:
>
>
>template<class T> void f(void(*)(T,int));
>template<class T> void foo(T,int);
>void g(int,int);
>void g(char,int);
>
>
>
>void h(int,int,int);
>void h(char,int);
>int m()
>{
> f(&g); // error: ambiguous
> f(&h); // OK: void h(char,int) is a unique
match
> f(&foo); // error: type deduction fails because
foo is a template
>}
My gut feeling is that a fully parametrized instance of a function template
is point-like
and thus not a template any more but exactly one function. Notice that I am
not using
&bar1 in my code but &bar1<int>.
So is my above code legal, or do I have to work around with (ugly)
typecasts like this?:
void bar(const T& vi)
{
foo(vi, (void (*)(T))&bar1);
foo(vi, (void (*)(int))&bar1);
foo(vi, bar2);
}
TIA,
Gabor
[ 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 ]