草庐IT

BOOST_STRINGIZE

全部标签

c++ - 为 boost::program_options 设置精度

有没有办法改变boost::program_options在program_options::options_description的帮助文本中格式化选项的默认值的方式?(那个可以通过cout得到)?特别是我有默认值是float,所以通常的十进制到二进制转换给我一个看起来像--arg(0.100000001)的帮助文本。这是非常丑陋的。使用cout不起作用,因为program_options是将自身设置为某些内部流的默认值以首先进行格式化(至少这是我通过查看源代码推断的),然后得到的结果。编到cout是结果字符串(流?)。谢谢。 最佳答案

c++ - 生成巨大的 Boost.MPL 类型序列

考虑以下自动生成Boost.MPL类型序列(列表或vector)的代码。#include//cout#include//for_each#include//identity,make_identity#include//int_#include//list#include//next#include//push_front#include//vectortemplatestructiota_n;templatestructiota_n:boost::mpl::list//canchangethistoboost::mpl::vector{};templatestructiota_n:b

c++ - Boost::Spirit 中的复合语法

我有以下语法,它按预期工作。structquery_term{std::stringterm;boolis_tag;query_term(conststd::string&a,booltag=false):term(a),is_tag(tag){}};templatestructquery_grammar:grammar(),space_type>{query_grammar():query_grammar::base_type(query){word%=+alnum;tag=(omit[word>>':']>>word[_val=phoenix::construct(_1,true)

c++ - 适当使用 boost::shared_ptr?

关于boost::shared_ptr的问题:我有3个类(class)。A是某种负责管理一切的主类。B是一个类,它只具有完成某些工作的功能。Dispatcher只是一个围绕单独线程的类,它从B的Instaces中获取工作,在此线程中完成。所以它有点像这样工作:A有一个Dispatcher实例。现在,A偶尔会生成一个B的实例,并将其传递给调度程序。重要的是,B在完成后需要调用A::callback()。这就是为什么B在其构造函数中获取对A的引用(参见下面的代码)A.hppclassA:publicboost::enable_shared_from_this{public:A();void

c++ - 使用函数 <void (boost::any)> 的事件系统是个好主意?

我做过一个模块系统,是这样的://settingeventmodule->set_event("started",[](boost::anyev){coutstart();//implvoidModule::start(){//runonceprotectionherethis->trigger_event("start");//prestartthis->_impl->start();//onerror,throwexceptionthis->trigger_event("started");//poststart}voidModule::trigger_event(stringst

c++ - 多处理器 boost::线程?在一个处理器上运行的所有线程

我有一个令人尴尬的并行问题,我想在多个处理器上执行。我原以为boost::thread会自动将新线程发送到新处理器,但它们都在与父进程相同的内核上执行。是否可以让每个线程在不同的处理器上运行,或者我是否需要MPI之类的东西?我怀疑boost::thread根本不是多处理器工具,我要求它做一些不是为它设计的。编辑:我的问题归结为:为什么所有线程都在一个处理器上执行?有没有办法让boost::thread将线程发送到不同的处理器?这是我的代码的相关示例:size_tlim=1000;std::dequevals(lim);std::dequethreads;inti=0;std::dequ

c++ - boost::spirit::qi Expectation Parser 和分组意外行为的解析器

我希望有人可以通过我对使用>的无知来点亮。和>>spirit解析中的运算符。我有一个工作语法,顶级规则看起来像test=identifier>>operationRule>>repeat(1,3)[any_string]>>arrow>>any_string>>conditionRule;它依靠属性自动将解析后的值分配给适合fusion的结构(即boost元组)。但是,我知道一旦我们匹配了operationRule,我们必须继续或失败(即我们不想让回溯尝试其他以identifier开头的规则)。test=identifier>>operationRule>repeat(1,3)[any

c++ - 如何将 boost::spirit::lex token 的值从 iterator_range 转换为字符串?

当我尝试从iterator_range转换标记的值时,词法分析器在尝试读取下一个标记时失败。这是包含token定义的token结构:(我不认为这是相关的,但我包括以防万一。)templatestructTokens:boost::spirit::lex::lexer{Tokens();boost::spirit::lex::token_defidentifier;boost::spirit::lex::token_defstring;boost::spirit::lex::token_defboolean;boost::spirit::lex::token_defreal;boost:

c++ - 如何使用 boost::spirit 将文本解析为结构?

我在学习boost::spirit,我正在尝试读取一些文本并将其解析为一个结构。例如,"2:4.6"被解析为int2和双4.6在我的TestStruct下面:#include#include#include#includenamespaceqi=boost::spirit::qi;structTestStruct{intmyint;doublemydouble;TestStruct(){}TestStruct(std::pairp):myint(p.first),mydouble(p.second){}};templatestructMyGrammar:qi::grammar{MyGr

c++ - boost::unordered_map 中的迭代器失效

我正在使用boost::unordered_map如下typedefboost::shared_ptrPtrWriter;typedefstd::listPtrList;boost::unordered_map,PtrList>MapMapinstrMap;现在我正在循环中对PtrList类型的列表进行一些更改for(autoit=instrMap.begin();it!=instrMap.end();++it){autokey=it->first();autolist&=it->second();//Makesomechangetoanelementinlistif(list.emp