我如何包装BOOST在一个单独的命名空间? [英] How can I wrap BOOST in a separate namespace?
本文介绍了我如何包装BOOST在一个单独的命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我期待有BOOST的两个版本同时编译成一个项目。理想的情况下,他们应该沿着这些线路是可用的:
boost_1_36_0 ::提高:: shared_ptr的< SomeClass的> SomeClass的=新SomeClass的();
boost_1_35_0 ::的boost ::正则表达式前pression([0-9],boost_1_35_0 ::提高:: regex_constants ::基础);
解决方案
我读(好扫描)通过的开发列表讨论。有没有简单的解决方案。综上所述:
-
在一个命名空间声明包装的头文件
命名空间boost_1_36_0 {
#包括LT&; boost_1_36_0 /升压/ regex.hpp>
}
命名空间boost_1_35_0 {
#包括LT&; boost_1_35_0 /升压/ shared_ptr.hpp>
}- 需要修改源文件
- 不允许用于向被包括在相同的翻译单元两个版本,由于这一事实,即宏不尊重命名空间。
-
定义提振包括标题前
的#define提升boost_1_36_0
#包括LT&; boost_1_36_0 /升压/ regex.hpp>
和#undef提振
#定义提振boost_1_35_0
#包括LT&; boost_1_35_0 /升压/ shared_ptr.hpp>
和#undef提振- 源文件可以简单地用
-Dboost = boost_1_36_0
编译 - 不是在一个翻译单元解决宏观的冲突。
-
一些内部头文件中的夹杂物可能会搞砸了,因为这样的事情确实发生了。
#如果定义(SOME_CONDITION)
#定义头<升压/一些/ header.hpp>
#其他
#定义头<升压/一些/其它/ header.hpp>
#万一但它可能是很容易解决这些情况。
- 源文件可以简单地用
- 修改整个升压库替换
空间boost {..}
与命名空间boost_1_36_0 {...}
然后提供了一个命名空间别名。替换所有BOOST_XYZ
宏及其用途与BOOST_1_36_0_XYZ
宏。- 如果您是愿意投入努力这可能会工作。
I'm looking to have two versions of BOOST compiled into a project at the same time. Ideally they should be usable along these lines:
boost_1_36_0::boost::shared_ptr<SomeClass> someClass = new SomeClass();
boost_1_35_0::boost::regex expression("[0-9]", boost_1_35_0::boost::regex_constants::basic);
解决方案
I read (well scanned) through the development list discussion. There's no easy solution. To sum up:
Wrapping header files in a namespace declaration
namespace boost_1_36_0 { #include <boost_1_36_0/boost/regex.hpp> } namespace boost_1_35_0 { #include <boost_1_35_0/boost/shared_ptr.hpp> }
- Requires modifying source files
- Doesn't allow for both versions to be included in the same translation unit, due to the fact that macros do not respect namespaces.
Defining boost before including headers
#define boost boost_1_36_0 #include <boost_1_36_0/boost/regex.hpp> #undef boost #define boost boost_1_35_0 #include <boost_1_35_0/boost/shared_ptr.hpp> #undef boost
- Source files can simply be compiled with
-Dboost=boost_1_36_0
- Still doesn't address macro conflicts in a single translation unit.
Some internal header file inclusions may be messed up, since this sort of thing does happen.
#if defined(SOME_CONDITION) # define HEADER <boost/some/header.hpp> #else # define HEADER <boost/some/other/header.hpp> #endif
But it may be easy enough to work around those cases.
- Source files can simply be compiled with
- Modifying the entire boost library to replace
namespace boost {..}
withnamespace boost_1_36_0 {...}
and then providing a namespace alias. Replace allBOOST_XYZ
macros and their uses withBOOST_1_36_0_XYZ
macros.- This would likely work if you were willing to put into the effort.
这篇关于我如何包装BOOST在一个单独的命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文