Can I partially specialize a template with a template like foo <T ..., int, U ...>?

If possible, you can index into the package of parameters of the variational template without recursion. However, GCC refuses to select my private specialization here:

template <int I, typename List> struct element_impl; template <typename... TL, int... IL, typename T, int I, typename... TR, int... IR> struct element_impl<I, typelist<pair<TL,IL>..., pair<T,I>, pair<TR,IR>...>> { typedef T type; }; 

prog.cpp: when creating ' element<0, typelist<int, double, char, float, long int> > ':
prog.cpp: 52: 34: created here
prog.cpp: 47: 79: error: invalid use of incomplete type ' struct element_impl<0, typelist<pair<int, 0>, pair<double, 1>, pair<char, 2>, pair<float, 3>, pair<long int, 4> > '

Is GCC a bug, or am I ignoring some limitation of variational patterns?

+6
source share
2 answers

The spectrum speaks at 14.8.2.5p9

If P has a form containing <T> or <i> , then each argument Pi corresponding argument list of the pattern P compared with the corresponding argument Ai corresponding argument list of the pattern A If the argument list of the template P contains a package extension that is not the last argument of the template, the entire argument list of the template is an irreducible context.

Unfortunately, your typelist<T> matches this pattern.

+5
source

AFAICT, rules for matching partial specializations are the same as deriving rule types from rule parameters. And in ยง14.8.2.1 / 1 it says the following:

For the function parameter package that occurs at the end of parameter-declaration-list, the type A each remaining argument call is compared with the type P identifier declarator function parameter package. Each comparison displays the template arguments for subsequent positions in the parameter template packages extended by the function parameter package. For a function parameter package that does not occur at the end of the declaration-parameter list, the parameter parameter type is not an inferred context.

Thus, TL and IL packets cannot be deduced in this case, and partial specialization is not selected.

+2
source

Source: https://habr.com/ru/post/918293/


All Articles