Choose default type and encoding for C ++ string literals at compile time

C ++ 11 introduced new string literals for UTF-8, 16, and 32 with the prefixes u8 , u and u , but I need to hardcode what I want to use. I am looking for a way to choose which encoding I want to use at compile time (similar to how typedef works).

Custom string literals don't seem to help, since they work with strings of the specified encoding.

I saw in pre C ++ 11 code using a short macro such as L("string") to choose between "string" and L"string" , but personally I find it pretty ugly.

Can I carefully select the default type and encoding, or do I have to use the macro parameter?

+4
source share
1 answer

Unfortunately, the solution to this problem is to use macros. Although @Nadim Farhat pointed out that you can make a specific selection using gcc, this is by no means a portable solution.

0
source

Source: https://habr.com/ru/post/1495310/


All Articles