mercredi 27 mai 2015

C++ raw character literal

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?

  • Did the Raw character literals exists? (I've not found nothing about them so I'm nearly sure that they don't)
    • If they exists: How I should write a Raw character literal?
    • If they don't exist: Why? Is there a reason to add Raw string literals but AVOID to add Raw character literals?

Thanks!

Aucun commentaire:

Enregistrer un commentaire