Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ easy way to convert macro variable to wchar string literal

Tags:

c++

macros

In the following example, I would like to remove the std::wstring(std::widen(...)) part, but the '#' macro only returns a char string literal -- is there any way to accommodate a wchar?

#define FOO_MACRO(className)\
struct className##Factory : public OtherClass {\
// does some stuff here\
} className##Factory;\
someMap->add(std::wstring(std::widen(#className), className##Factory)))

How would I do the same thing using wchar?

like image 970
ash Avatar asked Feb 17 '23 11:02

ash


1 Answers

You use an L prefix on the string literal to make a wchar string literal:

#define CAT(A, B)   A##B
#define WSTRING(A)  CAT(L, #A)
like image 189
Chris Dodd Avatar answered Feb 20 '23 02:02

Chris Dodd