Стандарт C++ 11 (1119564), страница 13
Текст из файла (страница 13)
The escape \xhhh consists of the backslash followed by x followed byone or more hexadecimal digits that are taken to specify the value of the desired character. There is no limitto the number of digits in a hexadecimal sequence. A sequence of octal or hexadecimal digits is terminatedby the first character that is not an octal digit or a hexadecimal digit, respectively. The value of a characterliteral is implementation-defined if it falls outside of the implementation-defined range defined for char (forliterals with no prefix), char16_t (for literals prefixed by ’u’), char32_t (for literals prefixed by ’U’), orwchar_t (for literals prefixed by ’L’).23) They are intended for character sets where a character does not fit into a single byte.24) Using an escape sequence for a question mark can avoid accidentally creating a trigraph.§ 2.14.3© ISO/IEC 2011 – All rights reserved27ISO/IEC 14882:2011(E)5A universal-character-name is translated to the encoding, in the appropriate execution character set, of thecharacter named.
If there is no such encoding, the universal-character-name is translated to an implementationdefined encoding. [ Note: In translation phase 1, a universal-character-name is introduced whenever an actualextended character is encountered in the source text. Therefore, all extended characters are described interms of universal-character-names. However, the actual compiler implementation may use its own nativecharacter set, so long as the same results are obtained. — end note ]2.14.4Floating literals[lex.fcon]floating-literal:fractional-constant exponent-partopt floating-suffixoptdigit-sequence exponent-part floating-suffixoptfractional-constant:digit-sequenceopt .
digit-sequencedigit-sequence .exponent-part:e signopt digit-sequenceE signopt digit-sequencesign: one of+ digit-sequence:digitdigit-sequence digitfloating-suffix: one off l F L1A floating literal consists of an integer part, a decimal point, a fraction part, an e or E, an optionally signedinteger exponent, and an optional type suffix. The integer and fraction parts both consist of a sequence ofdecimal (base ten) digits. Either the integer part or the fraction part (not both) can be omitted; either thedecimal point or the letter e (or E ) and the exponent (not both) can be omitted.
The integer part, theoptional decimal point and the optional fraction part form the significant part of the floating literal. Theexponent, if present, indicates the power of 10 by which the significant part is to be scaled. If the scaledvalue is in the range of representable values for its type, the result is the scaled value if representable, else thelarger or smaller representable value nearest the scaled value, chosen in an implementation-defined manner.The type of a floating literal is double unless explicitly specified by a suffix.
The suffixes f and F specifyfloat, the suffixes l and L specify long double. If the scaled value is not in the range of representablevalues for its type, the program is ill-formed.2.14.5String literals[lex.string]string-literal:encoding-prefixopt " s-char-sequenceopt "encoding-prefixopt R raw-stringencoding-prefix:u8uULs-char-sequence:s-chars-char-sequence s-char§ 2.14.528© ISO/IEC 2011 – All rights reservedISO/IEC 14882:2011(E)s-char:any member of the source character set exceptthe double-quote ", backslash \, or new-line characterescape-sequenceuniversal-character-nameraw-string:" d-char-sequenceopt ( r-char-sequenceopt ) d-char-sequenceopt "r-char-sequence:r-charr-char-sequence r-charr-char:any member of the source character set, excepta right parenthesis ) followed by the initial d-char-sequence(which may be empty) followed by a double quote ".d-char-sequence:d-chard-char-sequence d-chard-char:any member of the basic source character set except:space, the left parenthesis (, the right parenthesis ), the backslash \,and the control characters representing horizontal tab,vertical tab, form feed, and newline.1A string literal is a sequence of characters (as defined in 2.14.3) surrounded by double quotes, optionallyprefixed by R, u8, u8R, u, uR, U, UR, L, or LR, as in "...", R"(...)", u8"...", u8R"**(...)**", u"...",uR"*˜(...)*˜", U"...", UR"zzz(...)zzz", L"...", or LR"(...)", respectively.2A 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.3[ Note: The characters ’(’ and ’)’ are permitted in a raw-string. Thus, R"delimiter((a|b))delimiter"is equivalent to "(a|b)". — end note ]4[ Note: A source-file new-line in a raw string literal results in a new-line in the resulting execution stringliteral. Assuming no whitespace at the beginning of lines in the following example, the assert will succeed:const char *p = R"(a\bc)";assert(std::strcmp(p, "a\\\nb\nc") == 0);— end note ]5[ Example: The raw stringR"a()\a")a"is equivalent to "\n)\\\na\"\n".
The raw stringR"(??)"§ 2.14.5© ISO/IEC 2011 – All rights reserved29ISO/IEC 14882:2011(E)is equivalent to "\?\?". The raw stringR"#()??=")#"is equivalent to "\n)\?\?=\"\n". — end example ]6After translation phase 6, a string literal that does not begin with an encoding-prefix is an ordinary stringliteral, and is initialized with the given characters.7A string literal that begins with u8, such as u8"asdf", is a UTF-8 string literal and is initialized with thegiven characters as encoded in UTF-8.8Ordinary string literals and UTF-8 string literals are also referred to as narrow string literals.
A narrowstring literal has type “array of n const char”, where n is the size of the string as defined below, and hasstatic storage duration (3.7).9A string literal that begins with u, such as u"asdf", is a char16_t string literal. A char16_t string literalhas type “array of n const char16_t”, where n is the size of the string as defined below; it has static storageduration and is initialized with the given characters. A single c-char may produce more than one char16_tcharacter in the form of surrogate pairs.10A string literal that begins with U, such as U"asdf", is a char32_t string literal.
A char32_t string literalhas type “array of n const char32_t”, where n is the size of the string as defined below; it has static storageduration and is initialized with the given characters.11A string literal that begins with L, such as L"asdf", is a wide string literal. A wide string literal has type“array of n const wchar_t”, where n is the size of the string as defined below; it has static storage durationand is initialized with the given characters.12Whether all string literals are distinct (that is, are stored in nonoverlapping objects) is implementationdefined.
The effect of attempting to modify a string literal is undefined.13In translation phase 6 (2.2), adjacent string literals are concatenated. If both string literals have the sameencoding-prefix, the resulting concatenated string literal has that encoding-prefix. If one string literal hasno encoding-prefix, it is treated as a string literal of the same encoding-prefix as the other operand. If aUTF-8 string literal token is adjacent to a wide string literal token, the program is ill-formed. Any otherconcatenations are conditionally supported with implementation-defined behavior. [ Note: This concatenation is an interpretation, not a conversion. Because the interpretation happens in translation phase 6 (aftereach character from a literal has been translated into a value from the appropriate character set), a stringliteral’s initial rawness has no effect on the interpretation or well-formedness of the concatenation.
— endnote ] Table 8 has some examples of valid concatenations.Table 8 — String literal concatenationsSourceu"a" u"b"u"a" "b""a"u"b"Meansu"ab"u"ab"u"ab"SourceU"a" U"b"U"a" "b""a"U"b"MeansU"ab"U"ab"U"ab"SourceL"a" L"b"L"a" "b""a"L"b"MeansL"ab"L"ab"L"ab"Characters in concatenated strings are kept distinct.[ Example:"\xA" "B"§ 2.14.530© ISO/IEC 2011 – All rights reservedISO/IEC 14882:2011(E)contains the two characters ’\xA’ and ’B’ after concatenation (and not the single hexadecimal character’\xAB’). — end example ]14After any necessary concatenation, in translation phase 7 (2.2), ’\0’ is appended to every string literal sothat programs that scan a string can find its end.15Escape sequences and universal-character-names in non-raw string literals have the same meaning as incharacter literals (2.14.3), except that the single quote ’ is representable either by itself or by the escapesequence \’, and the double quote " shall be preceded by a \.
In a narrow string literal, a universal-charactername may map to more than one char element due to multibyte encoding. The size of a char32_t or widestring literal is the total number of escape sequences, universal-character-names, and other characters, plusone for the terminating U’\0’ or L’\0’. The size of a char16_t string literal is the total number of escapesequences, universal-character-names, and other characters, plus one for each character requiring a surrogatepair, plus one for the terminating u’\0’. [ Note: The size of a char16_t string literal is the number of codeunits, not the number of characters.
— end note ] Within char32_t and char16_t literals, any universalcharacter-names shall be within the range 0x0 to 0x10FFFF. The size of a narrow string literal is the totalnumber of escape sequences and other characters, plus at least one for the multibyte encoding of eachuniversal-character-name, plus one for the terminating ’\0’.2.14.6Boolean literals[lex.bool]boolean-literal:falsetrue1The Boolean literals are the keywords false and true. Such literals are prvalues and have type bool.2.14.7Pointer literals[lex.nullptr]pointer-literal:nullptr1The pointer literal is the keyword nullptr.