- // * __STL_NO_BOOL: defined if the compiler doesn't have bool as a builtin type.
- # if defined(__sgi) && !defined(__GNUC__)
- # include <standards.h>
- # if !defined(_BOOL)
- # define __STL_NO_BOOL
- # endif
- //... ...
- # endif
- //下面定义了bool
- # if defined(__STL_NO_BOOL) && !defined(__STL_DONT_USE_BOOL_TYPEDEF)
- typedef int bool;
- # define true 1
- # define false 0
- # endif
__STL_PARTIAL_SPECIALIZATION_SYNTAX: defined if the compiler supports partial specialization syntax for full specialization of class templates. (Even if it doesn't actually support partial specialization itself.)
__STL_FUNCTION_TMPL_PARTIAL_ORDER: defined if the compiler supports partial ordering of function templates. (a.k.a partial specialization of function templates.)
__STL_MEMBER_TEMPLATES: defined if the compiler supports template member functions of classes.
__STL_MEMBER_TEMPLATE_CLASSES: defined if the compiler supports nested classes that are member templates of other classes.
__STL_TEMPLATE_FRIENDS: defined if the compiler supports templatized friend declarations.
不想深入研究的话就默认编译器都支持就行了。再就是异常捕获和断言了:
- # ifdef __STL_USE_EXCEPTIONS
- # define __STL_TRY try
- # define __STL_CATCH_ALL catch(...)
- # define __STL_THROW(x) throw x
- # define __STL_RETHROW throw
- # define __STL_NOTHROW throw()
- # define __STL_UNWIND(action) catch(...) { action; throw; }
- # else
- # define __STL_TRY
- # define __STL_CATCH_ALL if (false)
- # define __STL_THROW(x)
- # define __STL_RETHROW
- # define __STL_NOTHROW
- # define __STL_UNWIND(action)
- # endif
- #ifdef __STL_ASSERTIONS
- # include <stdio.h>
- # define __stl_assert(expr) \
- if (!(expr)) { fprintf(stderr, "%s:%d STL assertion failure: %s\n", \
- __FILE__, __LINE__, # expr); abort(); }
- #else
- # define __stl_assert(expr)
- #endif
既然出现了__FILE__就说一说C++里的六个预定义的符号常量:
__FILE__: 当前源代码文件的行号(一个整数常量)
__LINE__: 假定的源文件名(一个字符串)
__DATE__: 源文件的编译日期(字符串格式为:“Mmm dd yyyy")
__STDC__: 指出程序是否符合ANSI/ISO C标准。如果完全符合,值就为1,否为未定义
__TIME__: 源文件的编译时间(字符串格式为:"hh:mm:ss")
__cplusplus: 如果文件被C++编译器编译则包含值199711L,否则未定义。允许文件当做C/C++文件来创建和编译