What is the rationale behind the syntax chosen to declare template friends?

前端 未结 2 518
被撕碎了的回忆
被撕碎了的回忆 2021-02-14 23:37

Declaring template function friends involves some incredibly unintuitive syntax, even for C++! What is the rationale behind the choice of syntax for the extra <>

2条回答
  •  梦谈多话
    2021-02-15 00:05

    Wait. You are not declare a friend template. You declare a specialization of a template as friend! As such, why would you want to put a template clause there?

    The syntax to name specializations of function templates is by teplateName, and that is what you shall use according to the Standard in the friend declarations.

    If you want to befriend the whole template and all specializations generated and explicitly specialized, you can still do that, and then you can use a template clause

    template
    friend void bar(Foo);
    

提交回复
热议问题