Basically, if I have this string:
"abcd"
I want to end up with the equivalent of:
'abcd'
at compile time. I have tried using macros, preprocessor magic, and Microsoft's charize operator (#@
), but none of them work correctly. The end result should allow me to do something like this:
template <long N> struct some_type {};
long whatever = STR_TO_MULTI_CHAR_LITERAL("abcd");
some_type<whatever> xyz;
Let us assume that we can forget about big/little endian for now, you could use a
constexpr
union
likeIf we need to consider endian, it becomes more complex. Also size of
long
could be 8, not 4.Another thought, if
long
is 32bit,char32_t char4b = U'\UAABBFFFF'
is supported in C++11. But then you need figure out the map fromA
to45
(hex value ofA
). Then castchar4b
tolong
.