草庐IT

boost-lambda

全部标签

c++ - boost 异步 tcp 客户端

我刚刚开始使用boost。我正在使用异步套接字编写TCP客户端-服务器。任务如下:客户端向服务器发送一个数字客户端可以在收到服务器的回答之前发送另一个数字。服务器收到一个数字,用它做一些计算并将结果发送回客户端。多个客户端可以连接到服务器。现在可以执行以下操作从客户端发送一个数字到服务器服务器在当前线程中接收到一个数字并在OnReceive处理程序中进行计算(我知道这很糟糕......但是我应该如何启动一个新线程来并行计算)服务器返回应答但客户端已经断开连接如何让客户端在键盘输入数字的同时等待服务器的响应?为什么我的客户端不等待服务器的响应?客户端代码:usingboost::asio

c++ - 如何在 boost (c++) 中将内存页锁定到物理 RAM?

对于需要将内存页锁定到物理内存中的实时C++应用程序,我正在处理boost中的共享内存对象。我没有看到在boost中执行此操作的方法。我觉得我错过了一些东西,因为我知道Windows和Linux都有这样做的方法(mlock()和VirtualLock())。 最佳答案 根据我的经验,最好编写一个小型跨平台库来为此提供必要的功能。当然,在内部会有一些#ifdef-s。类似这样的事情(假设GetPageSize和Align*已经实现):voidLockMemory(void*addr,size_tlen){#ifdefined(_uni

c++ - 编译器错误或非标准代码? - lambda 中的可变参数模板捕获

我有以下C++11代码;templateintg(T...t){return0;}templatevoidf(Args...args){autolm=[&,args...]{returng(args...);};lm();}intmain(){f(2,5,7);}我确实相信它是有效的C++11,根据;标准第5.1.2.23节;Acapturefollowedbyanellipsisisapackexpansion(14.5.3).[Example:templatevoidf(Args...args){autolm=[&,args...]{returng(args...);};lm();

C++ lambda : Access static method in lambda leads to error 'this was not captured for this lambda function'

考虑以下代码://thisiswhatIwanttocall;Icannotmodifyitssignaturevoidsome_library_method(void(*fp)(void));classSingleton{public:staticSingleton*instance();voidfoo();voidbar();private:Singleton();};voidSingleton::foo(){//thisleadstoanerror('this'wasnotcapturedforthislambdafunction)void(*func_pointer)(void

c++ - Boost Graph Library astar和导航网格

我在做一个项目SFML/C++,我需要生成一个图来连接它们之间的障碍物以方便寻路,所以我有兴趣生成一个导航网格,我将应用boostA*算法。有点像这样:但是我在使用BoostGraphLibrary实现它时遇到了很多问题(如果您有一个更合适的库,我很感兴趣)。首先,我创建一个具有适当结构的adjacency_list:structWayPoint{sf::Vector2fpos;};structWayPointConnection{floatdist;};typedefboost::adjacency_listWayPointGraph;typedefWayPointGraph::ve

c++ - 在 MacOS 10.9 (Mavericks) 上构建 Boost.Python 应用程序

我升级到Mavericks,现在在进行大量故障排除后无法构建我的应用程序。在链接期间,我收到错误Undefinedsymbolsforarchitecturex86_64:"boost::python::objects::function_object(boost::python::objects::py_functionconst&,std::pairconst&)..."boost::python::objects::register_dynamic_id_aux(boost::python::type_info,std::pair(*)(void*))"我正在使用来自macpor

c++ - 变量模板 + std::map 的通用 lambda

安answertoC++14VariableTemplates:whatisthepurpose?Anyusageexample?提出了一个变量模板+通用lambda的用法示例,看起来像这样:voidsome_func(){templatestd::mapstorage;autostore=[](intkey,constT&value){storage.insert(key,value)};store(0,2);store(1,"Hello"s);store(2,0.7);//Allthreevaluesarestoredinadifferentmap,accordingtotheir

c++ - 在 Boost.Log 中正确重载运算符 <<

在Boost.Logdocumentation,据说NoteThelibraryusesbasic_formatting_ostreamstreamtypeforrecordformatting,sowhencustomizingattributevalueformattingrulestheoperatormustusebasic_formatting_ostreaminsteadofstd::ostream.但是,在整个文档中,我所看到的只是重载operator在std::ostream而不是basic_formatting_ostream在示例代码中。例如,查看自定义类型的重载s

c++ - 如何使用 Cereal 序列化 boost::ptr_vector?

是否可以使用cereal序列化boost::ptr_vector实例?如果是,怎么办? 最佳答案 绝对有可能。您可以在存档和指针类型上创建外部save()和load()模板函数,如下所示:#include#include#include#include#include//Sampleserializableobject.structMyRecord{std::strings_;MyRecord(conststd::strings=std::string()):s_(s){}templatevoidserialize(Archive&

c++ - 如何简化 boost 变体的加号 Action ?

我有boost变体类型定义:typedefboost::variantVariantType;我想对其执行加/减/乘/除操作。以添加类为例。问题是如果向VariantType添加新类型,例如std::string,则必须使用新类型更新Add类。structAdd:publicboost::static_visitor{templateToperator()(Ta,Tb)const{returna+b;}floatoperator()(inta,floatb)const{returna+b;}floatoperator()(floata,intb)const{returna+b;}dou