Question

C++11 introduced the new string literals for UTF-8, 16 and 32 with the u8, u and U prefixes but I have to hard code which one I want to use. I'm looking for a way to select which encoding I want to use at compile time (similar to how a typedef works).

User defined string literals don't seem to help as they work on the strings of the specified encoding.

I have seen in pre C++11 code the use of a short macro such as L("string") to choose between "string" and L"string" but personally I find that quite ugly.

Is it possible to neatly choose the default type and encoding or will I have to use the macro option?

Was it helpful?

Solution

Unfortunately the solution to this problem is to use the macros. Although @Nadim Farhat pointed out that you can do a certain amount of choosing with gcc it is by no means a portable solution.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top