2012-06-17 2 views
6

Wenn dies möglich ist, kann man in ein Variant-Template-Parameterpaket ohne Rekursion indizieren. Allerdings ist GCC refusing to pick up my partial specialization hier:Kann ich eine Vorlage mit einem Muster wie foo <T ..., int, U ...> teilweise spezialisieren?

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: In instantiation of ' element<0, typelist<int, double, char, float, long int> > ':
prog.cpp:52:34: instantiated from 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> > '

Ist GCC Buggy, oder bin ich eine Einschränkung von variadische Vorlagen zu ignorieren?

+0

Mit [dieser einfachen Code] (http://ideone.com/CrNSc), sagt GCC: 'Fehler: Parameter-Pack 'T' muss am Ende der Vorlage Parameterliste sein. Daher denke ich, dass es eine Sprachbeschränkung ist. – Nawaz

+0

@Nawaz Das ist überhaupt nicht das Gleiche. –

+0

Es ist nicht "genau" gleich, aber die Fehlermeldung ist ziemlich klar: Das Parameterpack * muss * am Ende der Vorlagenparameterliste sein. GCC wiederholt die gleiche Nachricht auch hier: http://ideone.com/2Rifn – Nawaz

Antwort

5

Die Spezifikation sagt bei 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.

Ihr typelist<T> leider dieses Muster passt.

+0

Können Sie auf den Standard-Text in einfachen Worten, möglicherweise mit ein oder zwei Beispiele? – Nawaz

+0

@Nawaz @RMartinho zeigte ein hervorragendes Beispiel für Diese Regel ist möglicherweise besser als alles, was mir einfällt. '' bedeutet "Template-Argumentliste, die einen Typparameter (pack) enthält" und "" bedeutet "Template-Argumentliste, die einen Nicht-Typparameter (pack)" enthält. –

2

AFAICT, die Regeln für übereinstimmende partielle Spezialisierungen sind die gleichen wie die Regeln für die Ableitung von Funktionsparametern. Und §14.8.2.1/1 sagt die folgenden:

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 die Packungen TL und IL können in diesem Fall nicht abgeleitet werden, und die partielle Spezialisierung wird nicht abgeholt.

Verwandte Themen