boost-mpl

boost multi index convert index to tag and loop on indexes

感情迁移 提交于 2019-12-12 07:04:15
问题 I have a template class(CrMultiIndex) that receive a template parameter a definition of boost multi index(GlobalHash).I work with c++14 I need a way to translate index to tag(n_to_tag)? And to loop on indexes in CrMultiIndex ctor or Init function? My original purpose is to loop on indexes and generate tags names string with typeid(T).name() at init. So i can display statistics according to Tag name I have template class template <typename KeysType, typename MultiIndexType> class CrMultiIndex

Getting started with boost mpl with vector and push_back

蹲街弑〆低调 提交于 2019-12-11 15:07:12
问题 I've been scratching my head for far too long, I'm finding using MPL very difficult to get around and hoping somebody can get me started. Here is some partial code from a class I am developing which does not use MPL. I eventually want to implement this class all at compile time. This code probably won't make sense but I don't want all the solution in MPL - hopefully I can achieve that myself (see below for particular help). class define_cell_type{ public: define_cell_type () = default; define

Boost Fusion: validate adapted struct member ordering at compile time

喜夏-厌秋 提交于 2019-12-11 02:16:48
问题 I'm using BOOST_FUSION_ADAPT_STRUCT() , and I need to check that all the members are declared and in the correct order. So first I did this: template <typename Sequence> struct checker { static void check() { typedef typename mpl::accumulate<Sequence, mpl::size_t<0>, mpl::plus<mpl::_1, mpl::sizeof_<mpl::_2>>>::type total_size; static_assert(sizeof(Sequence) == total_size::value, "omitted field?"); } }; And this works: struct foo { int x; float y; double z; }; BOOST_FUSION_ADAPT_STRUCT(foo, x,

inserted items disappear from boost::mpl::map

我只是一个虾纸丫 提交于 2019-12-11 00:46:52
问题 The following example demonstrates what I mean: #include <boost/mpl/map.hpp> #include <boost/mpl/for_each.hpp> #include <boost/mpl/pair.hpp> #include <boost/mpl/at.hpp> #include <boost/mpl/insert.hpp> #include <iostream> using namespace boost::mpl; template <int n1, int n2> struct entry { typedef pair<int_<n1>, int_<n2> > type; }; typedef map<entry<1,1>::type> entries; typedef insert< entries, entry<4,4>::type>::type update; typedef insert< update, entry<5,5>::type>::type update2; struct

Ambiguous metafunction or undefined type

∥☆過路亽.° 提交于 2019-12-10 10:22:25
问题 I am new to metafunctions. I want to write a function that replaces all matches of a certain type in a compound type with some other type. In example: replace<void *, void, int>::type should be int * , replace<void, void, int>::type should be int , etc. I basically failed with two different approaches so far: template < typename C, // Type to be searched typename X, // "Needle" that is searched for typename Y // Replacing type > struct replace { typedef C type; }; // If the type matches the

Combination of types using boost::mpl

丶灬走出姿态 提交于 2019-12-09 13:36:20
问题 I have a list of types, from which I want to construct the list of all combinations with two elements. For example: namespace mpl = boost::mpl; typedef mpl::vector<int, long> typelist; // mpl magic... // the wanted list is equivalent to: typedef mpl::vector<pair<int, int>, pair<int, long>, pair<long, int>, pair<long, long> > combinations; Here, pair<T1,T2> could be std::pair<T1,T2> , or mpl::vector<T1,T2> . How to do this? I would also be interested in removing the duplicates when we consider

How do I convert a C string to a int at compile time?

一个人想着一个人 提交于 2019-12-09 12:47:57
问题 I want to be able to pass an integer or a double (or a string) as a template argument and in some instances convert the result to an integer and use it as a template argument for a type in the class. Here's what I've tried: template <typename MPLString> class A { // the following works fine int fun() { // this function should return the int in the boost mpl type passed to it // (e.g. it might be of the form "123") return std::stoi(boost::mpl::c_str<MPLString>::value); } // the following

concatenate boost::mpl::string

こ雲淡風輕ζ 提交于 2019-12-08 06:51:34
问题 How I can concatenate boost::mpl::string? The following code produce errors: #include <iostream> #include <boost/mpl/vector.hpp> #include <boost/mpl/string.hpp> #include <boost/mpl/fold.hpp> #include <boost/mpl/placeholders.hpp> #include <boost/mpl/push_back.hpp> typedef boost::mpl::vector< boost::mpl::string<'ab'>, boost::mpl::string<'cd'>, boost::mpl::string<'ef'> > slist; typedef boost::mpl::fold< slist, boost::mpl::string<>, boost::mpl::push_back<boost::mpl::_1, boost::mpl::_2> >::type

Sun C++ Compilers and Boost

与世无争的帅哥 提交于 2019-12-07 23:29:21
问题 I am currently developing on OpenSolaris 2009-06. The Boost::MPL Documentation seems to suggest that sun compilers are not supported (the document was last updated in 2004 ). Boost's top level documentation seems to suggest that the sun compilers 5.10 onwards are supported -- I guess this is a general level of support or does this include MPL ?. Does anyone have any details on the state of the C++ conformance of the sun 5.10 compilers ? I could always compile using GCC. 回答1: I have had some

type wrapper error with boost::mpl::for_each (section 9.1.1 from Abrahams & Gurtovoy book)

瘦欲@ 提交于 2019-12-07 23:00:02
问题 The following code is copied almost verbatim from section 9.1.1 of the book C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond by David Abrahams & Aleksey Gurtovoy. The only change is that I want to be able to change the type wrapper template from the book with the regular Boost template mpl::identity. However, under Microsoft Visual C++ Express 2010 (SP1) I get a mysterious compiler warning if I do that. It seems somehow related to the fact that the type