boost-mpl

Boost::MPL Vector and For_Each: how to print avector as a tuple?

寵の児 提交于 2019-12-22 10:55:47
问题 So imagine we had a mpl::vector we want to print (cout for example) it as such string: int, string, char . How to do such thing with boost::mpl? 回答1: Make a functor and call boost::for_each: struct print_class_name { template <typename T> void operator()( T t ) const { std::cout << typeid(t).name() << " "; } }; boost::mpl::for_each< Sequence >(print_class_name()); 来源: https://stackoverflow.com/questions/8386494/boostmpl-vector-and-for-each-how-to-print-avector-as-a-tuple

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 “concatenate” boost::mpl::vectors

左心房为你撑大大i 提交于 2019-12-19 16:35:47
问题 I have to different vectors mpl::vector<Type1, Type2...> mpl::vector<Type3, Type4...> I'd like to "concatenate" them to form: mpl::vector<Type1, Type2, Type3, Type4...> This would allow me to prepare vector templates and reuse them afterwards. There are different solutions to my problem, but this approach seems most appropriate to me. Thanks... 回答1: The libaray native supported function boost::mpl::joint_view is probably a better choice. It is optimized and lazy-evaluated. http://www.boost

Transforming mpl vector with own function

你说的曾经没有我的故事 提交于 2019-12-19 09:09:28
问题 I want to multiply each element in an mpl::vector by an int . First, a metafunction to multiply an int_ with an int . template <int i> struct multiply_scalar { template<typename T> struct apply { typedef int_<(T::value * i)> type; }; }; Here are the calls I want to make. typedef vector<int_<3>, int_<4> > my_vec; typedef typename transform< my_vec, multiply_scalar<2> >::type my_vec_2; typedef vector<int_<6>, int_<8> > my_vec_3; BOOST_MPL_ASSERT(( boost::is_same< my_vec_2, my_vec_3 > )); /

Is there a way to break out of boost::mpl for_each?

柔情痞子 提交于 2019-12-18 20:47:27
问题 Simple question really, let me give some background: I have a mpl::vector of types where each type has an id, at run time I use the mpl::for_each to iterate through this vector and find the matching type for the given id. But once found, there is no point in continuing the loop, so - question is, is there a way to break out of it ( without throwing an exception )? 回答1: To implement something like find_if I changed the for_each (calling it exec_if ) to take a bool template argument. The bool

boost::mpl::fold for double parameter abstraction

落爺英雄遲暮 提交于 2019-12-14 02:21:18
问题 I have a class called caRender, which provides one caRender::renderClientObject() method per given object type in clientObjectTypes. So the following code snipped shows this running situation: #define UNUSED(x) (void)(x) typedef boost::mpl::vector<Model::ClientModel::cClientVerticesObject, Model::ClientModel::cRawClientObject> clientObjectTypes; template <class T> struct methodForward{ virtual void renderClientObject(T* clientObject, Controller::QtOpenGL::cQOpenGLContext* glContext) { UNUSED

Is MPL pos an undocumented metafunction?

こ雲淡風輕ζ 提交于 2019-12-14 01:23:28
问题 There is the following example code in the BOOST MPL documentation of the find algorithm: typedef vector<char,int,unsigned,long,unsigned long> types; typedef find<types,unsigned>::type iter; ... BOOST_MPL_ASSERT_RELATION( iter::pos::value, ==, 2 ); However, I cannot find the documentation for the iterator's pos metafunction. Can I use it reliably? I'd like to use it somehow as: typedef vector<type1, type2, type3> types; template <typename T> void File::write(T value) { BOOST_MPL_ASSERT(

meta-programming: inherit from every class in a boost mpl::vector

岁酱吖の 提交于 2019-12-13 13:08:22
问题 I wish to inherit from a set of classes contained in a boost mpl::vector. Is this possible? Specifically, I wish to extend test for arbitrary many template parameters, passed as a mpl::vector. template<class T> struct Slice { public: virtual void foo(T v) const = 0; }; struct A{}; struct B{}; template <class T1, class T2> struct test : public Slice<T1>, public Slice<T2> { void foo(T1 a) const {std::cout<<"A"<<std::endl;} void foo(T2 b) const {std::cout<<"B"<<std::endl;} }; If I know there are

How to use Boost Spirit with variant with more than 20 types?

心不动则不痛 提交于 2019-12-12 21:12:50
问题 I'm parsing a quite complex grammar with Boost Spirit and I'm facing a problem with a variant that have more than 20 types (21 here): namespace eddic { namespace ast { typedef boost::mpl::vector< Integer, IntegerSuffix, Float, Litteral, VariableValue, DereferenceValue, Expression, Unary, Null, True, False, ArrayValue, FunctionCall, MemberFunctionCall, Cast, BuiltinOperator, Assignment, SuffixOperation, PrefixOperation, Ternary > types_initial; typedef boost::mpl::push_back<types_initial, New>

How do I invoke a non-default constructor for each inherited type from a type list?

有些话、适合烂在心里 提交于 2019-12-12 07:27:36
问题 I'm using a boost typelist to implement the policy pattern in the following manner. using namespace boost::mpl; template <typename PolicyTypeList = boost::mpl::vector<> > class Host : public inherit_linearly<PolicyTypeList, inherit<_1, _2> >::type { public: Host() : m_expensiveType(/* ... */) { } private: const ExpensiveType m_expensiveType; }; The Host class knows how to create an instance of ExpensiveType , which is a costly operation, and each policy class exposes functionality to use it.