结交模板模板参数

Que*_*tin 29 c++ templates friend template-templates

我有一个带有模板模板参数的类模板,我想将此参数(即其所有特化)声明为friend.但我找不到正确的语法.

template <template <class> class T>
struct Foo {

    template <class U>
    friend T;           // "C++ requires a type specifier for all declarations"

    template <class U>
    friend struct T;    // "declaration of 'T' shadows template parameter"

    template <class U>
    friend struct T<U>; // "cannot specialize a template template parameter"

    pretty<please>
    lets(be) friends T; // Compiler shook its standard output in pity
};
Run Code Online (Sandbox Code Playgroud)

如何将模板模板参数声明为friend

Coliru片段

ven*_*syv -2

模板往往会让程序员把事情变得过于复杂。我不太确定你想做什么,我怀疑可能有更好的方法来做到这一点,但这应该可行。

template <template <class> class T, class U>
class Foo {
    friend class T<U>;
};
Run Code Online (Sandbox Code Playgroud)