Can I partially specialize a template with a pattern like foo?

前端 未结 2 484
误落风尘
误落风尘 2021-01-12 18:07

If this is possible, one can index into a variadic template parameter pack without recursion. However, GCC is refusing to pick up my partial specialization here:

<         


        
相关标签:
2条回答
  • 2021-01-12 18:21

    The spec says at 14.8.2.5p9

    If P has a form that contains <T> or <i>, then each argument Pi of the respective template argument list P is compared with the corresponding argument Ai of the corresponding template argument list of A. If the template argument list of P contains a pack expansion that is not the last template argument, the entire template argument list is a non-deduced context.

    Your typelist<T> unfortunately matches that pattern.

    0 讨论(0)
  • 2021-01-12 18:41

    AFAICT, the rules for matching partial specializations are the same as the rules type deduction of function parameters. And §14.8.2.1/1 says the following:

    For a function parameter pack that occurs at the end of the parameter-declaration-list, the type A of each remaining argument of the call is compared with the type P of the declarator-id of the function parameter pack. Each comparison deduces template arguments for subsequent positions in the template parameter packs expanded by the function parameter pack. For a function parameter pack that does not occur at the end of the parameter-declaration-list, the type of the parameter pack is a non-deduced context.

    So the packs TL and IL cannot be deduced in this case, and the partial specialization is not picked.

    0 讨论(0)
提交回复
热议问题