boost bcp --namespace真的有什么作用?

时间:2013-06-14 05:51:47

标签: c++ boost namespaces

我的印象是,带有命名空间选项的boost bcp旨在重命名所有列出的模块的包含和定义。在运行工具并检查输出时,它似乎没有这样做。如果他们仍然#include <boost/*>并希望最终用户的#include <boost/*>不会导致版本冲突,我如何重新分发这些内容?它只是用命名空间封闭包装它们吗?

我使用了以下bcp命令:

.\boost_1_53_0\dist\bin\bcp.exe --boost=boost_1_53_0 --namespace=myboost --namespace-alias smart_ptr filesystem array.hpp container move ptr_container algorithm/string.hpp tokenizer.hpp thread chrono atomic foreach.hpp build myboost

文件的快速grep:

[boost]grep -e "boost/" algorithm\string.hpp
grep -e "boost/" algorithm\string.hpp
#include <boost/algorithm/string/std_containers_traits.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/find.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/erase.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/find_iterator.hpp>

我很确定这是带有命名空间选项的bcp工具的用例,但是,我显然误解了一些常见的C ++概念/用法,对吧?或者,也许,我使用的工具不正确?

提前感谢任何见解。

2 个答案:

答案 0 :(得分:3)

bcp --namespace = myboost --namespace-alias regex config build / foo

将完整的正则表达式lib(在libs / regex中)和config lib(libs / config)以及构建系统(tools / build)复制到/ foo,包括所有依赖项。还要将boost命名空间重命名为myboost,并将二进制库的文件名更改为以前缀“myboost”而不是“boost”开头。 --namespace-alias选项使命名空间提升为新名称的别名。

只会重命名二进制文件(libboost_regex.so将为libmyboost_regex.so),而不是头文件。此外,名称空间boost将替换为myboost(而boost将替换为myboost)。

答案 1 :(得分:0)

与名称一样,它重命名名称空间和库文件(即.dll和.libs),但标题所在的目录,以及因此不是包括。

Boost库通常位于namespace boost。使用bcp,您将该命名空间更改为myboost。例如,此代码变为有效:

#include <boost/sharedptr.hpp> //header directories haven't changed

myboost::shared_ptr<int> pi = myboost::make_shared<int>(5); //but the namespace has

感谢--namespace-alias,您可以继续使用namesapce提升,因为boost已成为myboost的别名:

boost::shared_ptr<int> pi; //ok, this is in fact a myboost::shared_ptr

请参阅文档中的示例:http://www.boost.org/doc/libs/1_53_0/tools/bcp/doc/html/index.html