用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

June 11, 2014 · 1 min · kamus

用Range Adaptor,废弃replace_copy_if之类的函数

看看replace_copy_if的一个简单的例子: std::vector vec; boost::replace_copy_if(rng, std::back_inserter(vec), pred, new_value); 对于这种写法,如果使用Range Adaptor的话,则可以写成: std::vector vec; boost::push_back(vec, rng | boost::adaptors::replaced_if(pred, new_value)); 第二种写法有什么好处呢, 更高效率。因为std::back_inserter有额外的内存分配开销。 更灵活。因为第二种写法可以应用更多的适配器,比如: boost::push_back(vec, rng | boost::adaptors::replaced_if(pred, new_value) | boost::adaptors::reversed); 更安全。因为第二种写法没有用unbounded output iterator。

April 15, 2014 · 1 min · kamus

boost::io_service的poll_one和run_one有什么区别

boost::io_service的poll_one会立即返回(non-blocking),不管有没有已经被触发的处理函数(ready handler)。 而run_one有可能阻塞。如果还没有被触发的处理函数,run_one会阻塞到有一个handler被调用为止。 更多资料: http://think-async.com/ 呃。这篇日志也太短了!!! BOOST库真是个好东西啊~~好多写法很有现代脚本语言的taste。~~而且,那么丰富的库让生产效率大大提高了。 copyright ykyi.net

March 18, 2014 · 1 min · kamus

C++准标准库boost转向github,并发布模块化boost(modular Boost)

难道是中文社区首次报道吗?我用中文搜索引擎没有搜索到modular boost的文章。 昨天想在STL的map容器上增加一个特性,即把std::map中所有的元素按照加入的先后时间用链表链接起来,以保存元素之间的时序关系。 为了这个基于std::map和std::list的新的容器能够兼容STL的算法,于是想实现stl compatible iterator。一口气读了几十页资料,发现最酷最好的方法是用boost的迭代器模板实现。纠结了很久,最终决定在我的工程中引入boost。为了获得快速开发的好处,还是加入更多的开源库吧。毕竟,如果自己造一个轮子,阅读者仍然要花时间理解你发明的轮子,还不如用已经广泛使用的轮子。况且,计划要引入boost中asio的proactor I/O模型。所以,今天就开始引入boost吧。 于是,发现boost早就发起了modular boost项目并把boost host在github.com上,如下地址: https://github.com/boostorg 在boost的官方网站上有模块化boost的FAQ: https://svn.boost.org/trac/boost/wiki/ModCvtFAQ 还有它的简单使用教程: https://svn.boost.org/trac/boost/wiki/TryModBoost#InstallingModularBoost 教程上说,如果把整个module boost git clone到本地,需要花费45分钟,如果下行网速是3Mbps,而且需要占用1.5G磁盘! 我晕~~ 另外FAQ上说:没办法只检出一个子库,暂时不能自动地解决依赖性问题。 原文: Is it possible to checkout only one library and its prerequisites? Not automatically. Automatic dependency resolution is planned for the future, but not as a part of the conversion to Git and Modular Boost. ...

February 13, 2014 · 1 min · kamus