Skip to content

Instantly share code, notes, and snippets.

@Cylix
Created October 19, 2020 06:00
Show Gist options
  • Save Cylix/74d13fbe6bdfdfebbab2c7dc35d34c8b to your computer and use it in GitHub Desktop.
Save Cylix/74d13fbe6bdfdfebbab2c7dc35d34c8b to your computer and use it in GitHub Desktop.
Reflection in C++14 - Macros #2
//! macro to convert any kind of value to string
#define __REFLEX_TO_STRING(val) #val
//! macro called for each member function to build a pair of <string, member_function_pointer>
#define __REFLEX_MAKE_REGISTERABLE_FUNCTION(r, type, i, function) \
BOOST_PP_COMMA_IF(i) std::make_pair(std::string(__REFLEX_TO_STRING(function)), &type::function)
//! main macro who build the static variable
#define REGISTER_CLASS(type, functions) \
static reflectable<type> \
reflectable_##type(#type, BOOST_PP_SEQ_FOR_EACH_I( __REFLEX_MAKE_REGISTERABLE_FUNCTION, \
type, \
functions ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment