Skip to content

Instantly share code, notes, and snippets.

@Yacoby
Created November 12, 2013 14:00
Show Gist options
  • Save Yacoby/7431255 to your computer and use it in GitHub Desktop.
Save Yacoby/7431255 to your computer and use it in GitHub Desktop.
#include <string>
#include <sstream>
#include <boost/preprocessor/iteration/local.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#define YAC_PLUS() +
#define YAC_PLUS_IF(cond) BOOST_PP_IF(cond, YAC_PLUS, BOOST_PP_EMPTY)()
#define YAC_ENUM_TP(count, param) BOOST_PP_REPEAT(count, YAC_ENUM_TP_M, param)
#define YAC_ENUM_TP_M(z, n, param) BOOST_PP_COMMA_IF(n) const T ## n & param ## n
#define YAC_PRINT_ADDITION(count, param) BOOST_PP_REPEAT(count, YAC_PRINT_ADDITION_M, param)
#define YAC_PRINT_ADDITION_M(z, n, param) YAC_PLUS_IF(n) _toString( param ## n )
#define BOOST_PP_LOCAL_MACRO(n) \
template<BOOST_PP_ENUM_PARAMS(n, class T)> std::string toString( YAC_ENUM_TP(n, v) ){ \
return \
YAC_PRINT_ADDITION(n, v)\
;\
};
#define BOOST_PP_LOCAL_LIMITS (1, 32)
#include BOOST_PP_LOCAL_ITERATE()
template <typename T> std::string _toString(const T& c){
std::ostringstream oss;
oss << c;
return oss.str();
}
template <> std::string _toString<std::string>(const std::string& c){
return c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment