boost-mpl

Boost MPL to generate code for object serialization?

北慕城南 提交于 2019-12-07 12:48:08
问题 I want to generate serialization/deserialization code for class Object { string a; int b; long c; char d; }; by looking at a mpl sequence, but I need to be able to identify object and retrieve it back as well, I can't figure out how would I get the names of it members, do I have to know it ? code should look like void SerializeObject(ostream os) { serialize(object.a, os); serialize(object.b, os); //serialize(object.member, os); } I want to generate above code by user only defining a mpl

How to concatenate a const char* in compile time

徘徊边缘 提交于 2019-12-07 12:29:09
问题 I have a vector of mpl::string. mpl::string size limit is 32 elements. Have a way to create const char* array in compile time MACRO(z,i,data) data ............. const char* array[] = { BOOST_PP_ENUM(SIZE,MACRO,mpl_vector) }; But i need get a one const char* string in compile time. How to make it? UPDATE I create an array of mpl::string in compile time. They compressed (size of every string about 25-31 with limit of 32). I may get array from it strings like //first,second string etc is mpl::c

Why does Boost MPL have integral constants?

佐手、 提交于 2019-12-06 22:13:52
问题 Since you can take integral values as template parameters and perform arithmetic on them, what's the motivation behind boost::mpl::int_<> and other integral constants? Does this motivation still apply in C++11? 回答1: You can take integral values as template parameters, but you cannot take both types and non-type template parameters with a single template. Long story short, treating non-type template parameters as types allows for them to be used with a myriad of things within MPL . For

concatenate boost::mpl::string

天涯浪子 提交于 2019-12-06 16:27:36
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 string; int main() { std::cout << boost::mpl::c_str<string>::value << std::endl; } full source here: http

Sun C++ Compilers and Boost

蓝咒 提交于 2019-12-06 09:06:43
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. Chris Huang-Leaver I have had some success with Boost and Sun's CC compiler on Solaris 10, but it is a pain. The main thing

C++11 how to proxy class function having only its name and parent class?

风格不统一 提交于 2019-12-06 05:19:27
问题 I wonder if it is possible using boost::mpl/preprocessor or some noce C++11 features to create function proxy from class type and function name. Say we had: inline void set_email(const ::std::string& value); inline void set_email(const char* value); inside class Email. We know there is set_email function n it, we want to create a prox class with API like PROXY(Email, set_email, MyEmail) Email * email = new Email(); MyEmail * myEmail = new MyEmail(email); and have abilety to call any of set

Boost MPL: Call a (member) function only if it exists

拈花ヽ惹草 提交于 2019-12-06 02:44:25
问题 I have a class A that has a template parameter T. There are use cases where the class T offers a function func1() and there are use cases where T doesn't offer it. A function f() in A should call func1(), iff it exists. I think this should be possible with boost mpl, but I don't know how. Here some pseudo code: template<class T> class A { void f(T param) { if(T::func1 is an existing function) param.func1(); } }; Even better would be an else-case: template<class T> class A { void f(T param) {

pretty printing boost::mpl::string<…> types in gdb

人走茶凉 提交于 2019-12-06 01:37:07
问题 I use boost::mpl::string<...> types extensively... enough that it would really help with debugging to have the types pretty-printed in gdb . So... instead of gdb showing the individual (multicharacter literal) components like it currently does ... boost::mpl::string<1668248165, 778856802, 778858343, ..., ..., 0, 0, 0, 0, 0, 0> It would display the equivalent string value instead ... boost::mpl::string<"The way out is through"> I've seen gdb macros and python scripts for pretty-printing STL

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

梦想与她 提交于 2019-12-06 00:48:26
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? 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

Ambiguous metafunction or undefined type

半腔热情 提交于 2019-12-05 23:50:36
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 search exactly, replace template < typename C, typename Y > struct replace<C, C, Y> { typedef Y type; };