This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: CPP (preprocessor) quandry
Hi Buddy,
Thanks for the idea!
This "two-part macro" trick will work:
#define $MkEnum(name$) \
struct name$ {\
typedef enum {
#define $EndEnum(name$) \
} Type;\
Type m;\
name$(Type in) : m(in) { }\
operator Type () const { return m; }\
}
In use:
$MkEnum(Marx)
Groucho, Chico, Harpo, Gummo, Zeppo, Karl = 86
$EndEnum(Marx);
Voila! Slightly awkward, but acceptable. It could all be put on one line,
but I'm not sure if that'd be better or worse.
Note: C++ only, no C.
Thanks,
--Eljay