boost-phoenix

How can I make std::find_if and std::map work together using some boost library?

雨燕双飞 提交于 2019-12-21 13:07:44
问题 This question is inspired from another topic which poses this question: Find the first value greater than user specified value from a map container which can be solved in several ways. A typical C++03 solution defines a dedicated function (or functor) and pass it to std::find_if as third argument. In C++11, one can avoid defining a dedicated function (or functor), and can instead make use of lambda as: auto it = std:: find_if(m.begin(), mp.end(), [n](const std::pair<std::string, int> & x) ->

Static functions from boost.lambda or boost.phoenix

荒凉一梦 提交于 2019-12-19 16:47:32
问题 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

how to create boost phoenix make_shared?

狂风中的少年 提交于 2019-12-19 08:14:24
问题 Is it possible to create boost phoenix lazy variant of std::make_shared ? I mean, to make possible something like namespace p = boost::phoenix; ... expr = custom_parser[_a=p::make_shared<Node>(_1,_2,_3)] >> ... One cannot use BOOST_PHOENIX_ADAPT_FUNCTION because of variadic template nature of std::make_shared . So, probably wrapper should be variadic template itself, if it is possible to write one. 回答1: If you can spare an extra set of parentheses: namespace { template <typename T> struct

What are the benefits of using Boost.Phoenix?

前提是你 提交于 2019-12-18 13:01:44
问题 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? 回答1: I

How to implement a lambda function for a sort algorithm involving object members, indirection, and casting?

可紊 提交于 2019-12-18 07:02:53
问题 I'm working on some code and I have a section where I do a one off sort function. To implement it I decided it was easiest to overload the operator< function. What I would prefer to do is move the implementation of the sort closer to the actual call by using some sort of boost::bind, boost::phoenix, lambda or some other type of implementation. Unfortunately I don't have access to new C++11 functionality. Below is some example code. // In a header struct foo { char * a; char * c_str() { return

Functional data structures in C++

蹲街弑〆低调 提交于 2019-12-17 23:32:23
问题 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

Boost::Spirit Expression Parser

天涯浪子 提交于 2019-12-17 09:45:20
问题 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:

When is boost phoenix useful? [duplicate]

时光总嘲笑我的痴心妄想 提交于 2019-12-12 08:19:31
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: What are the benefits of using Boost.Phoenix? So I started reading the documentation for boost phoenix. However, I must admit that I don't quite understand the purpose of the library, especially since we have language support for lambdas in C++0x. Could someone please explain or give me an example? 回答1: Well, not all C++ compilers support C++0x for a start. Then there are some things that are not possible with C

Boost.spirit: parsing number char and string

∥☆過路亽.° 提交于 2019-12-10 22:22:48
问题 I need to parse a line containing an unsigned int, the character X that is to be discarded, and a string, all separated by one or more spaces. e.g., 1234 X abcd bool a = qi::phrase_parse(first, last, uint_[ref(num) = _1] >> lit('X') >> lexeme[+(char_ - ' ')], space, parsed_str); The above code parses the three parts, but the string ends up containing a junk character ( �abcd ) and having a size of 5 and not 4. What is wrong with my parser? and why is there junk in the string? 回答1: What you

Subscript operator[] error with Boost C++ Phoenix user-defined argument

女生的网名这么多〃 提交于 2019-12-10 19:56:59
问题 With an existing Boost Phoenix (placeholder) argument, such as _1 , I can use the array/subscript operator. For example, the following excerpt will display a 1 . int arr[4] = {1,2,3,4}; std::cout << _1[0](arr) << std::endl; However, if I define my own placeholder argument: phoenix::actor<phoenix::expression::argument<1>::type> const my_1 = {{}}; though it works fine unadorned (the following outputs a 7): std::cout << my_1(7) << std::endl; if I attempt to use the subscript operator (as above):