Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <boost/preprocessor/comparison/greater.hpp>
- #include <boost/preprocessor/punctuation/comma_if.hpp>
- #include <boost/preprocessor/seq/enum.hpp>
- #include <boost/preprocessor/seq/for_each.hpp>
- #include <boost/preprocessor/stringize.hpp>
- #define TOK_ENUM(ENUM_NAME, ENUM_SEQ) \
- enum ENUM_NAME { BOOST_PP_SEQ_ENUM(ENUM_SEQ), BOOST_PP_CAT(NUM_, ENUM_NAME) };
- #define TOK_HELPER(r, data, elem) \
- BOOST_PP_COMMA_IF(BOOST_PP_GREATER(r,2)) BOOST_PP_STRINGIZE(elem)
- #define TOK_NAMES(STRING_NAME, ENUM_SEQ) \
- const char* const STRING_NAME[] = { BOOST_PP_SEQ_FOR_EACH(TOK_HELPER, ~, ENUM_SEQ) };
- #define TOK_SEQ (comment)(identifier)(string_literal)(char_constant)
- int main()
- {
- TOK_ENUM(TokKind, TOK_SEQ);
- TOK_NAMES(tokNames, TOK_SEQ);
- std::cout << tokNames[identifier] << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement