草庐IT

BOOST-ASIO

全部标签

c++ - 我可以将 Boost Phoenix 表达式字符串化吗?

我可以将一个BoostPhoenix表达式转换成一个具有代表性的C++字符串吗?我可以:stringify(_1然后可能会生成一个包含类似以下内容的字符串:templatestructfoo{autooperator()(T1x1,T2x2)->decltype(x1我很欣赏这个例子有一些粗糙的边缘,但我想知道是否有人尝试过这些方面的任何事情? 最佳答案 使用您可以找到的转换evalhere作为“灵感”。Liveexample.#include#include#include#include#include#includenames

c++ - 比使用流保存 boost 随机生成器状态更快的替代方法

我需要能够保存/加载此boost随机生成器的状态:boost::variate_generator>generator;我是这样做的:std::ostringstreamcontent;contentgenerator.engine();问题是,这非常慢,难道没有其他方法来存储它吗?(或以native格式访问随机生成器数据)。这段代码封装在我们的RandomGenerator类中,所以它可能有点讨厌。 最佳答案 一些方法,都非常hacky:只需使用如下方式获取原始字节:typedeftypenamestd::aligned_stor

c++ - 努力获得 boost 共享内存段来构建

我有一些代码正在尝试创建一个共享内存段。为此,该段是从一个类中管理的。共享部分将以“公告板”方式使用。也就是说,这个进程将写入它,而许多其他进程将从中读取。事不宜迟:#include#include#includestaticconststd::stringSHM_NAME("SharedMemory");staticconststd::stringSHM_STATUS("StatusArray");staticconststd::stringSHM_INFO1("MfgData");classManager{u_int8_t*_status;char*_info;boost::int

C++11 替代 boost::checked_delete

作为前向声明的重度用户,我喜欢我的类在销毁时完成。为确保这一点,我将析构函数设为私有(private)并与boost::checked_delete成为friend:#includestructMyClass{//MyClass'sinterfaceprivate:~MyClass(){/*something*/}friendvoidboost::checked_delete(MyClass*x);};在C++11中,std::default_delete还在销毁时检查完整性。然而,我无法实现与上面相同的行为:#includestructMyClass{//MyClass'sinter

c++ - 在非 boost 线程中使用 boost::thread_specific_ptr

我正在阅读thedocumentationsectionforboost::thread_specific_ptr,并尝试解析这段:Note:onsomeplatforms,cleanupofthread-specificdataisnotperformedforthreadscreatedwiththeplatform'snativeAPI.Onthoseplatformssuchcleanupisonlydoneforthreadsthatarestartedwithboost::threadunlessboost::on_thread_exit()iscalledmanually

c++ - boost 单位的平方根 scaled_unit

我使用boost::units来处理项目中的单元。我创建了一个缩放单位来存储微米:usingnamespaceboost::units;typedefmake_scaled_unit>>::typemicro_meter_unit;一切如期进行:quantitysome_meter=10*si::meter;quantitysome_mu_meter=static_cast>(some_meter);std::cout但是平方根运算没有被编译:std::cout'beingcompiled//with//[//X=boost::units::quantity,//Y=boost::un

c++ - boost线程库的型号是什么

c++boost线程库使用的线程模型是什么?1:1(内核级线程)N:1(用户级线程)M:N(混合线程)这些模型之间的区别(来自wiki):http://en.wikipedia.org/wiki/Thread_(computing)#Models我检查了boost站点,它没有提到它使用的线程模型。我猜是1:1,因为它没有提供yield或reschedule之类的功能,但我不确定... 最佳答案 它是native线程,即它会使用平台线程,至少在Linux、Windows和Mac中是这样。据我所知,对于每个生成的线程,线程映射将与Win

c++ - 使用 Boost 就地替换正则表达式

我有一大段文本存储在名为“text”的std::string中。在这个字符串上,我使用boostregex库将某些模式替换为空格。这是我的代码。//Removetimesoftheform(00:33)and(1:33)boost::regexrgx("\\([0-9.:]*\\)");text=boost::regex_replace(text,rgx,"");//RemovesinglewordHTMLtagsrgx.set_expression("");text=boost::regex_replace(text,rgx,"");//Removecommentslike[paus

c++ 内存泄漏 - boost 库

我在以下程序中观察到内存泄漏://g++-std=c++1132_MyTime.cpp////valgrind--leak-check=full./a.out//#include#includeusingnamespacestd;classMyTime{private:intyear;intmonth;intday;inthour;boost::posix_time::ptime*ptrTime;voidupdate(){year=ptrTime->date().year();month=ptrTime->date().month();day=ptrTime->date().day()

c++ - 与 static_assert 和 boost::hana 相关的 Clang 编译错误

考虑以下使用-std=c++14在Clang3.8上成功编译的问题。#includenamespacehana=boost::hana;intmain(){constexprautoindices=hana::range();hana::for_each(indices,[&](autoi){hana::for_each(indices,[&](autoj){constexprbooltest=(i==(j==i?j:i));static_assert(test,"error");});});}这个测试非常荒谬,但这不是重点。现在考虑一个替代版本,其中测试直接放在static_asse