boost-fusion

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

早过忘川 提交于 2019-12-04 06:03:08
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_c expects a const . I've tried other stuff (see the previous question) but still can't work out how to

Boost.MPL and type list generation

こ雲淡風輕ζ 提交于 2019-12-04 05:19:29
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 generating the types I need, so I may eventually use Fusion to instantiate those types. The types in use

Iterating over Boost fusion::vector

半城伤御伤魂 提交于 2019-12-02 11:26:15
问题 I'm trying to iterate over a boost::fusion vector using: typedef typename fusion::result_of::begin<T>::type t_iter; std::cout << distance(begin(t), end(t)) << std::endl; for(t_iter it = begin(t); it != end(t); next(it)){ std::cout<<deref(it)<<std::endl; } The distance cout statement gives me a finite length (2), however the loop seems to run indefinitely. Any advice much appreciated! 回答1: You can't just iterate a Fusion vector like that, the type for each iterator may be different than the

Iterating over Boost fusion::vector

空扰寡人 提交于 2019-12-02 06:24:55
I'm trying to iterate over a boost::fusion vector using: typedef typename fusion::result_of::begin<T>::type t_iter; std::cout << distance(begin(t), end(t)) << std::endl; for(t_iter it = begin(t); it != end(t); next(it)){ std::cout<<deref(it)<<std::endl; } The distance cout statement gives me a finite length (2), however the loop seems to run indefinitely. Any advice much appreciated! K-ballo You can't just iterate a Fusion vector like that, the type for each iterator may be different than the previous one (and usually is). I guess that's why you don't have it = next(it) in your code, it would

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

半腔热情 提交于 2019-12-01 01:59:22
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, typeid( make_wrap(3.14) ) --> wrap<double> typeid( make_wrap(a) ) --> wrap<double&> typeid( make_wrap(c) ) -

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

会有一股神秘感。 提交于 2019-11-29 14:04:19
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't found a way to construct a map from it. In particular, if I iterate over it I get only the values.

Accessing boost fusion map field name

删除回忆录丶 提交于 2019-11-29 03:45:42
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's documentation but no one seems to be accessing the field name. struct print_xml { template

Boost Spirit x3: parse into structs

六月ゝ 毕业季﹏ 提交于 2019-11-29 02:39:54
From the Boost Spirit X3 tutorial: First, let's create a struct representing an employee: namespace client { namespace ast { struct employee { int age; std::string surname; std::string forename; double salary; }; }} Then, we need to tell Boost.Fusion about our employee struct to make it a first-class fusion citizen that the grammar can utilize. BOOST_FUSION_ADAPT_STRUCT( client::ast::employee, (int, age) (std::string, surname) (std::string, forename) (double, salary) )` [...] In fusion's view, a struct is just a form of a tuple. You can adapt any struct to be a fully conforming fusion tuple. [

Boost Spirit x3: parse into structs

梦想的初衷 提交于 2019-11-27 17:00:13
问题 From the Boost Spirit X3 tutorial: First, let's create a struct representing an employee: namespace client { namespace ast { struct employee { int age; std::string surname; std::string forename; double salary; }; }} Then, we need to tell Boost.Fusion about our employee struct to make it a first-class fusion citizen that the grammar can utilize. BOOST_FUSION_ADAPT_STRUCT( client::ast::employee, (int, age) (std::string, surname) (std::string, forename) (double, salary) )` [...] In fusion's view

C++ iterate into nested struct field with boost fusion adapt_struct

℡╲_俬逩灬. 提交于 2019-11-27 12:56:05
Two stackoverflow answers suggest the approach using fusion adapt_struct to iterate over struct fields. The approach looks nice. However, how do you iterate into a field which itself is a struct? Following the previous answers, I come up with the code below. The problem is at the "#if 0" clause the code does not compile. As an alternative solution I created "decode()" function to take a void pointer to the target argument. That works, but loses the type information at compile time. Is there a better solution? struct Foo_s { int i; }; BOOST_FUSION_ADAPT_STRUCT( Foo_s, (int, i) ) struct Bar_s {