草庐IT

boosting

全部标签

c++ - 如何使用 boost lambda 用新对象填充指针 vector

我最近开始使用boostlambda,我想我会尝试在它会/应该使事情更容易阅读的地方使用它。我有一些类似下面的代码std::vectorv;for(inti=0;i稍后,删除它...std::for_each(v.begin(),v.end(),boost::lamda::delete_ptr());整齐地整理。但是,我想我应该尝试使用lambda来“lambda化”vector的总体......然后烟火开始了......我试过了..std::generate_n(v.begin(),20,_1=newX());但这引发了各种编译器错误。实现此目标的最佳“lambda”方式的任何想法。

c++ - C++ 中的 boost::bind 和 << 运算符

我想绑定(bind)for_each(begin,end,boost::bind(&operator不幸的是它不起作用:Error1errorC2780:'boost::_bi::bind_t::type,boost::_mfi::dm,_bi::list_av_1::type>boost::bind(MT::*,A1)':expects2arguments-3providedc:\source\repository\repository\positions.cpp90我做错了什么? 最佳答案 相反,您可以尝试boost.lambd

c++ - 使用 boost 创建一个始终返回 true 的 lambda 函数

假设我有一个采用某种形式的谓词的函数:voidFoo(boost::functionpredicate);如果我想用一个始终返回true的谓词来调用它,我可以定义一个辅助函数:boolAlwaysTrue(int,int,int){returntrue;}...Foo(boost::bind(AlwaysTrue));但是有没有办法调用这个函数(可能使用boost::lambda)而不必定义一个单独的函数?[编辑:忘了说:我不能使用C++0x] 最佳答案 UncleBens在Scharron的回答中对此发表了评论,但我认为这实际上是

c++ - boost::bind 会导致开销吗?

我目前从事网络软件方面的工作。它有一个主类,server这显然代表一个服务器实例。Aserver实例可以发送请求,并通过回调通知用户响应。代码如下:classserver{public:typedefboost::functioncallback_func;voidsend_request(endpoint&ep,callback_funccb);};现在让我们说,作为一个用户,我想通过回调了解调用它的实例,我可以做以下事情:voidmycallback(constserver&sv,intduration){...}serversv;sv.send_request("localhos

c++ - 用 boost.python 包装结构列表

我有一个返回结构列表的C++函数。在结构内部,还有更多的结构列表。structCameraInfo{CamNamename;std::listlImgFormats;std::listlCamControls;};std::listgetCameraInfo(){std::listlCamerasInfo;//filllCamerasInforeturnlCamerasInfo;}然后为了导出它,我使用了:class_>("CameraNode",no_init).......def("listCameraInfo",make_function(&CameraNode::listCam

c++ - 使用 boost::tuple<bool, T> 来指示是否找到 T 是否好?

假设我们需要一个返回值的函数。但是那个东西是找不到的。我看到选项:1.Tfind(bool&ok);//returndefaultTvalueifnotfound我们可以创建一个结构体:templateclassCheckableValue{public:CheckableValue(),_hasValue(false){}CheckableValue(constT&t):_value(t),_hasValue(true){}inlineboolhasValue()const{return_hasValue}constT&value()const{assert(hasValue());

c++ - boost shared_ptr 运算符 =

这里是代码示例classA{inti;public:A(inti):i(i){}voidf(){prn(i);}};intmain(){A*pi=newA(9);A*pi2=newA(87);boost::shared_ptrspi(pi);boost::shared_ptrspi2(pi2);spi=spi2;spi->f();spi2->f();pi->f();pi2->f();}输出:8787087问题是为什么输出中是0?文档注释:效果:等同于shared_ptr(r).swap(*this)。但是如果shared_ptr对象刚刚交换,结果应该是9。如果第一个对象被删除,应该有S

c++ - boost::spirit::qi 对输出进行重复解析

我有一个使用Boost::Spirit的非常简单的解析器:rulezeroTo255=(string("25")>>char_('0','5'))|(char_('2')>>char_('0','4')>>digit)|(char_('1')>>repeat[2](digit))|(char_('1','9')>>digit)|digit;当我尝试解析时std::stringo{"1"};std::strings;parse(o.begin(),o.end(),zeroTo255,s);std::cout我有输出1:111我显然做错了什么,但是什么? 最佳答

c++ - 打印 boost 属性树生成的 xml

我测试了boost::property_tree,结果很好:我可以加载XML、提取元素、保存XML等。但是,是否可以生成XML并打印它?我不想保存它。voiddebug_settings::load(conststd::string&filename){usingboost::property_tree::ptree;ptreept;read_xml(filename,pt);m_file=pt.get("debug.filename");m_level=pt.get("debug.level",0);BOOST_FOREACH(ptree::value_type&v,pt.get_c

c++ - boost.pool 是如何实现分配内存的重用呢?

背景我的previousquestion关于boost.pool让我详细研究了boost.pool,现在我有一个补充问题来完成我的理解。序曲Thisreference声明以下关于对象池模式:Theobjectpoolpatternisasoftwarecreationaldesignpatternthatusesasetofinitializedobjectskeptreadytouse,ratherthanallocatinganddestroyingthemondemand.据我所知,boost.pool(简化版)通过主要基于element_type大小的内存分配和管理实现对象池模