草庐IT

boost-pool

全部标签

c++ - 如何为 boost::tuple 编写一个 `<<` 运算符?

在下面的示例代码中,它表明可以从第一个模板参数隐式创建boost::tuple。因此,我无法写运算符,因为它变得模棱两可。我也不明白为什么ostringstream&也是模棱两可的。这没有任何隐式构造。为什么这也会产生模棱两可的错误?#include#include#include#includeusingnamespacestd;classMyclass{};typedefboost::tupleMytuple;ostringstream&operator();//os_();//ErrorbecauseintisimplicitlyconvertedintoMytuple.WHYY

c++ - Boost Gzip 过滤器 : compile failes

我正在尝试从BoostGzip过滤器页面编译示例:#include#include#include#include#includeintmain(){usingnamespacestd;ifstreamfile("hello.gz",ios_base::in|ios_base::binary);filtering_streambufin;in.push(gzip_decompressor());in.push(file);boost::iostreams::copy(in,cout);}遗憾的是我的g++返回错误:gzlib.cpp:Infunction‘intmain()’:gzli

c++ - 使用单独的 .h 和 .cpp 文件 boost 序列化

我正在试验boost序列化库,并且大部分都可以正常工作。唯一的问题是当我尝试序列化具有单独的.h和.cpp文件的对象时。当我使用这个命令编译时:g++boostSerialize.cppClass.cpp-lboost_serialization我收到这个错误:/tmp/cc8kbW6J.o:Infunction`voidboost::serialization::access::serialize(boost::archive::text_oarchive&,Class&,unsignedint)':boostSerialize.cpp:(.text._ZN5boost13seria

c++ - BOOST 线程 : cout behavior

我是Boost线程的新手,我对如何从多个线程执行输出感到困惑。我有一个简单的boost::thread从9倒数到1;主线程等待然后打印“LiftOff..!!”#include#includeusingnamespacestd;structcallable{voidoperator()();};voidcallable::operator()(){inti=10;while(--i>0){cout问题是我必须在线程中使用明确的“cout.flush()”语句来显示输出。如果我不使用flush(),我只会得到“LiftOff!!”作为输出。有人可以告诉我为什么我需要显式使用flush()

c++ - boost::call_traits - 为什么 gcc 为此给出 false?

示例:#include#include#includeboost::call_traits::param_typef(){return1;}intmain(){std::cout::param_type>::value::value问题:除非我做错了什么,我想我应该为两者都得到true,但是gcc4.7.0为后者输出false。有什么我想念的吗? 最佳答案 非类类型的右值永远不是const限定的。只有类类型的右值可以是const限定的。因此,即使函数f被声明为返回一个constint,即使函数f的类型是constint(),调用表达

c++ - 如何使用boost::spirit解析UTF-8?

#include#include#include#include#defineBOOST_SPIRIT_UNICODE//We'lluseunicode(UTF8)allthroughout#include#include#includevoidparse_simple_string(){namespaceqi=boost::spirit::qi;namespaceencoding=boost::spirit::unicode;//namespacestw=boost::spirit::standard_wide;typedefstd::wstring::const_iteratori

c++ - 在boost中为斐波那契堆定义比较函数

我需要在我的项目中使用Fibonacci堆,我正在尝试从boost库中使用它。但我不知道如何为任意数据类型设置用户定义的比较函数。我需要为结构节点构造一个最小堆,定义如下:structnode{intid;intweight;structnode*next;/*distisaglobalarrayofintegers*/booloperator>(structnodeb)//BoostgeneratesaMax-heap.WhatIneedisamin-heap.{returndist[id]".booloperatordist[b.id]?1:0;}booloperator>=(st

c++ - 尝试使用 boost::optional 失败

我一直在尝试将boostoptional用于可以返回对象或null的函数,但我无法弄清楚。这是我到目前为止所拥有的。任何有关如何解决此问题的建议都将不胜感激。classMyclass{public:inta;};boost::optionalfunc(inta)//ThiscouldeitherreturnMyClassoranull{boost::optionalvalue;if(a==0){//returnanobjectboost::optionalvalue;value->a=200;}else{returnNULL;}returnvalue;}intmain(intargc,

c++ - boost::split 与 boost::iter_split 之间的区别

boost::split和boost::iter_split函数有什么区别? 最佳答案 boost::split将拆分后的字符串复制到SequenceSequenceT(例如std::vector)。boost::iter_split地点iterators(特别是迭代器范围)到SequenceSequenceT.这实际上意味着两件事:使用split将创建拷贝,因此原始字符串不会看到对返回的字符串容器的任何更改。此外,您无需担心迭代器失效。使用iter_split将返回一个迭代器范围的容器,因此,修改这些迭代器指向的内容也会修改原始字

c++ - Boost.Spirit 编译器无法识别 std::pair

#include#includenamespaceqi=boost::spirit::qi;intmain(){//thefollowingparses"1.02.0"intoapairofdoublestd::stringinput("1.02.0");std::string::iteratorstrbegin=input.begin();std::pairp;qi::phrase_parse(strbegin,input.end(),qi::double_>>qi::double_,//parsergrammarqi::space,//delimitergrammarp);//at