boost-fusion

Adapt class containing a string member as synthesized attribute

寵の児 提交于 2019-12-08 19:21:12
问题 I’m trying to parse a character string into an attribute of a custom type symbol , which contains a std::string member. I thought I could use BOOST_FUSION_ADAPT_STRUCT here but that doesn’t work. If I declare the rule as rule<It, std::string(), space_type> it works. If I define it as rule<It, symbol(), space_type> it fails with the error “no type name value_type in symbol ”. I think Spirit is trying to append the value character-for-character to the attribute, which fails as expected. But isn

Can I read a file and construct hetereogenous objects at compile time?

好久不见. 提交于 2019-12-06 06:31:33
问题 Situation: YAML file containing list of heterogeneous objects by name, like so: object: Foo name: Joe Bloggs age: 26 object: Bar location: UK Objects do not inherit from any base class or share any sort of relationship between each other apart from the fact that they appear to "live" together. This can contain any number of objects. The list of available types can exist in a typelist in the codebase if required. In my C++ land I have the objects: struct Foo { Foo(std::string n, int a) : name

Can spirit X3 work with BOOST_FUSION_ADAPT_ADT?

自闭症网瘾萝莉.ら 提交于 2019-12-06 03:06:32
Change my codes from QI to X3, and get some compile error with BOOST_FUSION_ADAPT_ADT . I tried boost 1.64 and 1.67, neither of them work. I modified the spirit X3 example rexpr_min , adding getter and setter to struct rexpr , changing the BOOST_FUSION_ADAPT_STRUCT to BOOST_FUSION_ADAPT_ADT , and compile it fail, too. Enviroment: ubuntu 16.04 G++ 5.4, with -std=c++17 flag boost 1.67 Error message: boost/spirit/home/x3/core/detail/parse_into_container.hpp:142:35: error: invalid initialization of non-const reference of type ‘boost::fusion::extension::adt_attribute_proxy<client::ast::rexpr, 0,

How to fill boost::fusion::vector at runtime?

假装没事ソ 提交于 2019-12-06 02:16:41
问题 Firstly, apologies for the similarity to my previous question here, but I don't think I asked the right thing. I have a method: template <typename T> void some_method( T &t) {...} which takes a type fusion::vector<T1, T2, T3, ..., Tn> to be determined at runtime - e.g. vector<int, double> in one call and vector<int, double, int> in another. I want to fill this vector dynamically with something like: int blah = 5; for(int i = 0; i<size(t); i++){ at_c<i>(t) = blah; } This doesn't work since at

Boost::Spirit::Qi. How to turn inlined parser expressions into standalone grammars, and how to unpack the tuples generated by them?

巧了我就是萌 提交于 2019-12-04 19:19:57
问题 I'm using QI and Phoenix, and I want to write a small grammar that returns 4 bools which are to be used as arguments for a function call inside a semantic action. I have several functions that need those things, and so far I have used this approach: ( qi::_bool >> qi::_bool >> qi::_bool >> qi::_bool) [px::bind(&Bool4Function, spirit::_val, spirit::_1, spirit::_2, spirit::_3, spirit::_4)] and while it's okay on it's own, using it all over the place is just plain ugly and confusing, even with

How to serialize fusion::vector?

荒凉一梦 提交于 2019-12-04 17:03:17
Tell me, how can I serialize/deserialize the fusion::vector object type? Thanks. niXman Solved. Like this: http://liveworkspace.org/code/652cab59dc33d280b6d48470c11cfb91 #include <iostream> #include <sstream> #include <boost/fusion/algorithm/iteration/for_each.hpp> #include <boost/fusion/include/for_each.hpp> #include <boost/fusion/container/vector.hpp> #include <boost/fusion/include/vector.hpp> #include <boost/fusion/container/vector/vector_fwd.hpp> #include <boost/fusion/include/vector_fwd.hpp> #include <boost/fusion/container/generation/make_vector.hpp> #include <boost/fusion/include/make

Can I read a file and construct hetereogenous objects at compile time?

北城余情 提交于 2019-12-04 14:04:09
Situation: YAML file containing list of heterogeneous objects by name, like so: object: Foo name: Joe Bloggs age: 26 object: Bar location: UK Objects do not inherit from any base class or share any sort of relationship between each other apart from the fact that they appear to "live" together. This can contain any number of objects. The list of available types can exist in a typelist in the codebase if required. In my C++ land I have the objects: struct Foo { Foo(std::string n, int a) : name(n), age(a) {} std::string name; int age; }; struct Bar { Bar(std::string l) : location(l) {} std:

Boost fusion serialization of a class using BOOST_FUSION_ADAPT_ADT

大城市里の小女人 提交于 2019-12-04 12:49:53
I am trying to get a serialization module for classes using boost fusion. I have converted my class to a boost::fusion sequence. This example is followed from the slides of the talk of Michael Caisse at boostcon 13 https://github.com/boostcon/cppnow_presentations_2013/blob/master/thu/solving_world_problems_with_fusion.pdf?raw=true The example explained by Michael worked good for struct type. The same could not be applied for class types. What am i missing here ? #include <iostream> #include <typeinfo> #include <string> #include <boost/fusion/include/sequence.hpp> #include <boost/fusion/include

Boost Fusion: convert adapted struct type to text

蹲街弑〆低调 提交于 2019-12-04 11:31:59
Given a struct like this: struct Foo { int x; int y; double z; }; BOOST_FUSION_ADAPT_STRUCT(Foo, x, y, z); I want to generate a string like this: "{ int x; int y; double z; }" I have seen how to print the values of a Fusion adapted struct, but here I need to print the types and names only. How can I do this mostly simply? I'm not married to Boost.Fusion if there's a better way. llonesmiz I think you can get something similar to what you want by making some slight modifications on the code in this answer . You can easily get the member name using boost::fusion::extension::struct_member_name but

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

ぃ、小莉子 提交于 2019-12-04 06:38:19
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) -> bool { return x.second > n; } ); which is the accepted answer . I'm still looking for a short and cool