2012-06-17 9 views
6

यदि यह संभव है, तो कोई भी रिकर्सन के बिना एक भिन्न टेम्पलेट पैरामीटर पैक में अनुक्रमित कर सकता है। हालांकि, जीसीसी refusing to pick up my partial specialization यहाँ है:क्या मैं आंशिक रूप से एक टेम्पलेट जैसे foo <टी ..., int, U ...> के साथ टेम्पलेट का विशेषज्ञ कर सकता हूं?

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> > '

जीसीसी गाड़ी है, या मैं variadic टेम्पलेट्स में से कुछ सीमा अनदेखी कर रहा हूँ?

+0

[यह सरल कोड] (http://ideone.com/CrNSc) के साथ, जीसीसी कहता है: 'त्रुटि: पैरामीटर पैक' टी 'टेम्पलेट पैरामीटर सूची के अंत में होना चाहिए'। इसलिए मुझे लगता है कि यह एक भाषा सीमा है। – Nawaz

+0

@ नवाज यह बिल्कुल वैसा नहीं है। –

+0

यह "बिल्कुल" समान नहीं है, लेकिन त्रुटि संदेश बहुत स्पष्ट है: पैरामीटर पैक * टेम्पलेट पैरामीटर सूची के अंत में * होना चाहिए। जीसीसी ने वही संदेश दोहराया है: http://ideone.com/2Rifn – Nawaz

उत्तर

5

कल्पना का कहना है 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.

आपका typelist<T> पर दुर्भाग्य है कि नमूने का मिलान।

+0

क्या आप साधारण शब्दों में मानक शब्दों को संभवतः एक या दो उदाहरणों के साथ विस्तारित कर सकते हैं? – Nawaz

+0

@ नवाज़ @RMartinho ने एक उत्कृष्ट उदाहरण दिखाया यह नियम संभवतया कुछ भी हो सकता है जो मैं कर सकता हूं। '' का अर्थ है "एक प्रकार पैरामीटर (पैक) युक्त टेम्पलेट तर्क सूची" और "" का अर्थ है "टेम्पलेट तर्क सूची जिसमें एक गैर-प्रकार पैरामीटर (पैक) है"। –

2

AFAICT, आंशिक विशेषज्ञता से मेल खाने के नियम नियम पैरामीटर के नियमों की कटौती के समान हैं। और §14.8.2.1/1 निम्नलिखित कहते हैं:

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.

तो पैक TL और IL इस मामले में निष्कर्ष निकाला जा सकता है, और आंशिक विशेषज्ञता नहीं उठाया गया है।