x-macros

Can any one explain about X-macros with example code to use them? [closed]

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-19 09:05:02
问题 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 7 years ago . Improve this question I am trying to understand the X-macros topic in detail. But didn't get the full clarity on this. It would be better if any one of the expert will explain this topic with some example "how to use, how to call." I have found several articles, but didn't get the

Can any one explain about X-macros with example code to use them? [closed]

蓝咒 提交于 2021-01-19 09:02: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 7 years ago . Improve this question I am trying to understand the X-macros topic in detail. But didn't get the full clarity on this. It would be better if any one of the expert will explain this topic with some example "how to use, how to call." I have found several articles, but didn't get the

Can any one explain about X-macros with example code to use them? [closed]

狂风中的少年 提交于 2021-01-19 09:02:04
问题 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 7 years ago . Improve this question I am trying to understand the X-macros topic in detail. But didn't get the full clarity on this. It would be better if any one of the expert will explain this topic with some example "how to use, how to call." I have found several articles, but didn't get the

Can any one explain about X-macros with example code to use them? [closed]

做~自己de王妃 提交于 2021-01-19 09:01:36
问题 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 7 years ago . Improve this question I am trying to understand the X-macros topic in detail. But didn't get the full clarity on this. It would be better if any one of the expert will explain this topic with some example "how to use, how to call." I have found several articles, but didn't get the

Use enum to determine type of return result ( a hack using Macro )

三世轮回 提交于 2019-12-25 14:01:42
问题 I have many types of game-object that are related together is some ways. All relations is implemented by Map<K1,K2> . #include <vector> using namespace std; template<class K1,class K2> class Map{ //N:N relation public: std::vector<K2*> getK2(K1* k1){/* some code */return std::vector<K2*>();} public: std::vector<K1*> getK1(K2* k2){/* some code */return std::vector<K1*>();} //... various function ... }; Here is the hub class GameRelation that facilitates all relation query :- (just an example,

Use enum to determine type of return result ( a hack using Macro )

雨燕双飞 提交于 2019-12-25 14:01:21
问题 I have many types of game-object that are related together is some ways. All relations is implemented by Map<K1,K2> . #include <vector> using namespace std; template<class K1,class K2> class Map{ //N:N relation public: std::vector<K2*> getK2(K1* k1){/* some code */return std::vector<K2*>();} public: std::vector<K1*> getK1(K2* k2){/* some code */return std::vector<K1*>();} //... various function ... }; Here is the hub class GameRelation that facilitates all relation query :- (just an example,

one #macro add a field and a case (in switch-case)

末鹿安然 提交于 2019-12-23 02:53:31
问题 How to define macro ( ALL_SWITCH ) to recognize another macro ( SINGLE_CASE ) occurrences as list, and insert codes into 2 different places? Is it possible? Example I want to create macro that have syntax roughly similar as :- SINGLE_CASE <Class Name> <Enum slot> //add fields ALL_SWITCH //recognize all calling SINGLE_CASE (see below) Below is the expected usage. TopHeader.h :- SINGLE_CASE Machine slot1 SINGLE_CASE Machine slot2 //^-------- will be replaced by below code (generate the whole

Can I append to a preprocessor macro?

↘锁芯ラ 提交于 2019-12-18 16:07:32
问题 Is there any way in standard C—or with GNU extensions—to append stuff to a macro definition? E.g. , given a macro defined as #define List foo bar can I append bas so that it List expands as if I’d defined it #define List foo bar bas ? I was hoping I could do something like this: #define List foo bar bas #define List_ Expand(List) #undef List #define List Expand(List_) quux but I can’t figure out how to define the Expand() macro so it’ll do what I want. Motivation: I’m playing with

Real-world use of X-Macros

ⅰ亾dé卋堺 提交于 2019-12-16 20:16:31
问题 I just learned of X-Macros. What real-world uses of X-Macros have you seen? When are they the right tool for the job? 回答1: I discovered X-macros a couple of years ago when I started making use of function pointers in my code. I am an embedded programmer and I use state machines frequently. Often I would write code like this: /* declare an enumeration of state codes */ enum{ STATE0, STATE1, STATE2, ... , STATEX, NUM_STATES}; /* declare a table of function pointers */ p_func_t jumptable[NUM

Concatenate multiple tokens for X macro

北慕城南 提交于 2019-12-11 06:18:11
问题 I'm trying to use X macros and preprocessor concatenation, both for the first time, together. I've read a lot of the other questions on SO related to preprocessor concatenation but not yet been able to wrap my head around them or how to adapt those to my use case. The list of items is a list of ID numbers for a bunch of structs , like so: #define LIST_OF_ID_NUMS \ X(1) \ X(2) \ X(3) \ X(4) \ X(5) \ X(6) \ X(7) \ X(8) \ X(9) \ X(10) \ X(11) I can declare the structs like so: #define X(id_num)