I don't know if I've missed something or it really doesn't exists. In the C++11 standard the Raw string literals were added:
string s = "\\w\\\\\\w"; // I hope I got that right
string s = R"(\w\\\w)"; // I'm pretty sure I got that right
But all my attempts to use a Raw character literal have failed:
constexpr char bslash = R('\'); // error: missing terminating ' character
constexpr char bslash = R'(\)'; // error: 'R' was not declared in this scope
The second attempt is considered a multi-character constant! The only way I've found to use something similar to Raw character literal is:
constexpr char slash = *R"(\)"; // All Ok.
But I don't like this notation (dereferencing a string literal in order to store a copy of the first element) because is kind of confusing.
Well, what's the question?
The proposal that introduced raw string literals in C++11 is, as far as I can tell, N2442 - Raw and Unicode String Literals; Unified Proposal. It is based upon N2146 - Raw String Literals (Revision 1) by Beman Dawes, which contains a section about raw character literals:
As a deliberate design choice, raw character (as opposed to string) literals are not proposed because there is no apparent need; escape sequences do not pose the same practical problems in character literals that they do in string literals.
The arguments in favor of raw character literals are symmetry and error-reduction. Knowing that raw string-literals are allowed, programmers are likely to assume raw character-literals are also available. Indeed, a committee member inadvertently made that assumption when reading a draft of this paper. Although the resulting error is easy to fix, there is the argument that it is better to eliminate the possibility of the error by providing raw character-literals in the first place.
I will be happy to provide proposed wording if the committee desires to add raw character literals.
Unfortunately, I cannot find any discussion in the meeting minutes that mention any of the related proposals. It is likely though that the reason mentioned first paragraph lead to the current situation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With