boost-phoenix

Static functions from boost.lambda or boost.phoenix

跟風遠走 提交于 2019-12-01 16:22:02
I regularly use boost.lambda (and phoenix) to define lambda functions in C++. I really like their polymorphic property, the simplicity of their representation and the way they make functional programming in C++ so much easier. In some cases, it's even cleaner and more readable (if you're used to reading them) to use them for defining small functions and naming them in the static scope. The way to store these functionals that resembles conventional functions the most is to capture them in a boost::function const boost::function<double(double,double)> add = _1+_2; But the problem is the runtime

What are the benefits of using Boost.Phoenix?

允我心安 提交于 2019-11-30 08:43:47
I can not understand what the real benefits of using Boost.Phoenix. When I use it with Boost.Spirit grammars, it's really useful: double_[ boost::phoenix::push_back( boost::phoenix::ref( v ), _1 ) ] When I use it for lambda functions, it's also useful and elegant: boost::range::for_each( my_string, if_ ( '\\' == arg1 ) [ arg1 = '/' ] ); But what are the benefits of everything else in this library? The documentation says: "Functors everywhere". I don't understand what is the good of it? I'll point you out what is the critical difference between Boost.Lambda and Boost.Phoenix: Boost.Phoenix

Functional data structures in C++

萝らか妹 提交于 2019-11-28 20:25:34
Does anyone know of a C++ data structure library providing functional (a.k.a. immutable, or "persistent" in the FP sense) equivalents of the familiar STL structures? By "functional" I mean that the objects themselves are immutable, while modifications to those objects return new objects sharing the same internals as the parent object where appropriate. Ideally, such a library would resemble STL, and would work well with Boost.Phoenix (caveat- I haven't actually used Phoenix, but as far as I can tell it provides many algorithms but no data structures, unless a lazily-computed change to an

Boost spirit revert parsing

陌路散爱 提交于 2019-11-28 14:27:32
I want to parse a file containing the following structure: some garbage *&% section1 { section_content } section2 { section_content } The rule parsing section_name1 { ... } section_name2 { ... } is already defined: section_name_rule = lexeme[+char_("A-Za-z0-9_")]; section = section_name_rule > lit("{") > /*some complicated things*/... > lit("}"); sections %= +section; So I need to skip any garbage until the sections rule is met. Is there any way to accomplish this? I have tried seek[sections] , but it seems not to work. EDIT : I localized the reason why seek is not working: if I use follows

Boost::Spirit Expression Parser

走远了吗. 提交于 2019-11-27 08:44:17
I have another problem with my boost::spirit parser. template<typename Iterator> struct expression: qi::grammar<Iterator, ast::expression(), ascii::space_type> { expression() : expression::base_type(expr) { number %= lexeme[double_]; varname %= lexeme[alpha >> *(alnum | '_')]; binop = (expr >> '+' >> expr)[_val = construct<ast::binary_op<ast::add>>(_1,_2)] | (expr >> '-' >> expr)[_val = construct<ast::binary_op<ast::sub>>(_1,_2)] | (expr >> '*' >> expr)[_val = construct<ast::binary_op<ast::mul>>(_1,_2)] | (expr >> '/' >> expr)[_val = construct<ast::binary_op<ast::div>>(_1,_2)] ; expr %= number

Boost spirit revert parsing

痞子三分冷 提交于 2019-11-27 08:37:22
问题 I want to parse a file containing the following structure: some garbage *&% section1 { section_content } section2 { section_content } The rule parsing section_name1 { ... } section_name2 { ... } is already defined: section_name_rule = lexeme[+char_("A-Za-z0-9_")]; section = section_name_rule > lit("{") > /*some complicated things*/... > lit("}"); sections %= +section; So I need to skip any garbage until the sections rule is met. Is there any way to accomplish this? I have tried seek[sections]

Boost.Spirit.Qi: dynamically create “difference” parser at parse time

家住魔仙堡 提交于 2019-11-27 06:29:49
问题 A "difference" parser can be created by the binary - (minus) operator: rule = qi::char_ - qi::lit("}}") or even compound differences: rule = qi::char_ - qi::lit("}}") - qi::lit("]]") But how could I generate the whole result of the difference parser at the parse time? I'm guessing it might be some kind of form like below: phoenix::function<difference_parser_impl> difference_parser; rule = qi::lazy(difference_parser(qi::char_, {"}}", "]]"})); Here, the {..., ..., ...} part would actually be a