用boost的方式在预编译期检查编译器和平台以及其它

用boost的方式在预编译期检查编译器和平台以及其它

一般C/C++程序员都知道用一些编译器预编译宏来判断编译器的种类的操作系统。

一般有:
_WIN32 ,不管windows x86 还是 x86_64 都会有_WIN32,注意前面的下划线,如果没有下划线,MSDN的官方定义有这个酷酷的下划线.
__unix__ 是否 unix OS
__linux__ 是否是 linux
__apple__ 是否是平台

原来咧,BOOST库提供了一个相当丰富的库来做这件事:
这个BOOST库是 Predef http://www.boost.org/doc/libs/1_55_0/libs/predef/doc/html/index.html

#include <boost/predef.h>

看看官方文档的目录:
Table of Contents

Introduction
Using the predefs
Adding new predefs
Reference
BOOST_ARCH architecture macros
BOOST_COMP compiler macros
BOOST_LANG language standards macros
BOOST_LIB library macros
BOOST_OS operating system macros
Other macros
Version definition macros
Acknoledgements

包括处理器架构,编译器相关宏,语言相关宏,库相关宏,操作系统相关宏~~~

I like boost ~~~

copyright ykyi.net