STL源代码分析(ch 1)组态2
生活随笔
收集整理的這篇文章主要介紹了
STL源代码分析(ch 1)组态2
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
4. __STL_MEMBER_TEMPLATES
模板類中包含模板成員,是否支持template members of classes
class vec { public:typedef T value_type;typedef value_type* iterator;template<class I>void insert(iterator position, I first, I last) {cout << "insert()" << endl;} };int main() {int ia[5] = { 0,1,2,3,4 };vec<int> a;vec<int>::iterator ite;a.insert(ite, ia, ia + 5); }5. __STL_LIMITED_DEFAULT_TEMPLAES
用到前一個模板的模板形參的某一個具現體作為當前模板的模板形參的默認值
template <class T,class Alloc=alloc,size_t BufSiz=0> class deque { public:deque() { cout << deque() << endl; } };template <class T,class Sequence=deque<T>> class stack { public:stack() { cout << "Stack" << endl; } private:Sequence c; };int main() {stack<int> x; }6. __STL_NON_TYPE_TMPL_PARAM_BUG
類模板是否使用非類型模板參數(non-type template parameters)
通常它們只能是常數整數(constant integral values )包括枚舉,或者是指向外部鏈接的指針。
不能把float,class-type類型的對象,內部鏈接(internal linkage )對象,作為非類型模板參數。
7.__STL_TEMPLATE_NULL
指定一種或多種模板形參的實際值或實際類型,作為特殊情況
#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION # define __STL_TEMPLATE_NULL template<> #else # define __STL_TEMPLATE_NULL #endif template<class type> struct __type_traits{ ...};//非特化情況均使用這個 __STL_TEMPLATE_NULL struct __type_traits<char> { ... };//特化char情況template<class Key> struct hash { };//非特化情況均使用這個 __STL_TEMPLATE_NULL struct hash<char> { ... };//特化char情況 __STL_TEMPLATE_NULL struct hash<unsgned char> { ... };//特化unsigned char情況=>
template<class type> struct __type_traits{ ...};//非特化情況均使用這個 template<> struct __type_traits<char> { ... };//特化char情況template<class Key> struct hash { };//非特化情況均使用這個 template<> struct hash<char> { ... };//特化char情況 template<> struct hash<unsgned char> { ... };//特化unsigned char情況總結
以上是生活随笔為你收集整理的STL源代码分析(ch 1)组态2的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 排序 (5)桶排序“概念”
- 下一篇: STL源代码分析(ch2 内存分配)概述