为什么原始字符串文字的分隔符必须小于 16 个字符?
Why must the delimiters of raw string literals be under 16 chars?
以下程序无法编译:
#include <iostream>
int main() {
std::cout << R"RAW_STRING_LITERAL(
hello
world
)RAW_STRING_LITERAL";
}
错误: raw string delimiter longer than 16 characters
。
为什么对原始字符串定界符施加长度限制?
标准规定:
A string-literal that has an R in the prefix is a raw string literal.
The d-char-sequence serves as a delimiter. The terminating
d-char-sequence of a raw-string is the same sequence of characters as
the initial d-charsequence. A d-char-sequence shall consist of at most
16 characters
http://open-std.org/JTC1/SC22/WG21/docs/papers/2015/n4527.pdf
§ 2.13.5 第 28 页
标准中没有给出任何理由,但对我来说,这似乎是完全随机的限制,因为它对分隔符是什么绝对没有影响。
我能找到的关于原始字符串文字的最早提议是 N2146,作者是 Beman Dawes。它包含文本:
The maximum length of d-char-sequence shall be 16 characters.
这似乎是作者强加的任意限制,他可能认为 16 个字符足以在所有情况下创建明确的分隔符序列。
该提案还指出
The terminating d-char-sequence of a raw string literal shall be the same sequence of characters as the initial d-char-sequence
因此,符合规范的实现必须缓冲并处理 d-char-sequence 以确保两个序列匹配。 d-char-sequence 没有任何限制会不必要地增加实现该功能的复杂性。
以下程序无法编译:
#include <iostream>
int main() {
std::cout << R"RAW_STRING_LITERAL(
hello
world
)RAW_STRING_LITERAL";
}
错误: raw string delimiter longer than 16 characters
。
为什么对原始字符串定界符施加长度限制?
标准规定:
A string-literal that has an R in the prefix is a raw string literal. The d-char-sequence serves as a delimiter. The terminating d-char-sequence of a raw-string is the same sequence of characters as the initial d-charsequence. A d-char-sequence shall consist of at most 16 characters
http://open-std.org/JTC1/SC22/WG21/docs/papers/2015/n4527.pdf § 2.13.5 第 28 页
标准中没有给出任何理由,但对我来说,这似乎是完全随机的限制,因为它对分隔符是什么绝对没有影响。
我能找到的关于原始字符串文字的最早提议是 N2146,作者是 Beman Dawes。它包含文本:
The maximum length of d-char-sequence shall be 16 characters.
这似乎是作者强加的任意限制,他可能认为 16 个字符足以在所有情况下创建明确的分隔符序列。
该提案还指出
The terminating d-char-sequence of a raw string literal shall be the same sequence of characters as the initial d-char-sequence
因此,符合规范的实现必须缓冲并处理 d-char-sequence 以确保两个序列匹配。 d-char-sequence 没有任何限制会不必要地增加实现该功能的复杂性。