Yep, that is annoying. Perhaps there should be raw literals (R"PREFIX("
) and multiline raw literals (M"PREFIX
).
I came up with this alternative which almost describes itself:
#include<iterator> // std::next
...
{
...
...
std::string atoms_text =
std::next/*_line*/(R"XYZ(
O123 12.4830720891 13.1055820441 9.5288258996
O123 13.1055820441 13.1055820441 9.5288258996
)XYZ");
assert( atoms_text[0] != '\n' );
...
}
Limitations:
- If the raw literal is empty it will generate an invalid string. But that should be obvious to spot.
- If the raw literal doesn't start with a new line it will eat the first character instead.
std::next
is constexpr
only from C++17, you then can use 1+(char const*)R"XYZ("
but it is not as clear and might produce warning.
constexpr auto atom_text = 1 + (R"XYZ(
O123 12.4830720891 13.1055820441 9.5288258996
O123 13.1055820441 13.1055820441 9.5288258996
)XYZ");
Also, no warranties ;) . After all, I don't know if it is legal to do arithmetic with pointers to static data.
Another advantage of the + 1
approach is that it can be put at the end:
constexpr auto atom_text = R"XYZ(
O123 12.4830720891 13.1055820441 9.5288258996
O123 13.1055820441 13.1055820441 9.5288258996
)XYZ" + 1;
Possibilities are endless:
constexpr auto atom_text = &R"XYZ(
O123 12.4830720891 13.1055820441 9.5288258996
O123 13.1055820441 13.1055820441 9.5288258996
)XYZ"[1];
constexpr auto atom_text = &1[R"XYZ(
O123 12.4830720891 13.1055820441 9.5288258996
O123 13.1055820441 13.1055820441 9.5288258996
)XYZ"];