zoukankan      html  css  js  c++  java
  • STL源码剖析——SGI STL编译器组态

    1、__STL_STATIC_TEMPLATE_MEMBER_BUG

    如果编译器无法处理static member of template classes(模板类静态成员)就定义

    2、__STL_CLASS_PARTIAL_SPECIALIZATION

    如果编译器支持 partial specialization of class templates(模板类偏特化)就定义,所谓模板类偏特化

    参考:

      http://blog.csdn.net/thefutureisour/article/details/7964682/ 

      https://blog.csdn.net/q8250356/article/details/80672466 

    3、__STL_FUNCTION_TMPL_PARTIAL_ORDER

    如果编译器支持partial ordering of function templates或者说partial specialization of function templates就定义。

    参考:

      https://msdn.microsoft.com/en-us/library/zaycz069.aspx 可以理解为对函数模板的重载的支持

      https://blog.csdn.net/q8250356/article/details/80672500

    4、__STL_MEMBER_TEMPLATES

    如果编译器支持template members of classes 就定义,模板类中包含模板成员

    5、__STL_LIMITED_DEFAULT_TEMPLAES 

    用到前一个模板的模板形参的某一个具现体作为当前模板的模板形参的默认值 

    例如:
    template<class T, class Sequence=deque<T> >

    6、__STL_NON_TYPE_TMPL_PARAM_BUG

    测试类模板是否使用非类型模板参数(non-type template parameters) 
    参考:

      http://blog.csdn.net/zhangxiao93/article/details/50747862

      https://blog.csdn.net/q8250356/article/details/80672544

    7、__STL_NULL_TMPL_ARGS

    __STL_NULL_TMPL_ARGS是定义在 <stl_config.h>,定义如下:

    1 # ifdef __STL_EXPLICIT_FUNCTION_TMPL_ARGS 
    2 # define __STL_NULL_TMPL_ARGS <> 
    3 # else 
    4 # define __STL_NULL_TMPL_ARGS 
    5 # endif

    在STL中的<stl_stack.h>中有出现

     1 template <class T, class Sequence = deque<T> >
     2 class stack {
     3   friend bool operator== __STL_NULL_TMPL_ARGS (const stack&, const stack&);
     4   friend bool operator< __STL_NULL_TMPL_ARGS (const stack&, const stack&);
     5   //......
     6  };
     7  //也就是:
     8  template <class T, class Sequence = deque<T> > 
     9 class stack { 
    10 friend bool operator== <> (const stack&, const stack&); 
    11 friend bool operator< <> (const stack&, const stack&); 
    12 //... 
    13 };
    14 
    15 //实现:
    16 template <class T, class Sequence>
    17 bool operator==(const stack<T, Sequence>& x, const stack<T, Sequence>& y) {
    18   return x.c == y.c;
    19 }
    20 
    21 template <class T, class Sequence>
    22 bool operator<(const stack<T, Sequence>& x, const stack<T, Sequence>& y) {
    23   return x.c < y.c;
    24 }

    下面这四种写法都是可以的:

     1 //第一种写法:
     2 friend bool operator== __STL_NULL_TMPL_ARGS (const stack&, const stack&);
     3 friend bool operator< __STL_NULL_TMPL_ARGS (const stack&, const stack&);
     4 //第二种写法:
     5 friend bool operator== <T> (const stack<T>&, const stack<T>&); 
     6 friend bool operator< <T> (const stack<T>&, const stack<T>&); 
     7 //第三种写法:
     8 friend bool operator== <T> (const stack&, const stack&); 
     9 friend bool operator< <T> (const stack&, const stack&); 
    10 //第四种写法:
    11 friend bool operator== <> (const stack&, const stack&); 
    12 friend bool operator< <> (const stack&, const stack&);

    但是不能写成这样:

    1 //不可以
    2 // friend bool operator== (const stack&, const stack&); 
    3 // friend bool operator< (const stack&, const stack&);

    8、__STL_TEMPLATE_NULL

    即 template <> 显式的模板特化 
    比如
      __STL_TEMPLATE_NULL struct hash<char>{...};
    展开为
      template<> struct hash<char>{...};

    本文来自博客园,作者:Mr-xxx,转载请注明原文链接:https://www.cnblogs.com/MrLiuZF/p/14000191.html

  • 相关阅读:
    Django组件-cookie与session
    Js获取标签高度
    js动态添加事件
    div 显示与隐藏
    JS字符串截取
    网页事件
    js_event.keycode值大全
    DOS删除服务
    判断字符串的编码
    《把时间当作朋友》读书笔记(二)-- 困境
  • 原文地址:https://www.cnblogs.com/MrLiuZF/p/14000191.html
Copyright © 2011-2022 走看看