草庐IT

boost-container

全部标签

c++ - boost::variant 是否与 std::string 一起使用?

我使用boost::variant用C++编写了一个简单的程序。程序代码如下所示。#include#include#includeintmain(intargc,char**argv){boost::variantv;v=3;std::cout但是当我尝试用命令编译它时g++main.cpp-omain-lboost_system我明白了/usr/include/boost/variant/detail/variant_io.hpp:64:error:nomatchfor‘operator>>*)this)->boost::detail::variant::printer>>::out

c++ - 将 boost::bind 与 boost::function 一起使用:检索绑定(bind)变量类型

有什么方法可以检索有关哪些参数受boost::bind限制的信息,还是需要手动存储?即:在.h中classMyClass{voidfoo(inta);voidfoo2(doubleb);voidbar();voidexecute();int_myint;double_mydouble;}在.cpp中MyClass::bar(){vectormyVector;myVector.push_back(boost::bind(&MyClass::foo,this,MyClass::_myint);myVector.push_back(boost::bind(&MyClass::foo2,thi

c++ - const decltype(*std::begin(container))& val 不会使 val const?

这段代码:std::vectorints(5,1);std::for_each(ints.begin(),ints.end(),[](constdecltype(*std::begin(ints))&val){val*=2;});在VisualStudio2010中编译和运行得很好,并且修改容器中的每个值,就像没有const关键字一样。这是编译器中的错误吗,因为预期的行为是val是不可修改的?(换句话说,我希望它不会编译,但它会编译)更新:std::for_each(ints.begin(),ints.end(),[](conststd::remove_reference::type&

c++ - 如何格式化不带引号的 boost 路径对象?

这是我的代码:fs::pathdatadir=...;std::stringdataDirOption((boost::format("--datadir=%1%")%datadir).str());对于datadir=="c:/db",我得到dataDirOption=="--datadir=\"c:/db\"",而不是"--datadir=c:/db"是否可以告诉boost::filesystem::path在格式化时跳过引号?现在,我知道我可以用datadir.string()替换datadir并以这种方式去掉引号,但我想知道我是否可以这样做没有额外的字符串。谢谢。

c++ - 链接 boost::thread

我正在尝试使用boost库学习一些东西,但是当我尝试编译包含boost::threads的东西时遇到了问题。我在链接过程中遇到错误,消息如下:/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/../../../../x86_64-pc-linux-gnu/bin/ld:cannotfind-lboost-thread但这很奇怪,因为只有当我用普通用户编译时才会发生这种情况,使用root我可以毫无问题地编译。提前致谢。 最佳答案 包含#include其他链接器标志-lboost_system-lboost_

c++ - 将字符串 vector 连接到 std::ostream(如 boost::join)

我有一个字符串vector,我想将它输出到流(实际上是文件流)。我想在vector元素之间有一个分隔符。有一种方法可以使用标准ostream_iteratorstd::vectorstrs;std::ostream_iteratorout_file_iterator(out_file,delim);std::copy(strs.begin(),strs.end(),out_file_iterator);我不喜欢这种方式,因为each元素后有一个delim文本,但我不需要有一个delim在最后一个元素之后。我想使用类似boost::join的东西。但是boost::join返回字符串,而

c++ - Cpp - 检查 key 是否存在于 boost bimap 中

我有一张双图。我想检查key是否存在于我的bimap中。我怎样才能做到这一点。这是我的双图:namespacebimap{structName{};structID{};typedefboost::bimaps::bimap>,boost::bimaps::set_of>>name_index_bimap;}我想检查“名称”是否存在。 最佳答案 这在thisexample中解释得很清楚。.在您的情况下,它应该如下所示:name_index_mapyour_map;name_index_map::right_const_iterato

c++ - boost ASIO 并发度

我正在学习使用BoostASIO。这是从chatexample复制的一些代码与BoostASIO文档一起提供,typedefstd::dequechat_message_queue;classchat_client{public:chat_client(boost::asio::io_service&io_service,tcp::resolver::iteratorendpoint_iterator):io_service_(io_service),socket_(io_service){boost::asio::async_connect(socket_,endpoint_iter

c++ - boost::optional<std::string> 和来自 char[] 的隐式构造函数

我已经习惯了通过让编译器找出所涉及的魔法来以下列方式初始化std::stringsstd::stringmy_string="hello";以下将不起作用,因为两种类型之间没有显式转换:boost::optionalmy_optional_string="hello";但这确实有效:boost::optionalmy_optional_string=std::string("hello");现在,难道没有办法菊花链隐式调用的单参数构造函数以允许第二种形式吗?我问的原因(虽然我不想用细节打扰你)是有一大堆类需要填充可选成员。必须显式输入所有内容似乎是一种负担(我不太担心自己,但我正在开发

c++ - 是否有 auto_ptr 的替代品可以与 c++11 中的 boost ptr_map 一起使用

在c++11中,auto_ptr已弃用,取而代之的是更合理的unique_ptr。唉,如果你使用boost::ptr_map,auto_ptr就完成了一个非常方便的用途:std::auto_ptrpLayer(newLayer());mRawLayerPtrMap.insert(layerName,pLayer);是否有可能使用与c++11类似的东西。这个我知道Layer*pLayer=newLayer();mFusedLayers.insert(fusedLayerName,pLayer);有效,但auto_ptr在一些更复杂的场景中有它的优点。是否有适用于C++11的替代品?