草庐IT

boost-lambda

全部标签

c++ - Lambda 表达式作为类属性?

是否可以使用lambda表达式作为类属性?我正在用C++开发一个小游戏,其中所有机器人都有相同的更新例程,但每个人都应该有自己的可选额外更新例程。我是这么想的classBot{private:Lambdatypelambda;public:Bot(Lambdal){lambda=l;}update(){dosomething();lambda();}}; 最佳答案 您可以使用std::function,例如假设它是void函数并获得两个int:classBot{private:usingLambda=std::function;La

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

c++ - 使用具有不同编译器版本的 boost 库

我用gcc版本4.6.3(在3.2.0-29-generic#46-Ubuntu中)编译了boost1.54。然后,我使用这个boost库开发了我的库。由于我不想每次更改我的库时都重新编译boost,所以我将已编译的boost静态库添加到我的git存储库中。现在,我正在尝试在具有不同版本编译器的不同机器上编译我的库(尝试使用gcc4.4和gcc4.7)。我的库编译正常,但在链接时打印以下错误。`.text._ZN5boost16exception_detail10bad_alloc_D2Ev'referencedinsection`.text._ZN5boost16exception_

C++ lambda 函数访问写冲突

我正在学习如何将C++lambda函数与一起使用的function类(class)。我正在尝试解决这个CodeGolf作为练习(挑战是晚餐吃curry)我有这个功能://Thiscreatesafunctionthatrunsyanumberof//timesequaltox'sreturnvalue.functionCurry(functionx,functiony){return[&](){for(inti=0;i为了测试这个,我在我的main()中有这段代码:autox=[](){return8;};autoy=[](){cout这会抛出Accessviolationreadin

c++ - Qt 连接功能 - 使用 lambda 进行信号消歧

这个问题在这里已经有了答案:ConnectingoverloadedsignalsandslotsinQt5(4个答案)关闭6年前。我正在使用c++11连接语法,并通过此连接语句得到以下错误:connect(fileSystemCompleter,&QCompleter::activated,[&](QModelIndexindex){fileSystemPathEdit->setFocus(Qt::PopupFocusReason);});错误:errorC2664:'QMetaObject::ConnectionQObject::connect(constQObject*,cons

c++ - Qt 信号 lambda 导致 shared_ptr 泄漏?

我有以下代码:#include#include#include#includeclassDocument{public:Document(){qDebug("Document");}~Document(){qDebug("~Document");}QUndoStackmUndostack;};classDocumentRepository{public:DocumentRepository(){qDebug("DocumentRepository");}~DocumentRepository(){qDebug("~DocumentRepository");}voidAddDoc(std

c++ - boost::lexical_cast 无法识别重载的 istream 运算符

我有以下代码:#include#includestructvec2_t{floatx;floaty;};std::istream&operator>>(std::istream&istream,vec2_t&v){istream>>v.x>>v.y;returnistream;}intmain(){autov=boost::lexical_cast("1231.2152.9");std::cout我从Boost收到以下编译错误:Error1errorC2338:Targettypeisneitherstd::istreamablenorstd::wistreamable这看起来很简单,

c++ - boost 记录器刷新到文件

在执行每个日志记录代码行后,我需要boost日志记录。是否有可能以某种方式配置接收器以这种方式运行?目前日志是在程序结束后立即填充的。#include#include#include#include#include#include#include#include#include;namespacelogging=boost::log;namespacesrc=boost::log::sources;namespacesinks=boost::log::sinks;namespacekeywords=boost::log::keywords;voidinit(){logging::add

c++ - boost::optional 和类型转换

我想知道是否有一种优雅的方式来转换boost::optional到boost::optional什么时候B可以从A构建,尽管是明确的。这有效:#includeclassFoo{inti_;public:explicitFoo(inti):i_(i){}};intmain(){boost::optionali;...//igetsinitializedornotboost::optionalfoo;foo=boost::optional(bool(i),Foo(i.value_or(0/*unusedvalue*/)));return0;}但是需要将一些永远不会被使用的值放在那里似乎很尴