I use the following macros in my code:
#define MAKE_FLAG_TYPE1(TYPE_NAME, F1) \
enum TYPE_NAME { F1 }; \
\
::std::ostream& operator<<(::std::ostream& os, TYPE_NAME f) \
\
switch(f) \
{ \
case F1: return os << #F1; \
} \
return os << "unknown"; \
}
[2, 3 and 4 argument versions]
#define MAKE_FLAG_TYPE5(TYPE_NAME, F1, F2, F3, F4, F5) \
enum TYPE_NAME { F1, F2, F3, F4, F5 }; \
\
::std::ostream& operator<<(::std::ostream& os, TYPE_NAME f) \
{ \
switch(f) \
{ \
case F1: return os << #F1; \
case F2: return os << #F2; \
case F3: return os << #F3; \
case F4: return os << #F4; \
case F5: return os << #F5; \
} \
return os << "unknown"; \
}
I wanted to try and do it with the Preprocessor library. It should be
something like this:
#include
On 12/17/01 7:00 PM, "Gustavo Guerra"
So, does anyone has any suggestions on how to implement my MAKE_FLAG_TYPE<N> macros using the Preprocessor library? Or is it just not possible?
The underlying issue is that you can't use a macro to define a macro. That just how the C and C++ language macros work. So #define X #define Y 1 X will not allow you to define Y by invoking X. You'll just get a syntax error when the compiler sees the "#define" after expanding X. I think the answer then is that it's just not possible, although there still may be some creative way to use the PREPROCESSOR library to help with what you are trying to do. -- Darin
gustavo -- the only way is to run the preprocessor, cpp, explicitly. then you can run it twice to fully expand the code darin shows below, once explicitly and once implicitly by running the compiler. -- chuck Darin Adler wrote:
On 12/17/01 7:00 PM, "Gustavo Guerra"
wrote: So, does anyone has any suggestions on how to implement my MAKE_FLAG_TYPE<N> macros using the Preprocessor library? Or is it just not possible?
The underlying issue is that you can't use a macro to define a macro. That just how the C and C++ language macros work.
So
#define X #define Y 1 X
will not allow you to define Y by invoking X. You'll just get a syntax error when the compiler sees the "#define" after expanding X.
I think the answer then is that it's just not possible, although there still may be some creative way to use the PREPROCESSOR library to help with what you are trying to do.
-- Darin
-- |\_/\_.-'""``:-._ What is life without looking for . . `; -._ )-;-,_`) the next cute little bug to play with? v_,- _ ),(,.\ ``-' _.- _.,-_/ / ((.' -- chuck.siska@conexant.com `<}:.. ((,.-' ((,/
----- Original Message -----
From: "Darin Adler"
The underlying issue is that you can't use a macro to define a macro. That just how the C and C++ language macros work.
So
#define X #define Y 1 X
will not allow you to define Y by invoking X. You'll just get a syntax error when the compiler sees the "#define" after expanding X.
I think the answer then is that it's just not possible, although there still may be some creative way to use the PREPROCESSOR library to help with what you are trying to do.
I has hoping that there was some obscure trick to make the preprocessor
reprocess that part, but I guess not.
So, I tried this, based on http://groups.yahoo.com/group/boost/message/21743
#include
participants (3)
-
Chuck Siska
-
Darin Adler
-
Gustavo Guerra