boost-fusion

Using spirit to parse into classes?

馋奶兔 提交于 2019-12-11 04:03:58
问题 Below is the employee.cpp source file from the boost spirit documentation. It's 'struct employee' followed by a macro that tells fusion about 'struct employee', followed by the employee parser. I am trying to adapt this for my purposes, but rather than use 'struct employee', I have a number of classes that I'd like to use in place of 'struct employee'. I was looking at trying to replace 'struct employee' for classes, but I don't see the macros to do that in fusion? And the reason I don't want

What is the correct way to use boost::qi::rule with BOOST_FUSION_ADAPT_STRUCT?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 03:46:00
问题 I am attempting to get a qi::rule<> to emit a struct with BOOST_FUSION_ADAPT_STRUCT based on the boost employee example. I have the following struct and its associated fusion macro: struct LineOnCommand { int lineNum; std::vector<char> humpType; }; BOOST_FUSION_ADAPT_STRUCT( LineOnCommand, (int, lineNum) (std::vector<char>, humpType) ) The associated parsing rules are: qi::rule<Iterator, std::vector<char> ascii::space_type> humpIdentifer = qi::lit("BH") | qi::lit("DH"); qi::rule<Iterator,

Compiler error when adapting struct with BOOST_FUSION_ADAPT_STRUCT [duplicate]

天涯浪子 提交于 2019-12-11 02:22:42
问题 This question already has an answer here : Spirit Qi attribute propagation issue with single-member struct (1 answer) Closed 5 years ago . #include <iostream> #include <vector> #include <string> #include <boost/spirit/include/qi.hpp> #include <boost/fusion/include/adapt_struct.hpp> #include <boost/fusion/include/io.hpp> namespace qi = boost::spirit::qi; struct VectorWrapper { std::vector<std::string> data; }; BOOST_FUSION_ADAPT_STRUCT( VectorWrapper, (std::vector<std::string>, data) ) int

Boost Fusion: validate adapted struct member ordering at compile time

喜夏-厌秋 提交于 2019-12-11 02:16:48
问题 I'm using BOOST_FUSION_ADAPT_STRUCT() , and I need to check that all the members are declared and in the correct order. So first I did this: template <typename Sequence> struct checker { static void check() { typedef typename mpl::accumulate<Sequence, mpl::size_t<0>, mpl::plus<mpl::_1, mpl::sizeof_<mpl::_2>>>::type total_size; static_assert(sizeof(Sequence) == total_size::value, "omitted field?"); } }; And this works: struct foo { int x; float y; double z; }; BOOST_FUSION_ADAPT_STRUCT(foo, x,

Why does Boost.Spirit correctly parse an identifier into a std::string, but not into an adapted struct consisting solely of std::string?

三世轮回 提交于 2019-12-10 17:20:03
问题 I have defined a rule for an identifier: start with an alpha character, followed by any number of alpha-numeric characters. I have differing results when I parse directly into a std::string versus an adapted struct containing a single std::string . If the attribute for my grammar is std::string , Qi will correctly adapt the sequence of characters into it. But with the struct, only the first character is stored. I'm not quite sure why this is. (Note that it makes no difference if the struct is

Can spirit X3 work with BOOST_FUSION_ADAPT_ADT?

╄→гoц情女王★ 提交于 2019-12-10 10:14:54
问题 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

Can I use BOOST_FUSION_ADAPT_STRUCT with inherited stuff?

痴心易碎 提交于 2019-12-10 06:26:59
问题 Assume I have struct cat { int tail; int head; }; struct bird { int wing; int bursa; }; If I do this... struct wat : public cat, public bird { }; BOOST_FUSION_ADAPT_STRUCT(cat,tail,head) BOOST_FUSION_ADAPT_STRUCT(bird, wing, bursa) BOOST_FUSION_ADAPT_STRUCT(wat, wat::cat, wat::bird) ... I cannot get a build, but if I explicit refer to the inherited objects like what's below, it's perfectly valid. #include <boost/spirit/include/qi.hpp> #include <boost/fusion/include/adapt_struct.hpp> namespace

How to serialize fusion::vector?

♀尐吖头ヾ 提交于 2019-12-09 19:54:56
问题 Tell me, how can I serialize/deserialize the fusion::vector object type? Thanks. 回答1: 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

Limits of BOOST_FUSION_ADAPT_STRUCT

狂风中的少年 提交于 2019-12-09 16:50:13
问题 I have tried to play with the BOOST_FUSION_ADAPT_STRUCT macro and tried some naive things such as use Fusion to print any arbitrary structure. Starting from this example code given in the documentation, I was unable to perform on my adapted structure some operations that are allowed with a fusion sequence. #include <boost/fusion/adapted.hpp> #include <boost/fusion/sequence/io/out.hpp> #include <boost/fusion/sequence/intrinsic.hpp> #include <boost/fusion/view.hpp> #include <iostream> namespace

Semantics for wrapped objects: reference/value by default via std::move/std::ref

旧城冷巷雨未停 提交于 2019-12-09 02:15:31
问题 In recent times I am using often a natural idiom I "discovered" in C++11 that is that wrapped object can automatically hold reference when this is possible. The main question here will be about the comparison with the behavior of this "idiom" to other behaviors in the standard (see below). For example: template<class T> struct wrap{ T t; }; template<class T> wrap<T> make_wrap(T&& t){ return wrap{std::forward<T>(t)}; } In this way for the code double a = 3.14 double const c = 3.14 I get,