boost-fusion

Parsing Selector struct with alternating tokens using Boost Spirit X3

前提是你 提交于 2021-02-05 08:30:09
问题 I am trying to parse the following struct: struct Selector { std::string element; std::string id; std::vector<std::string> classes; }; This struct is used to parse selectors in the form element#id.class1.class2.classn . These selectors always start with 1 or no elements, could contain 1 or no ids, and could contain 0 to n classes. This gets even more complicated though, because classes and id can appear in any order, so the following selectors are all valid: element#id.class1 , .class1#id

Parsing Selector struct with alternating tokens using Boost Spirit X3

故事扮演 提交于 2021-02-05 08:28:06
问题 I am trying to parse the following struct: struct Selector { std::string element; std::string id; std::vector<std::string> classes; }; This struct is used to parse selectors in the form element#id.class1.class2.classn . These selectors always start with 1 or no elements, could contain 1 or no ids, and could contain 0 to n classes. This gets even more complicated though, because classes and id can appear in any order, so the following selectors are all valid: element#id.class1 , .class1#id

Compile-time Size of Struct Minus Padding

谁说我不能喝 提交于 2021-01-01 06:43:37
问题 I'm trying to use Boost MPL and Fusion to calculate the size of a struct exclusive of any padding. This is my current best attempt: Live example template<class T> constexpr std::size_t sizeof_members(void) { using namespace std; namespace mpl = boost::mpl; namespace fusion = boost::fusion; //This works, but only for structs containing exactly 4 members... typedef typename mpl::apply<mpl::unpack_args<mpl::vector<mpl::_1, mpl::_2, mpl::_3, mpl::_4>::type >, T>::type member_types; typedef

Compile-time Size of Struct Minus Padding

≯℡__Kan透↙ 提交于 2021-01-01 06:42:46
问题 I'm trying to use Boost MPL and Fusion to calculate the size of a struct exclusive of any padding. This is my current best attempt: Live example template<class T> constexpr std::size_t sizeof_members(void) { using namespace std; namespace mpl = boost::mpl; namespace fusion = boost::fusion; //This works, but only for structs containing exactly 4 members... typedef typename mpl::apply<mpl::unpack_args<mpl::vector<mpl::_1, mpl::_2, mpl::_3, mpl::_4>::type >, T>::type member_types; typedef

Boost.Fusion run-time switch

我与影子孤独终老i 提交于 2020-01-31 07:09:08
问题 I am reading the type of an object from a file: enum class type_index { ... }; type_index typeidx = read(file_handle, type_index{}); Depending on the type index, I want to create a type (out of a list of possible types), and do something generic with it (the same generic code for each type): std::tuple<type1, type2, ..., typeN> possible_types; boost::fusion::for_each(possible_types, [&](auto i) { if (i::typeidx != typeidx) { return; } // do generic stuff with i }); That is: I have the same

Boost.Fusion run-time switch

ⅰ亾dé卋堺 提交于 2020-01-31 07:07:51
问题 I am reading the type of an object from a file: enum class type_index { ... }; type_index typeidx = read(file_handle, type_index{}); Depending on the type index, I want to create a type (out of a list of possible types), and do something generic with it (the same generic code for each type): std::tuple<type1, type2, ..., typeN> possible_types; boost::fusion::for_each(possible_types, [&](auto i) { if (i::typeidx != typeidx) { return; } // do generic stuff with i }); That is: I have the same

Compile time switch generation based on number of fields in structure

◇◆丶佛笑我妖孽 提交于 2020-01-17 11:17:11
问题 How in C++03 get in compile time number of members of chosen struct? I was experimenting with BOOST_FUSION_ADAPT_STRUCT but I did't get any working example. I want to generate switch statement in compile time, where there will be one case per each member. So lets say we have struct with 3 members then I want to generate this switch: switch(val) { case 0: break; case 1: break; case 2: break; } In each statement I will call template function with some parameters. One of this parameters is a

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:

Pointers to class members when iterating with boost::fusion

点点圈 提交于 2020-01-04 06:17:50
问题 I have a boost::graph that uses bundled properties like the following: struct Vertex { std::string id; }; If I want to use this information in boost::dynamic_properties (e.g. for printing in graphml-format), I can use something like that: template<typename T> std::string myPrettyPrinter(const T& t); int main() { using namespace boost; MyGraph g; dynamic_properties dp; dp.property("id", make_transform_value_property_map( & myPrettyPrinter<std::string>, get(&Vertex::id, g) ) ); } Since the

Parsing a structure in an associative manner with Boost Spirit and Fusion

痴心易碎 提交于 2020-01-04 02:44:17
问题 I'm trying to parse a key-value string into a structure. Some key-values may be absent or may be in different order, so I wanted to use boost::fusion to adapt the structure and then parse into it with at_key<> directive. #include <iostream> #include <string> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix.hpp> #include <boost/fusion/adapted.hpp> #include <boost/fusion/sequence.hpp> using namespace std; namespace qi = boost::spirit::qi; namespace ascii = boost: