Commit 1ac16f92 authored by daminetreg's avatar daminetreg

FEATURE: don't specify enum name twice.

parent 0073ac33
#include <type_traits>
#include <iostream>
#define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
......@@ -89,9 +90,19 @@ using enum_strval =
template <class enum_parse_result, int x>
using enum_as_cstr = typename boost::mpl::c_str< typename enum_strval< enum_parse_result, x >::type >::type;
#define SMART_ENUM(name, ENUMDECL) \
BOOST_PP_REMOVE_PARENS(ENUMDECL); \
using BOOST_PP_CAT(adapted_, name) = enum_parser::apply<MPLLIBS_STRING(#ENUMDECL)>::type;
template <class adapted_enum_type>
struct adapted_enum;
#define SMART_ENUM(name, ENUMDECL) \
BOOST_PP_REMOVE_PARENS(ENUMDECL); \
\
template <> \
struct adapted_enum<name> { \
typedef enum_parser::apply<MPLLIBS_STRING(#ENUMDECL)>::type parsed_enum; \
};
SMART_ENUM(banana, (
......@@ -108,16 +119,17 @@ SMART_ENUM(test, (
int main(int argc, const char** argv) {
using namespace boost::mpl;
std::cout << "There are " << get_enum_entry_count<adapted_banana>::value << " identifiers. " << std::endl;
std::cout << "Enum as string is " << enum_as_cstr<adapted_banana, int(banana::first)>::value << std::endl;
std::cout << "Enum as string is " << enum_as_cstr< adapted_banana, int(banana::second)>::value << std::endl;
std::cout << "There are " << get_enum_entry_count<adapted_test>::value << " identifiers. " << std::endl;
std::cout << "Enum as string is " << enum_as_cstr<adapted_test, int(test::Oh)>::value << std::endl;
std::cout << "Enum as string is " << enum_as_cstr<adapted_test, int(test::Yeah)>::value << std::endl;
std::cout << "Enum as string is " << enum_as_cstr<adapted_test, int(test::Cool)>::value << std::endl;
std::cout << "Enum as string is " << enum_as_cstr<adapted_test, 1>::value << std::endl;
std::cout << "There are " << get_enum_entry_count<adapted_enum<banana>::parsed_enum>::value << " identifiers. " << std::endl;
//std::cout << "Enum as string is " << to_string(banana::first) << std::endl;
//std::cout << "Enum as string is " << to_string(banana::second) << std::endl;
std::cout << "Enum as string is " << enum_as_cstr< adapted_enum<banana>::parsed_enum, int(banana::second)>::value << std::endl;
//
//std::cout << "There are " << get_enum_entry_count<adapted_test>::value << " identifiers. " << std::endl;
//std::cout << "Enum as string is " << enum_as_cstr<adapted_test, int(test::Oh)>::value << std::endl;
//std::cout << "Enum as string is " << enum_as_cstr<adapted_test, int(test::Yeah)>::value << std::endl;
//std::cout << "Enum as string is " << enum_as_cstr<adapted_test, int(test::Cool)>::value << std::endl;
//
//std::cout << "Enum as string is " << enum_as_cstr<adapted_test, 1>::value << std::endl;
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment