//---------------------------------------------------------------------------- #ifndef GMCG_ENUM_HELPER_HPP_20020108 #define GMCG_ENUM_HELPER_HPP_20020108 //---------------------------------------------------------------------------- #include #include #include #include #include //---------------------------------------------------------------------------- #define MAKE_ENUM(TYPE_NAME,LIST) \ enum TYPE_NAME { BOOST_PP_LIST_ENUM(LIST) }; \ std::ostream& operator<<(std::ostream& os, TYPE_NAME e) \ { \ switch(e) \ { \ BOOST_PP_LIST_FOR_EACH(MAKE_ENUM_AUX, _, LIST) \ default: \ return os << "unknown"; \ } \ } #define MAKE_ENUM_AUX(R,_,ELEM) \ case ELEM: return os << BOOST_PP_STRINGIZE(ELEM); //---------------------------------------------------------------------------- /* example use: #include #include "enum_helper.hpp" MAKE_ENUM (event_type, BOOST_PP_TUPLE_TO_LIST (4, (read_event, write_event, timeout_event, error_event))) int main() { std::cout << read_event << std::endl; std::cout << write_event << std::endl; std::cout << timeout_event << std::endl; std::cout << error_event << std::endl; } */ //---------------------------------------------------------------------------- #endif // GMCG_ENUM_HELPER_HPP_20020108 //----------------------------------------------------------------------------