boost-phoenix

Post callbacks to a task queue using boost::bind

血红的双手。 提交于 2021-01-27 10:41:53
问题 Suppose I have a function called subscribe() that takes a callback handler, which will be called when the event is triggered. Now, I have another version, called subscribe2() . Everything is the same except that, when triggered, it needs to post it to an event queue. It is implemented using the original subscribe() , with a helper funciton called helper() . All it does is to bind the original handler and whatever additional arguments into a functor, and call postToEventQueue() . Now, I wonder

Post callbacks to a task queue using boost::bind

倾然丶 夕夏残阳落幕 提交于 2021-01-27 10:40:35
问题 Suppose I have a function called subscribe() that takes a callback handler, which will be called when the event is triggered. Now, I have another version, called subscribe2() . Everything is the same except that, when triggered, it needs to post it to an event queue. It is implemented using the original subscribe() , with a helper funciton called helper() . All it does is to bind the original handler and whatever additional arguments into a functor, and call postToEventQueue() . Now, I wonder

Simple expression with boost::spirit

寵の児 提交于 2020-02-25 05:13:46
问题 I need to parse simple_expression ::= limit int_number (days | hours | minutes) . I wrote code for grammar struct Parser: grammar<std::string::const_iterator, boost::spirit::ascii::space_type> { public: Parser(ConditionTree& a_lTree): Parser::base_type(limit_expression), m_lTree(a_lTree) { using boost::spirit::qi::uint_; using boost::spirit::qi::_1; using boost::spirit::qi::_2; limit_expression = limit_days_operator | limit_hours_operator | limit_minutes_operator ; limit_days_operator = (

Binding a pretty-printer to boost::phoenix actors when iterating with boost::fusion

时间秒杀一切 提交于 2020-01-06 04:09:27
问题 This question is a follow-up to Pointers to class members when iterating with boost::fusion, where the accepted solution works. Now, I want not only to add the (primitive) values to the property-map, but use a pretty-printer to improve how the values are displayed. This mechanism will also be used in case the values are not trivial to print. So, there is some pretty-printer like this: template<typename T> std::string prettyPrinter(const T& t); template<> std::string prettyPrinter(const std:

Transforming a Boost C++ Phoenix Expression Tree

99封情书 提交于 2020-01-02 04:40:09
问题 In the Boost Phoenix article, "Transforming the Expression Tree", here, a set of specialisations of a custom invert_actions class, are used to invert binary arithmetic expressions. For example a+b becomes a-b ; a*b becomes a/b ; and vice versa for both. This involves a recursive traversal of the expression tree - however, this traversal stops when an expression involving an operator not explicitly handled is encountered. For example, _1+_2-_3 will become _1-_2+_3 , but _1+_1&_2 will stay as

Problems adapting member functions in Phoenix

若如初见. 提交于 2019-12-24 10:45:02
问题 I use BOOST_PHOENIX_ADAPT_FUNCTION all the time in Spirit. I'd like to be able to adapt member functions for all of the same reason. However, I get compile errors if I do something like this: struct A { int foo(int i) { return 5*i; }}; BOOST_PHOENIX_ADAPT_FUNCTION(int, AFoo, &A::foo, 2) Is there an easy way to adapt a member function? Note that I can't just store a bind expression in an auto because I am on VC2008. How come it doesn't just work like in bind and function ? Thanks, Mike 回答1:

Boost spirit semantic action not invoked

痴心易碎 提交于 2019-12-24 04:27:10
问题 I've been trying to parse a string with Boost Spirit like following: integer_count int1 int2 int3 ... intN Where N is the integer_count. For example, 5 1 2 3 4 5 The code is following: #define BOOST_SPIRIT_USE_PHOENIX_V3 #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix.hpp> #include <string> namespace qi = boost::spirit::qi; namespace spirit = boost::spirit; namespace ascii = boost::spirit::ascii; using boost::phoenix::ref; template <typename Iterator> struct x

Boost Phoenix (or Boost Lambda) - taking a pointer lazily

青春壹個敷衍的年華 提交于 2019-12-23 19:43:03
问题 Is there a way of taking a pointer of a lazy phoenix value / ref ? If so how ? 回答1: Phoenix placeholders overload operator&() , therefore a simple &_1 should do the trick (see Phoenix docs here). 来源: https://stackoverflow.com/questions/5211894/boost-phoenix-or-boost-lambda-taking-a-pointer-lazily

qi::rule with inherited attribute as inherited attribute

混江龙づ霸主 提交于 2019-12-22 18:43:20
问题 Let's say we have a rule1 qi::rule<std::string::iterator, int()> rule1 = qi::int_[qi::_val=qi::_1]; And we decide getting an int as attribute is not enough, we also want to get the raw data (boost::iterator_range). We may have a lot of rules with the same type as rule1. So it's better to have a generic solution for this. Therefore we could define another rule2. qi::rule< std::string::iterator, std::pair<int, boost::iterator_range<std::string::iterator>>( qi::rule<std::string::iterator, int()>

What is the difference between Boost::bind and Boost Phoenix::bind?

ⅰ亾dé卋堺 提交于 2019-12-22 03:19:13
问题 What is the difference between Boost::bind and Boost Phoenix::bind? 回答1: phoenix::bind is like lambda::bind a function that returns an expression template that records that it has to call the given function. These are designed to work together with phoenix and lambda, respectively. As a result, they contain much more things. Like, the type they return overloads all possible operators so that their respective action can be recorded and executed later. boost::bind is "just" a binder. It will