boost-mpl

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

How to use std::tuple types with boost::mpl algorithms?

霸气de小男生 提交于 2020-01-22 09:45:26
问题 The boost::mpl algorithms seem not to be able to work on std::tuple types out of the box, e.g., the following does not compile (boost-1.46.0, g++ snapshot 2011-02-19): #include <tuple> #include <boost/mpl/vector.hpp> #include <boost/mpl/contains.hpp> namespace mpl=boost::mpl; typedef mpl::vector<int,float,bool> types; static_assert(mpl::contains<types, float>::value, "vector contains bool"); typedef std::tuple<int,float,bool> types2; // the following does not compile: // error: no class

How do I loop over a boost MPL list of non-default constructed classes?

荒凉一梦 提交于 2020-01-13 03:55:11
问题 I have the following example: #include <iostream> #include <boost/mpl/for_each.hpp> #include <boost/mpl/list.hpp> struct one {}; struct two {}; struct three {}; struct four {}; struct five { five() = delete; }; template <typename T> void print() { std::cout << "hello " << typeid(T).name() << std::endl; } struct type_printer { template <typename T> void operator()(T) { print<T>(); } }; int main() { typedef boost::mpl::list< one, two, three, four, five >::type type_list; boost::mpl::for_each

How to loop through a boost::mpl::list?

不想你离开。 提交于 2019-12-30 06:12:07
问题 This is as far as I've gotten, #include <boost/mpl/list.hpp> #include <algorithm> namespace mpl = boost::mpl; class RunAround {}; class HopUpAndDown {}; class Sleep {}; template<typename Instructions> int doThis(); template<> int doThis<RunAround>() { /* run run run.. */ return 3; } template<> int doThis<HopUpAndDown>() { /* hop hop hop.. */ return 2; } template<> int doThis<Sleep>() { /* zzz.. */ return -2; } int main() { typedef mpl::list<RunAround, HopUpAndDown, Sleep> acts; // std::for

Is it possible to iterate an mpl::vector at run time without instantiating the types in the vector?

天大地大妈咪最大 提交于 2019-12-29 20:43:55
问题 Generally, I would use boost::mpl::for_each<>() to traverse a boost::mpl::vector , but this requires a functor with a template function declared like the following: template<typename T> void operator()(T&){T::staticCall();} My problem with this is that I don't want the object T to be instantiated by for_each<> . I don't need the T parameter in the operator() at all. Is there a way to accomplish this, or an alternative to for_each<> that doesn't pass an object of type T to the template

How can we implement the Builder design pattern using boost::mpl? [closed]

百般思念 提交于 2019-12-25 14:30:07
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . I have three classes which adhere to the same concept class but differ on the underlying data structure used for storage. As an illustration take the three classes given below. template< typename T > class A{ std::vector<T> storage; //etc }; template<> class A<bool>{ boost:

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

boost::mpl: How to generate pre-generated header files for lists with more than 50 entries?

会有一股神秘感。 提交于 2019-12-24 02:25:19
问题 I want to code a state machine which has a reaction list with more than 50 entries. I found here some python scripts to generate header files for lists with more than 50 entries. But I cannot manage to generate a single header file. Can someone please explain to me how to use theses scripts? I also didn't find any help in boost documention. Any help would be appreciated. 回答1: Important Update: A more improved script, which only requires a working python environment is described in this answer