C++ convert string literal to multi-character literal at compile time -
basically, if have string:
"abcd"
i want end equivalent of:
'abcd'
at compile time. have tried using macros, preprocessor magic, , microsoft's charize operator (#@
), none of them work correctly. end result should allow me this:
template <long n> struct some_type {}; long whatever = str_to_multi_char_literal("abcd"); some_type<whatever> xyz;
let assume can forget big/little endian now, use constexpr
union
union dirty_hack { long l; char[4] chars; };
if need consider endian, becomes more complex. size of long
8, not 4.
another thought, if long
32bit, char32_t char4b = u'\uaabbffff'
supported in c++11. need figure out map a
45
(hex value of a
). cast char4b
long
.
Comments
Post a Comment