| 
 stl_config.h的各种组态在阅读侯捷老师的《stl源码剖析》,了解到组态这个东西,说是其书上所列的几个组态常量是用来区分编译器对c++ Standard的支持程度,以下的组态所关系到的代码都是template参数推导,偏特化之类的问题 组态一:__STL_STATIC_TEMPLATE_BUG
  
 测试在class template中拥有static data members 组态二:__STL_CLASS_PARTIAL_SPECIALIZATION  
 测试 class template partial specialization–在class template 的一般化设计之外,特别针对某些template参数做特殊设计也就是说测试编译器是否支持模板偏特化,支持就定义 组态三:__STL_FUNTION_TMPL_PARTIAL_ORDER  
 测试对函数模板的支持 组态四:__STL_EXPLICIT_FUNTION_TMPL_ARGS  
 整个SGI STL中没有用到这一常量定义 组态五:__STL_MEMBER_TEMPLATE  
 测试模板类中可否再有模板成员,能否模板嵌套 组态六:__STL_LIMITED_DEFAULT_TEMPLATES  
 测试template参数是否可以根据前一个template参数设定默认值 例如 template<class T,class Sequence=deque<T>> 组态七:__STL_NON_TYPE_TMPL_PARAM_BUG  
 测试class template可否拥有 non—type template template <class T,class Ref,class Ptr, size_t sz>
 组态八:__STL_NULL_TMPL_ARGS  
 整个组态常量常常出现在友元函class template的friend函数声明 template <class T,class Sequence=deque<T>>
class stack{
 friend bool operator==__STL_NULL_TMPL_ARGS(const stack&,const stack&);
 friend bool operator<__STL_NULL_TMPL_ARGS(const stack&.const stack&);
 ...
}
//__STL_NULL_TMPL_ARGS展开为<>
template <class T,class Sequence=deque<T>>
class stack{
 friend bool operator==<>(const stack&,const stack&);
 friend bool operator< <>(const stack&.const stack&);
 ...
}
 组态九:__STL_TEMPLASTE_NULL  
 <Stl.config.h>定义了一个_STL_TEMPLATE_NULL,如下 #ifdef _STL_CLASA_PAITIAL_SPECIALIZATION #define _STL_TEMPLATE_NULL template<> #else #define _STL_REMPLATE_NULL #endif template <class key>struct hash{...};
_STL_REMPLATE_NULL struct hash<char>{...};
_STL_REMPLATE_NULL struct hash<unsigned char>{...};
//如果编译器支持偏特化那么就可以使用,_STL_REMPLATE_NULL代替template<>
template <class key>struct hash{...};
template<> struct hash<char>{...};
template<> struct hash<unsigned char>{...};
 临时对象的产生 所谓临时对象是一种无名对象,他的出现不会不在程序的预期之下,(例如任何pass by value,都会引发copy操作,于是形成临时对象,往往造成效率的负担。)但是有时候可以制造一些临时对象,却使程序非常干净。 如何可以制造临时对象:在性别名称之后直接加一对()并且可以给予初值,shape(3,5),int(8),其意义是调用相应的构造函数,且不指定对象名称。STL常常利用此技巧应用于仿函数与算法的搭配
 template<typename T>
class print{
  public:
     void operator()(const T& elem){
         cout<<elem<<" ";
     }
};
int main(){
    int ia[6]={0,1,3,4,5,6};
    vector<int>iv(ia,ia+6);
    for_each(iv.begin(),iv.end(),print<int>());//print<int>()是一个临时对象,当for_each结束时这个临水对象也结束了它的生命
}
 静态常量整数成员在class内部直接初始化template<typename T>
class test{
  public:
     static const int a=5;
     static const long b=4l;
     static const char c='c';
};
 increment/decrement/dereference操作符前开后闭区间表示法任何一个STL算法,都需要由一对迭代器所标示的区间,用于表示操作范围,这一对迭代器获得的是前闭后开的区间,也就是说end()所指的是最后一个元素的下一个元素。
 funtion call 操作符template<class T>
class puls{
    T operator()(const T&x,const T&y){
        return x+y;
    }
};
//有两种使用方式,一种是创建对象,一种是创建临时对象】
int main(){
    plus<int>plusobj;
    cout<<plusobj(3,5);
    
    cout<<plus<int>()(3,5);//创建临时对象
}
 |