Angel Tsankov wrote:

"Victor Bazarov" <v.********@comAcast.net> wrote in message news:ke******************************@comcast.com. .. Angel Tsankov wrote:> Let's say we have a class template:

>

> template< typename t >

> class c;

>

> and a function template:

>

> template< typename t1, typename t2 >

> bool operator ==

> (

> c< t1 > const&

> , c< t2 > const&

> );

>

> Now we want operator ==< t1, t2 > to be a friend of class c< t3 >

> ONLY for t1 = t3 or t2 = t3. How do we specify this?

It is only available if you specialise your 'c' for 't3'. You cannot

declare friendship outside any class definition.

What if we have access to the definition of c<t >?

Fine. If you declare operator==() a friend of the original template,

then it will be a friend of _all_ instantiations of that template.

How can we do that? Can we declare a template as a friend of another

template?

Right, this is what I do not want. I want operator ==<t1,t2> to be a friend of c<t> ONLY for t1 = t3 or t2 = t3.

template <class t>

class SomeTemplateClass {

friend bool operator ==<t, t3>(t&, t3&);

friend bool operator ==<t3, t>(t3&, t&);

// rest of the class declarations

};

Assuming t3 is known, won't the above code ensure that the operator ==

is a friend if and only if one of the arguments is of type t3? No?