In a nutshell:
It's possible to convert macro parameter to character string literal (that contains the spelling of the preprocessing token sequence for the corresponding argument, regarding to 16.3.2, n3797) with # operator. Is there a way, some trick, maybe, to convert macro parameter to multibyte character ? So, for example, I will have some macro TO_CHAR(WHATEWER) and TO_CHAR(CONSTANT) will give me 'CONSTANT' multibyte character ?
I need this to work with boost::mpl::string
. More precisely, I think so:
I have a lot of constants and I work with them with boost::mpl::vector
(boost::mpl::vector_c
). Now, I need to print out the name of constant after some work with this constant. Pseudo-pseudo code:
struct Temp
{
template<typename Value>
operator()(Value)
{
// ...
std::cout << "The value of " << @Value::value Name << " is " << Value::value;
};
};
typedef boost::mpl::vector_c<int, MY_CONST1, MY_CONST2> Constants;
boost::mpl::for_each<Constants>(Temp());
The output must be something like this:
The value of MY_CONST1 is 1
The value of MY_CONST2 is 2
I don't want to make some runtime array with a lot of typing:
typedef boost::mpl::vector_c<int, MY_CONST1, MY_CONST2> Constants;
const char* constant_names[] = { "MY_CONST1", "MY_CONST2" };
// Work with this stuff
What I want to have is something like this:
#define MAP_CONST(CONST) boost::mpl::pair<boost::mpl::int_<CONST>, (boost::mpl::string maybe here) #CONST>
typedef boost::mpl::vector<MAP_CONST(MY_CONST1), MAP_CONST(MY_CONST2)> Constants;
// Work with @Constants
Btw, I can't use constexp or new standard in general - I have C++03 compiler.
Thanks
UPD: Sorry for my mismatch - I mean not multibyte character, but "multicharacter literal" (regarding standard - 2.14.3, n3797). Somrthing like this