Is it possible to mark an alias template as a friend?

Imagine we have this code:

template <class, class> class Element {}; template <class T> class Util { public: template <class U> using BeFriend = Element<T, U>; }; 

Can I mark BeFriend as a friend? (Of Util or any other class).

Edit

The "obvious" syntax was analyzed, but both refused with Clang 3.6.

 template <class> friend class BeFriend; template <class> friend BeFriend; 

I did not know about the second syntax, but found it in this answer . It seems to work (and require) for non- template aliases, but does not help in this case when the template is smoothed.

(Please note: since some of them can deduce from a minimal example, Iโ€™m looking for a way around a limitation that C ++ does not allow to be friends with a partial specialized specialization)

+7
c ++ c ++ 11 friend templates
source share
2 answers

I think you cannot do this because partial specializations cannot be declared as friends.

From stardard, 14.5.4 / 8 Friends [temp.friend]

Friend declarations should not declare partial specialization. [Example:

 template<class T> class A { }; class X { template<class T> friend class A<T*>; // error }; 

-end example]

You should specify a more general version, for example:

 template <class, class> friend class Element; 

or the full version specified, for example:

 using BeFriend = Element<T, int>; friend BeFriend; 
+6
source share

The problem is not the alias, the problem is that "Partial specialization cannot be declared as a friend."

 template <class, class> friend class Element; // OK template <class, class> friend class Element<T, T>; // Error 
+1
source share

All Articles