2014-05-22 18 views
5

से 3.3.9/1 एक उद्धरण है:क्या टेम्पलेट पैरामीटर के टेम्पलेट पैरामीटर-सूची मतलब है

एक टेम्पलेट टेम्पलेट पैरामीटर के टेम्पलेट पैरामीटर के नाम की कथात्मक क्षेत्र है में सबसे छोटा टेम्पलेट-पैरामीटर-सूची जिसे नाम पेश किया गया था।

क्या आप उपर्युक्त परिभाषा को समझने के लिए एक उदाहरण दे सकते हैं? मुझे यह जानने में भी रूचि है कि टेम्पलेट पैरामीटर की टेम्पलेट-पैरामीटर-सूची का क्या अर्थ है? एक उदाहरण उपयोगी होगा।

उत्तर

5
template< // outer template-parameter-list 
    template< // inner template-parameter-list 
     typename q, // named parameter of a template template-parameter 
     q x // use that name 
    > // the declarative region ends here 
    class q // hence the name may be reused 
> struct x {}; 

यहाँ यह बिना फिर से है नहीं है टिप्पणियां अगर इससे आगे बढ़ने में मदद मिलती है:

template< template< typename q, q x > class q > 
struct x {}; 

यह किसी दिए गए प्रकार का निरंतर मान लेने वाले टेम्पलेट पर पैरामीटरकृत एक वर्ग है। उदाहरण के लिए आप x<std::integral_constant> कर सकते हैं।

2

यह उदाहरण निम्नलिखित के लिए अंतरतम पैरामीटर सूची टेम्पलेट टेम्पलेट मानकों के दायरे को सीमित करता है, वैध है

template<template<typename U, typename V = U> class T> 
struct foo 
{ 
    T<int> bar(); // T<int, int> 
}; 

लेकिन इस

template<template<typename U> class T> 
struct foo 
{ 
    U bar(); // error: ‘U’ does not name a type 
}; 
संबंधित मुद्दे