草庐IT

boost-thread

全部标签

c# - 是否有相当于 C# TryParse 的 boost lexical_cast?

简介(来自EricLippert博客):Vexingexceptionsaretheresultofunfortunatedesigndecisions.Vexingexceptionsarethrowninacompletelynon-exceptionalcircumstance,andthereforemustbecaughtandhandledallthetime.TheclassicexampleofavexingexceptionisInt32.Parse,whichthrowsifyougiveitastringthatcannotbeparsedasaninteger.

c++ - 这种情况下有什么样的多线程保护?

我使用的是C++,我使用的是boost库mutex、recursive_mutex和其他同步对象。我经常有以下模式:无效RebuildAll()。此功能进行了许多内部更改。无效DoSomethingA()。使用RebuildAll构建的内容做一些工作。无效DoSomethingB()。使用RebuildAll构建的内容做一些工作。无效DoSomethingC()。使用RebuildAll构建的内容做一些工作。...可以从不同的线程调用函数。我希望能够并行执行DoSomethingA()、DoSomethingB()和DoSomethingC()。但是当调用RebuildAll()时,我

c++ - 如何正确退出可能正在等待 std::condition_variable 的 std::thread?

我有一个类使用互斥锁和两个条件变量实现线程化生产者/消费者系统以进行同步。当有元素要使用时,生产者向消费者线程发出信号,而消费者在消费完元素时向生产者线程发出信号。线程继续生产和消费,直到析构函数通过设置bool变量请求它们退出。因为任何一个线程都可能在等待条件变量,所以我必须对quit变量进行第二次检查,这感觉不对而且很乱......我已将问题简化为以下(使用g++4.7在GNU/Linux上工作)示例://C++11andBoostrequired.#include//std::rand()#include#include#include#include#include#inclu

c++ - boost ptr_map 替换值

给定一个键,我试图替换一个值。对于不使用指针的常规映射,我只是使用了以下调用iter->second=object;//Whereobjectwaspassedinbyreference如何使用boost::ptr_map实现同样的效果?这里的概念是我们用derived_object替换整个类iter->second=derived_object;//derived_objectisabase_objectpointer 最佳答案 这样就可以了:the_map.replace(iter,derived_object);当然在哪里,t

c++ - 如何在没有boost的情况下在C++03中实现一个通用的回调机制?

我有一个http服务器,它有一个像这样的请求处理程序:boolhandleRequest(constRequestObject&request,ResponseRequest&response);我正在尝试编写一个包装器来提供这样的API:addRouteHandler(GET,"/foo/bar",handler);使用handler可以是:一个函数:boolhandleFooBarRequest(constRequestObject&request,ResponseRequest&response);现有对象的方法:FooResourceInstance+boolFooResour

c++ - boost::spirit:语义 Action block 中的多个语句

boost::phoenix使用运算符“,”定义语句block(参见boostphoenixblockstatements)。我试图在boost::spirit规则的语义Action部分使用这个构造。但是,看起来只执行了语句block中的最后一条语句。这是一个显示问题的最小可编译示例:#include#include#include#include#include#include#include#includeintmain(){usingboost::spirit::qi::int_;usingboost::phoenix::ref;usingboost::spirit::qi::p

c++ - GCC 4.7.2:带有指向成员函数指针的 std::thread

正在为thisquestion写测试代码我发现下面的注释行无法在GCC4.7.2上编译:#include#includestructS{voidf(){std::cout但cppreference似乎声称“this”参数可以等效地作为对象、对象引用或对象指针传递:IffispointertoamemberfunctionofclassT,thenitiscalled.Thereturnvalueisignored.Effectively,thefollowingcodeisexecuted:(t1.*f)(t2,...,tN)ifthetypeoft1iseitherT,referen

c++ - 转换 std::vector 为 boost::variant 类型

我如何实现下面的函数来从Value的vector进行转换?到Container?如果不是values的所有成员,我想断言是同一类型,即如果vector包含字符串和整数的混合。这是因为函数的返回值是std::vector。或std::vector.typedefboost::variantValue;typedefboost::variant,std::vector>Container;ContainervaluesToContainer(conststd::vector&values){returnContainer();} 最佳答案

C++:如何使用 boost::range 查找 max_element?

我正在尝试将迭代器返回到过滤范围内的最大元素。这是我目前所拥有的:#include#include#include#include#includeusingnamespaceboost::adaptors;usingnamespaceboost::lambda;usingnamespacestd;intmain(){vectorx={100,150,200,110};autoit=boost::max_element(x|indexed(0)|filtered(_1>100));/*problemhere*/cout我希望代码打印出vectorx中具有最大元素(即2)的索引,但不幸的是

c++ - BOOST_FUSION_ADAPT_TPL_STRUCT 和模板数组大小

由于BOOST_FUSION_ADAPT_TPL_STRUCT,我正在尝试迭代C++模板结构.我的结构包含固定大小的多维数组,其大小是模板参数。如果我们考虑修改Boost的示例以解决我的问题:#include#include#include#include//Example://http://www.boost.org/doc/libs/1_53_0/libs/fusion/doc/html/fusion/adapted/adapt_tpl_struct.htmlnamespacedemo{templatestructemployee{Namename;Ageage;Tar[SIZE1