STL源代码分析(ch 1)组态1
生活随笔
收集整理的這篇文章主要介紹了
STL源代码分析(ch 1)组态1
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1. __STL_STATIC_TEMPLATE_MEMBER_BUG
static member of template classes(模板類靜態成員)
template <typename T> class test{ public:static int _data; }int test<int>::_data=1; int test<char>::_data=2;2. __STL_CLASS_PARTIAL_SPECIALIZATION
模板類偏特化,是否支持 partial specialization of class templates
//一般化設計,非特化情況均使用這個 template <class I,class O> struct test{test() { cout << "I, O" <<endl; } };//特殊化設計1(偏特化1) template <class T> struct test <T* ,T*> {test() { cout << "T* ,T*" << endl; } };//特殊化設計2(偏特化2) template <class T> struct test <const T* ,T*> {test() { cout << "const T* ,T*" << endl; } };//測試 int main() {test<int, char> obj1; //I, Otest<int*, int*> obj2; //T*, T*test<const int*, int*> obj3; //const T*, T* }3. __STL_FUNCTION_TMPL_PARTIAL_ORDER
是否支持partial ordering of function templates
template <class T,class Alloc=alloc> class vec { public:void swap(vec<T, Alloc>&) { cout << "swap1()" << endl; } };#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER template <class T, class Alloc = alloc> inline void swap(vec<T, Alloc>& a, vec<T, Alloc>& b) { a.swap(b); } #endifint main() {vec<int> a, b;swap(a, b); }總結
以上是生活随笔為你收集整理的STL源代码分析(ch 1)组态1的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: STL源代码分析(ch 1)概述
- 下一篇: Boost Asio总结(16)例子