boost-fusion

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) ->

Boost.MPL and type list generation

家住魔仙堡 提交于 2019-12-21 12:39:26
问题 Background This is for a memory manager in a game engine. I have a freelist implemented, and would like to have a compile-time list if these. (A MPL or Fusion vector, for example). The freelist 's correspond to allocation sizes, and when allocating/deallocating objects of size less than a constant, they will go to the corresponding freelist . In the end, this means small objects globally have amortized constant time allocation and constant time deallocation. (Yay.) Problem The problem is

How to generalize a spirit parser to take lists in arbitrary order?

梦想的初衷 提交于 2019-12-19 04:01:36
问题 I have a simple parser which can parse lists of ints or quoted strings. If I do the SIMPLE_CASE where I take the input to be: std::string input1 = "{ INT: 42, 24 STR: \"Smith\", \"John\" }"; it parses correctly into my_record , which contains a list of ints and a list of std::string. I want to modify this code to be generic so that it can take zero or more INT lists and zero or more STR lists in arbitrary order and stuff them into my_record in the proper order. I would like my second, more

Is it possible to generate a fusion map from an adapted struct?

扶醉桌前 提交于 2019-12-18 08:10:28
问题 Let A be: struct A { int a; std::string b; struct keys { struct a; struct b; }; }; I would like to generate a fusion::map from the struct such that it contains the fusion::pair s: fusion::pair<A::keys::a, int> and fusion::pair<A::keys::b, std::string> . Something like A a; fusion::make_map<A>(a) I've tried with BOOST_FUSION_ADAPT_ASSOC_STRUCT BOOST_FUSION_ADAPT_ASSOC_STRUCT( A, (int, a, A::keys::a) (std::string, b, A::keys::b) ) This adapts A to be used as an associative sequence, but I haven

Accessing boost fusion map field name

人盡茶涼 提交于 2019-12-18 04:00:53
问题 I've been trying to use some of the boost fusion stuff to write a regular c struct to file. An XML file seems a good way to capture the data and make it compatible with other tools or hand editable. It seems like I almost have it but something fundamental seems to be missing. I'm using something pretty similar to what's on the boost::fusion quick start page: http://www.boost.org/doc/libs/1_54_0/libs/fusion/doc/html/fusion/quick_start.html. As a side note I have thoroughly looked here and on

Boost Fusion adapt declaration for a templated self referential structure

China☆狼群 提交于 2019-12-13 19:12:37
问题 I am trying to declare a self referential tree like structure that is templated on the type of data that the struct can hold. I am running into compilation errors, when trying to declare the boost fusion template adapt definition for this structure. Can anyone help ? #include <iostream> #include <string> #include <memory> #include <vector> #include <boost/lexical_cast.hpp> #include <boost/dynamic_bitset.hpp> #include <boost/fusion/adapted/struct/adapt_struct.hpp> #include <boost/fusion

Boost Fusion container of shared pointers (shared_ptr) causing Segmentation Fault (sigsegv) or garbage results

微笑、不失礼 提交于 2019-12-13 16:16:00
问题 Edit: This turned out to be an issue with temporaries. Basically, I was ignorantly using C++ as if it worked like Java or C#, which it does not. Hopefully, this will be a good cautionary tale. Edit: This issue only seems to happen with the combination of joint_view and shared_ptr . Raw pointers seem to work fine in the same scenario, as do shared pointers in a plain fusion container constructed w/ all its items at once, without adding anything more to it. Details below: I'm using mingw gcc 4

BOOST_FUSION_ADAPT_TPL_STRUCT and template array size

好久不见. 提交于 2019-12-12 11:35:30
问题 I am trying to iterate over a C++ template structure thanks to BOOST_FUSION_ADAPT_TPL_STRUCT. My structure contains fixed-size multidimensional arrays whose sizes are template parameters. If we consider Boost's example modified to fit my problem: #include <iostream> #include <string> #include <boost/fusion/adapted/struct/adapt_struct.hpp> #include <boost/fusion/include/adapt_struct.hpp> // Example: // http://www.boost.org/doc/libs/1_53_0/libs/fusion/doc/html/fusion/adapted/adapt_tpl_struct

parsing into classes (not structs)

陌路散爱 提交于 2019-12-11 13:07:56
问题 below I show an edited spirits employee example which does not compile. The problem I want to solve is to parse into classes not structs. I know, it's quite the same besides public/private. But I need to have a constructor to work before storing the class/struct into vector. How do I change BOOST_FUSION_ADAPT_STRUCT? How can I get this to run? // STD HEADER #include <iostream> #include <string> #include <complex> // BOOST HEADER #include <boost/config/warning_disable.hpp> #include <boost

Boost fusion error in substituting the adt_proxy type to the value type

与世无争的帅哥 提交于 2019-12-11 04:15:54
问题 I am trying to write a XML serializer and de-serializer for user defined classes. Please refer to the code posted in Coliru The deserializer i am unable to get the type resolved from the adt_proxy to the value type in question. The error is the read_handle function. Can anyone tell me what I am missing here ? static inline void read_handle(FusionVisitorConcept& visitor, S& s) { visitor.start_member(name_t::call()); VisitorApplication<FusionVisitorConcept, current_t>::read_handle(visitor,