Parameter pack must be at the end of the parameter list… When and why?

后端 未结 2 627
猫巷女王i
猫巷女王i 2020-11-27 18:48

I don\'t get the reason for which a parameter pack must be at the end of the parameter list if the latter is bound to a class, while the constraint is relaxed if the paramet

2条回答
  •  甜味超标
    2020-11-27 19:22

    The first one is not right. The compiler is just buggy and failed to diagnose it. [temp.param]/11:

    A template parameter pack of a function template shall not be followed by another template parameter unless that template parameter can be deduced from the parameter-type-list of the function template or has a default argument (14.8.2).


    If the function type T(Args...) is meaningful to the end-user, one way to fix this would be to use a partial specialization instead:

    template class C; //undefined
    template
    class C {
        // implementation
    };
    

    Depending on the actual requirements, type-erasing the allocator might also be worth considering.

提交回复
热议问题