boost-fusion

Boost Fusion articles, examples, tutorials?

依然范特西╮ 提交于 2019-12-31 17:51:21
问题 Do you know any good resources/articles/examples of boost::fusion library usage? Boost Fusion looks extremely interesting, I think I understand how it works and how to use the basics, but I'm looking for some resources that show any interesting usage/practices e.g. articles or blogs (apart from boost.org itself). 回答1: I thought the comment by johannes-schaub-litb should be an answer, as I nearly overlooked it. So here it is: Johannes' excellent example. There are also some other examples in

How to generate wrappings for C++ functions?

杀马特。学长 韩版系。学妹 提交于 2019-12-24 07:38:10
问题 I'm trying to create a generic way to wrap C++ functions (from a different language). I have a list of parameters (and and an iterator) and a specific C++ function to be called on the list of parameters. I'm trying to find someway to unpack the list of parameters as arguments to my function. My current approach is to: Use Boost::FunctionTypes to get the parameters of the function as a sequence. Create a Boost::Fusion list that would contain the values of the arguments, using the values of the

Boost fusion/mpl issues after upgrade to a newer version

一笑奈何 提交于 2019-12-24 07:18:16
问题 This is a simplified version of some code I wrote: #include <iostream> #include <boost/mpl/vector.hpp> #include <boost/mpl/contains.hpp> #include <boost/mpl/placeholders.hpp> #include <boost/fusion/include/filter_if.hpp> #include <boost/fusion/include/for_each.hpp> #include <boost/fusion/include/map.hpp> #include <boost/fusion/include/pair.hpp> #include <boost/fusion/include/io.hpp> namespace ids{ struct a0{}; struct a1{}; struct a2{}; struct a3{}; }; typedef boost::fusion::map< boost::fusion

c++/boost fusion handle parent class

試著忘記壹切 提交于 2019-12-24 06:28:10
问题 Lets suppose I have such classes hierarchy: enum class Type { DUMMY }; struct Base { int a; explicit Base(int a) : a(a) {} virtual ~Base() {} virtual Type type() = 0; }; struct Foo1 : public Base { double b; Foo1(int a, double b) : Base{a}, b(b) {} Type type() override { return Type::DUMMY; } }; all derived from Base using single inheritance and not defined any virtual methods, except overriding type() method. And I want to have meta info for each derived from Base to serialization and debug

Filling a std::tuple

馋奶兔 提交于 2019-12-24 04:01:11
问题 I have a overloaded function which looks like: template<typename T> T getColumn(size_t i); template<> std::string getColumn<std::string>(size_t i) { if(i == 0) return "first"; else return "other"; } template<> int getColumn<int>(size_t i) { return i*10; } // ... Now I want to implement the function template<typename... Values> std::tuple<Values...> getColumns(); Which creates a tuple (for the return value) and calls getColumn for every element of the tuple (saving the return value in that

boost fusion: strange problem depending on number of elements on a vector

痞子三分冷 提交于 2019-12-24 04:00:15
问题 I am trying to use Boost::Fusion (Boost v1.42.0) in a personal project. I get an interesting error with this code: #include "boost/fusion/include/sequence.hpp" #include "boost/fusion/include/make_vector.hpp" #include "boost/fusion/include/insert.hpp" #include "boost/fusion/include/invoke_procedure.hpp" #include "boost/fusion/include/make_vector.hpp" #include <iostream> class Class1 { public: typedef boost::fusion::vector<int,float,float,char,int,int> SequenceType; SequenceType s; Class1

How to write a for loop for a Hana sequence?

不打扰是莪最后的温柔 提交于 2019-12-23 02:43:11
问题 I have a Boos.Hana sequence and I would like to print it to screen separated by commas. However the commas separate elements only, so I have to check if I am at the last element. Currently my hack is pretty bad (looking at the pointer and casting to void* . template<class P, class... Ts> decltype(auto) operator<<( std::ostream& os, boost::hana::tuple<Ts...> const& tpl ){ os << "{"; boost::hana::for_each( tpl, [&](auto& x){ os << x; if((void*)&boost::hana::back(tpl) != (void*)&x) os << ", "; }

Boost spirit parse integer to custom list template

為{幸葍}努か 提交于 2019-12-22 09:19:38
问题 I have trouble with boost spirit to parse a file like that : int [int, int, int] [ int, int] ... Nothing really hard, the following grammar works for that: template<typename Iterator> struct parser_expression : qi::grammar<Iterator,ascii::space_type> { parser_expression() : parser_expression::base_type(start) { using qi::double_; using qi::int_; using boost::spirit::qi::char_; using qi::alpha; using qi::alnum; using qi::digit; using qi::eps; using qi::_val; using boost::phoenix::bind; start =

Boost fusion serialization of a class using BOOST_FUSION_ADAPT_ADT

一曲冷凌霜 提交于 2019-12-21 20:25:19
问题 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

Wrapping a Boost.Fusion Sequence

纵然是瞬间 提交于 2019-12-21 17:25:06
问题 I'm looking for a way to create a Boost.Fusion sequence wrapper that is itself a Fusion sequence and forwards all 'calls' to its wrapped sequence. Something in the lines of template< typename Sequence > struct sequence_wrapper { explicit sequence_wrapper( Sequence const& s ) : seq( s ){} Sequence seq; }; where sequence_wrapper< Sequence > is a Fusion sequence as well, and works just as Sequence would. The reason I need this is that I have several functions that operate on Fusion sequences