1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#include <boost/preprocessor.hpp>
// la liste unique où positionner les différentes valeurs
#define LISTE_CHAINES\
(str1)\
(str2)\
(str3)\
(str4)\
(str5)\
(str6)\
// macro pour definir l'enum
#define DEFINIR_ENUM(unused_1,unused_2,elem) BOOST_PP_CAT(e_,elem),
// macro pour definir les chaines de caractères
#define DEFINIR_CHAINES(unused_1,unused_2,elem) BOOST_PP_STRINGIZE(elem),
// definition de l'enum
enum myenum {
BOOST_PP_SEQ_FOR_EACH(DEFINIR_ENUM,~,LISTE_CHAINES)
e_end
};
// definition du tableau de chaines
const char *mystr[e_end]={
BOOST_PP_SEQ_FOR_EACH(DEFINIR_CHAINES,~,LISTE_CHAINES)
};
// undef de ce dont on n'a plus besoin
#undef DEFINIR_CHAINES
#undef DEFINIR_ENUM
#undef LISTE_CHAINES |
Partager