Topic: template member functions for non-template classes.
Author: ghogenso@u.washington.edu (Gordon Hogenson)
Date: 12 Aug 1994 17:21:46 GMT Raw View
vinay@pez.att.com (Vinay Purohit) writes:
>Why isn't the following allowed:
>class X {
> public:
> template <class T> f( <some parameter list that includes T> );
> // Is the following allowed?
> // I want all instantiations of the following template
> // to be friend functions of class X.
> friend template<class T> g( <some parameter list that includes T> );
>};
This really should be possible, especially the latter. If I
have a template function sitting around somewhere, I certainly
would want to be able to declare it a friend of some class
somehow!
And how about making a template out of an overloaded operator. This
would be especially useful for operator()():
template <class RetType, class Arg1_Type>
RetType operator()(Arg1_Type arg1)
{
// ...
}
I think there would be many uses for such functionality.
Gordon
Author: jason@cygnus.com (Jason Merrill)
Date: Sat, 13 Aug 1994 07:34:39 GMT Raw View
>>>>> Gordon Hogenson <ghogenso@u.washington.edu> writes:
> vinay@pez.att.com (Vinay Purohit) writes:
>> Why isn't the following allowed:
>> class X {
>> public:
>> template <class T> f( <some parameter list that includes T> );
This is allowed. If you specify a return type, anyway.
>> // Is the following allowed?
>> // I want all instantiations of the following template
>> // to be friend functions of class X.
>> friend template<class T> g( <some parameter list that includes T> );
This isn't, unless it was added at Waterloo (I still haven't seen the
minutes).
>> };
> This really should be possible, especially the latter. If I have a
> template function sitting around somewhere, I certainly would want to be
> able to declare it a friend of some class somehow!
You have always been able to declare specific instances to be friends. I
imagine that the reluctance to allow template friends has been
due to vulnerablity to hijacking through specializations.
> And how about making a template out of an overloaded operator. This
> would be especially useful for operator()():
> template <class RetType, class Arg1_Type>
> RetType operator()(Arg1_Type arg1)
> {
> // ...
> }
How would you invoke this particular template? If you have to explicitly
specify the return type, you can't rely on the implicit operator call
mechanism, so why not call it something elese?
Jason