让我们考虑以下来自C++11标准(确切地说是N3376版)的引用:
(2.14.8.5)
If L is a user-defined-string-literal, let str be the literal without its ud-suffix and let len be the number of code units in str (i.e., its length excluding the terminating null character). The literal L is treated as a call of the form
operator "" X (str , len )
然而,对于所有其他类型的用户定义字面量(浮点数、整数、字符),即使字面量本身以字符串形式传递,其长度也永远不会被传递。例如:
42_zzz; // calls operator "" _zzz("42") and not operator "" _zzz("42", 2)
为什么要区分字符串和非字符串用户自定义字面值?或者说,为什么实现在 UD 字符串字面值中传递 len? 就像其他字面值一样,长度可以通过空终止符来推断。我漏掉了什么吗?
\0
。 - Mat