草庐IT

boost_thread

全部标签

c++ - boost::lexical_cast<> 的语言环境不变保证

我正在使用boost::lexical_cast(double)用于将double转换为字符串,生成JSON序列化字节流,即(在远程端)由.NET解析。我能够强制.NET使用InvariantCulture用于解析,从而在每种可能的语言上返回可预测的结果。但是,我无法在boost::lexical_cast中找到此保证文档。我试了一下,对于不同的区域设置,它的工作方式相同。但是,我不能仅从几个测试中确定,我是否遗漏了文档中的某些内容,或者根本无法保证这一点,我必须使用其他东西吗?编辑:我发现了一个问题。std::locale::global(std::locale("Czech"));

c++ - 了解 Boost.spirit 的字符串解析器

#include#includenamespaceqi=boost::spirit::qi;intmain(){usingqi::string;std::stringinput("a");std::string::iteratorstrbegin=input.begin();std::stringp;boolok=qi::phrase_parse(strbegin,input.end(),((string("a")>>string("a"))|string("a")),qi::space,p);if(ok&&strbegin==input.end()){std::cout这个程序输出a

c++ - 防止 Boost Spirit Symbol 解析器过早接受关键字

当以有效关键字(符号)开头时,如何防止BoostSpirit符号解析器接受关键字(符号)。我希望该构造无法将“ONEMORE”作为一个整体进行解析,并且无法成功解析“ONE”,因为这是一个有效的关键字,然后在“MORE”上失败。下面是代码的实际输出:Keywordasanumber:1Keywordasanumber:2Keywordasanumber:1Invalidkeyword:MORETHREE这就是我喜欢的样子:Keywordasanumber:1Keywordasanumber:2Invalidkeyword:ONEMOREKeywordasanumber:3该代码只是一个

c++ - boost 正则表达式 : [:alpha:] and accented characters

我正在尝试使用Boost将字符串中的每个非字母字符替换为"":std::stringsanitize(std::string&str){boost::regexre;re.imbue(std::locale("fr_FR.UTF-8"));re.assign("[^[:alpha:]]");str=boost::regex_replace(str,re,"");returnstr;}intmain(){std::stringtest="(ça)/.2424,@vatrèsbien?";cout结果是avatrsbien但我想得到çavatrèsbien。我错过了什么?

c++ - Boost 记录器追加到文件

我已经初始化了记录到文件的接收器:logging::add_file_log(keywords::file_name="sample_%N.log",/**/keywords::rotation_size=10*1024*1024,/**/keywords::time_based_rotation=sinks::file::rotation_at_time_point(0,0,0),/**/keywords::format="[%TimeStamp%]:%Message%",/**/keywords::auto_flush=true);它看起来在程序重新启动期间重写了文件。如何让它附加

c++ - 如何在获得 future 值(value)后重用 boost::promise 对象?

voidsss(boost::promise&res){res.set_value("hi");}voidyyy(boost::promise&res){res.set_value("hello");}intmain(){boost::threadth;boost::promisea;th=boost::thread(sss,boost::ref(a));th.join();std::cout我收到promise已经满足的错误。如何复用同一个Promise对象? 最佳答案 用未使用的promise替换它:a=boost::promi

c++ - 对 std/boost 移动的模糊调用

遇到无法编译的代码:#include#include#include#include#include#includeusingnamespacestd;intmain(){typedefstd::pair>FirstPair;typedefstd::vectorVectorFirstPair;typedefstd::pairSecondPair;typedefstd::mapMap;MapmapInstance;SecondPairnewElement=make_pair(boost::posix_time::not_a_date_time,VectorFirstPair());map

c++ - 打印 std::this_thread::get_id() 给出 "thread::id of a non-executing thread"?

这曾经工作得很好(然后外星人一定黑了我的电脑):#include#includeintmain(){std::cout现在它打印thread::idofanon-executingthread。ideone.com打印了一些ID,但有趣的是是什么导致了我平台上的这种行为。$uname-aLinuxxxx3.13.0-77-generic#121-UbuntuSMPWedJan2010:50:42UTC2016x86_64x86_64x86_64GNU/Linux有什么想法吗?编辑:嗯..当我添加std::cout两行打印相同的ID,但是当我删除它时,结果仍然相同-“非执行线程”。

c++ - 为什么 std::thread 通过转发引用接受仿函数

为什么std::thread对象通过转发引用接受函数参数,然后使用decay_copy复制对象?只按值接受函数对象不是更容易吗?一般来说,为什么不对函数进行模板化以便按值获取函数对象?引用性不能用reference_wrapper来模仿吗(这会更明确,并且还方便地有一个成员operator()来调用存储的函数)? 最佳答案 Whydoesastd::threadobjectacceptthefunctionparameterbyforwardingreferenceandthenmakeacopyoftheobjectwithdec

c++ - 与 std::condition_variable 相比,使用 std::atomic 的方法 wrt 在 C++ 中暂停和恢复 std::thread

这是一个单独的问题,但与我之前提出的问题有关here我正在使用std::thread在我的C++不断轮询某些数据并将其添加到缓冲区的代码。我用C++lambda像这样启动线程:StartMyThread(){thread_running=true;the_thread=std::thread{[this]{while(thread_running){GetData();}}};}thread_running是一个atomic在类头中声明。这是我的GetData功能:GetData(){//Someheavylogic}接下来我还有一个StopMyThread我设置的功能thread_r