boost-preprocessor

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

How to use boost::preprocessor to unzip a sequence?

流过昼夜 提交于 2019-12-05 10:40:19
How to use boost::preprocessor to unzip a sequence of pairs? For example, I have a sequence as below (comma between doesn't matter) (int,x)(double,y)(float,z) or (int,x),(double,y),(float,z) or ((int)(x))((double)(y))((float)(z)) and want to convert to int,double,float and x,y,z By using macor like UNZIP(i, seq) where i is the index. Unzipping of (int, x, 10)(double, y, 20)(float, z, 30) , i.e. sequence without commas between elements. LIVE DEMO #include <boost/preprocessor/punctuation/comma_if.hpp> #include <boost/preprocessor/seq/for_each_i.hpp> #include <boost/preprocessor/seq/pop_front.hpp

Avoid if-else branching in string to type dispatching

烈酒焚心 提交于 2019-12-04 23:23:34
Usually when you write a CLI tool which accepts parameter you have to deal with them. Most of the time you want to switch between behaviours based on the value of an argument. The following is a common use case, where the program accepts a type and then prints something based on that type. I am using Boost to pre-process and auto generate the whole if-else branches. This is very nice in terms of maintainability as I only need to update a define when I introduce a new type. On the other hand it is quite far from being modern and elegant. I thought about using better-enums to avoid using the if

How to create proxy class?

谁都会走 提交于 2019-12-04 21:36:56
Having N difrent classes that have no public data fields, only methods (that do not overlap), how to create unifiing them all proxy class via boost preprocessor? For example we had classes: A that had method do(); and class B had method data(); . I wonder if there is a way (using Boost Preprocessor for example) to create a proxy class that would have all methods from A and B (here do() data() ) and a constructor taking in that pointers to that classes instances - one for A and one for B? So we would get api like such pseudocode: JOIN(A, B, C);// or if needed JOIN("path_to_A.h", "path_to_B.h",

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

不问归期 提交于 2019-12-04 09:08:25
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_email overloads.Is it possible and how to create such class that would proxy any number of overload

How do I expand a macro containing commas inside a BOOST_PP_IF

≯℡__Kan透↙ 提交于 2019-12-04 04:42:56
问题 I asked the following question earlier, but the solution doesn't seem to work in this particular case. How do I print out a comma multiple times using Boost Preprocessor I am trying to expand a macro containing a comma conditionally. Here is an example illustrating the problem: #define TEST(...)\ BOOST_PP_REPEAT( \ BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), \ MACRO, \ BOOST_PP_VARIADIC_TO_TUPLE(__VA_ARGS__)) #define MACRO(z, n, data) BOOST_PP_IF(1,MACRO_CONTAINING_COMMA(z, z),MACRO_CONTAINING_COMMA

Macro not expanded with direct call, but expanded with indirect

无人久伴 提交于 2019-12-02 13:22:59
问题 I've got the following macros #include <boost/preprocessor.hpp> #define DB_FIELD(...) BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__) #define DB_TOFIELD(type,name) \ private:\ type name##_;\ public:\ const type& get_##name(){return name##_;}\ void set_##name(const type& val) { name##_ = val; } #define GEN_ENUM_FIELD(r,data,elem) BOOST_PP_CAT(FIELD_,BOOST_PP_SEQ_ELEM(1,elem)), #define DECLARE(type, name) DB_TOFIELD(type, name) #define GEN_FIELD_DECL(r, data, elem) DECLARE(BOOST_PP_SEQ_ELEM(0,elem),BOOST

Use Boost Preprocessor to Parse sequence of elements

时光总嘲笑我的痴心妄想 提交于 2019-12-01 22:20:34
问题 I have a macro defined which is #define TYPES (height,int,10)(width,int,20) How to expand this macro using Boost Preprocessor something like this? int height = 10; int width = 20; at most i am able to get is height,int,10 and width,int,20 as string but can't parse individual element. 回答1: Using BOOST_PP_VARIADIC_SEQ_TO_SEQ to turn TYPES into ((height,int,10))((width,int,20)) before processing, so that BOOST_PP_SEQ_FOR_EACH doesn't choke on it: #define MAKE_ONE_VARIABLE(r, data, elem) \ BOOST

How do I expand a macro containing commas inside a BOOST_PP_IF

二次信任 提交于 2019-12-01 22:13:22
I asked the following question earlier, but the solution doesn't seem to work in this particular case. How do I print out a comma multiple times using Boost Preprocessor I am trying to expand a macro containing a comma conditionally. Here is an example illustrating the problem: #define TEST(...)\ BOOST_PP_REPEAT( \ BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), \ MACRO, \ BOOST_PP_VARIADIC_TO_TUPLE(__VA_ARGS__)) #define MACRO(z, n, data) BOOST_PP_IF(1,MACRO_CONTAINING_COMMA(z, z),MACRO_CONTAINING_COMMA(z, z)) #define MACRO_CONTAINING_COMMA(_NAME, _NAME2) _NAME TIBRA_EATEN_COMMA() _NAME2 #define EATEN

Boost Preprocessor library for generating a set of types based on a list of basic types e.g. PointI32, PointF32 etc. in C++/CLI

♀尐吖头ヾ 提交于 2019-12-01 13:45:35
I am trying to figure out how to use the Boost.Preprocessor library http://www.boost.org/doc/libs/release/libs/preprocessor to unfold a "generic" type for different specific types. Below I will ask this for a simple point class example. Given: struct Point##TYPE_SUFFIX_NAME { TYPE X; TYPE Y; // Other code }; I want to generate this type for different basic (POD) data types e.g.: PointF32, PointF64, PointI32 etc. where PointF32 would be: struct PointF32 { float X; float Y; }; That is, based on a list of types: short, int, long, float, double etc. I want to "unfold" the above type for these.