Let's look at the following quote from the C ++ 11 standard ( project N3376 , to be precise):
(2.14.8.5)
If L is a user-defined literal - string, let str be a literal without its ud-su ffi x and len the number of code units in str (i.e. its length, excluding the finite null character). The literal L is considered as a call of the form
operator "" X (str , len )
While for all other types of custom literals (floating point, integer, character), the length is never passed, even if the literal itself is passed as a string. For instance:
42_zzz; // calls operator "" _zzz("42") and not operator "" _zzz("42", 2)
Why is there such a difference between string and non-string user literals? Or should I say why the implementation is passed len to UD string literals? Length, as with other literals, can be inferred by null termination. What am I missing?
source share