Стандарт C++ 11 (1119564), страница 14
Текст из файла (страница 14)
It is a prvalue of type std::nullptr_t. [ Note: std::nullptr_tis a distinct type that is neither a pointer type nor a pointer to member type; rather, a prvalue of this type isa null pointer constant and can be converted to a null pointer value or null member pointer value. See 4.10and 4.11. — end note ]2.14.8User-defined literals[lex.ext]user-defined-literal:user-defined-integer-literaluser-defined-floating-literaluser-defined-string-literaluser-defined-character-literaluser-defined-integer-literal:decimal-literal ud-suffixoctal-literal ud-suffixhexadecimal-literal ud-suffixuser-defined-floating-literal:fractional-constant exponent-partopt ud-suffixdigit-sequence exponent-part ud-suffixuser-defined-string-literal:string-literal ud-suffixuser-defined-character-literal:character-literal ud-suffix§ 2.14.8© ISO/IEC 2011 – All rights reserved31ISO/IEC 14882:2011(E)ud-suffix:identifier1If a token matches both user-defined-literal and another literal kind, it is treated as the latter.
[ Example:123_km is a user-defined-literal, but 12LL is an integer-literal. — end example ] The syntactic non-terminalpreceding the ud-suffix in a user-defined-literal is taken to be the longest sequence of characters that couldmatch that non-terminal.2A user-defined-literal is treated as a call to a literal operator or literal operator template (13.5.8).
Todetermine the form of this call for a given user-defined-literal L with ud-suffix X , the literal-operator-idwhose literal suffix identifier is X is looked up in the context of L using the rules for unqualified namelookup (3.4.1). Let S be the set of declarations found by this lookup.
S shall not be empty.3If L is a user-defined-integer-literal, let n be the literal without its ud-suffix. If S contains a literal operatorwith parameter type unsigned long long, the literal L is treated as a call of the formoperator "" X (n ULL)Otherwise, S shall contain a raw literal operator or a literal operator template (13.5.8) but not both. If Scontains a raw literal operator, the literal L is treated as a call of the formoperator "" X ("n")Otherwise (S contains a literal operator template), L is treated as a call of the formoperator "" X <’c1 ’, ’c2 ’, ... ’ck ’>()where n is the source character sequence c1 c2 ...ck .
[ Note: The sequence c1 c2 ...ck can only contain charactersfrom the basic source character set. — end note ]4If L is a user-defined-floating-literal, let f be the literal without its ud-suffix. If S contains a literal operatorwith parameter type long double, the literal L is treated as a call of the formoperator "" X (f L)Otherwise, S shall contain a raw literal operator or a literal operator template (13.5.8) but not both. If Scontains a raw literal operator, the literal L is treated as a call of the formoperator "" X ("f")Otherwise (S contains a literal operator template), L is treated as a call of the formoperator "" X <’c1 ’, ’c2 ’, ...
’ck ’>()where f is the source character sequence c1 c2 ...ck . [ Note: The sequence c1 c2 ...ck can only contain charactersfrom the basic source character set. — end note ]5If L is a user-defined-string-literal, let str be the literal without its ud-suffix and let len be the number ofcode units in str (i.e., its length excluding the terminating null character). The literal L is treated as a callof the formoperator "" X (str, len)6If L is a user-defined-character-literal, let ch be the literal without its ud-suffix.
S shall contain a literaloperator (13.5.8) whose only parameter has the type ch and the literal L is treated as a call of the formoperator "" X (ch)7[ Example:§ 2.14.832© ISO/IEC 2011 – All rights reservedISO/IEC 14882:2011(E)long double operator "" _w(long double);std::string operator "" _w(const char16_t*, size_t);unsigned operator "" _w(const char*);int main() {1.2_w;// calls operator "" _w(1.2L)u"one"_w;// calls operator "" _w(u"one", 3)12_w;// calls operator "" _w("12")"two"_w;// error: no applicable literal operator}— end example ]8In translation phase 6 (2.2), adjacent string literals are concatenated and user-defined-string-literals areconsidered string literals for that purpose. During concatenation, ud-suffixes are removed and ignored andthe concatenation process occurs as described in 2.14.5.
At the end of phase 6, if a string literal is the resultof a concatenation involving at least one user-defined-string-literal, all the participating user-defined-stringliterals shall have the same ud-suffix and that suffix is applied to the result of the concatenation.9[ Example:int main() {L"A" "B" "C"_x; // OK: same as L"ABC"_x"P"_x "Q" "R"_y;// error: two different ud-suffixes}— end example ]10Some identifiers appearing as ud-suffixes are reserved for future standardization (17.6.4.3.5). A programcontaining such a ud-suffix is ill-formed, no diagnostic required.§ 2.14.8© ISO/IEC 2011 – All rights reserved33ISO/IEC 14882:2011(E)3Basic concepts[basic]1[ Note: This Clause presents the basic concepts of the C++ language. It explains the difference between anobject and a name and how they relate to the value categories for expressions.
It introduces the conceptsof a declaration and a definition and presents C++’s notion of type, scope, linkage, and storage duration.The mechanisms for starting and terminating a program are discussed. Finally, this Clause presents thefundamental types of the language and lists the ways of constructing compound types from these. — endnote ]2[ Note: This Clause does not cover concepts that affect only a single part of the language.
Such conceptsare discussed in the relevant Clauses. — end note ]3An entity is a value, object, reference, function, enumerator, type, class member, template, template specialization, namespace, parameter pack, or this.4A name is a use of an identifier (2.11), operator-function-id (13.5), literal-operator-id (13.5.8), conversionfunction-id (12.3.2), or template-id (14.2) that denotes an entity or label (6.6.4, 6.1).5Every name that denotes an entity is introduced by a declaration. Every name that denotes a label isintroduced either by a goto statement (6.6.4) or a labeled-statement (6.1).6A variable is introduced by the declaration of a reference other than a non-static data member or of anobject.
The variable’s name denotes the reference or object.7Some names denote types or templates. In general, whenever a name is encountered it is necessary todetermine whether that name denotes one of these entities before continuing to parse the program thatcontains it. The process that determines this is called name lookup (3.4).8Two names are the same if— they are identifiers composed of the same character sequence, or— they are operator-function-ids formed with the same operator, or— they are conversion-function-ids formed with the same type, or— they are template-ids that refer to the same class or function (14.4), or— they are the names of literal operators (13.5.8) formed with the same literal suffix identifier.9A name used in more than one translation unit can potentially refer to the same entity in these translationunits depending on the linkage (3.5) of the name specified in each translation unit.3.11Declarations and definitions[basic.def ]A declaration (Clause 7) may introduce one or more names into a translation unit or redeclare namesintroduced by previous declarations.
If so, the declaration specifies the interpretation and attributes of thesenames. A declaration may also have effects including:— a static assertion (Clause 7),— controlling template instantiation (14.7.2),— use of attributes (Clause 7), and§ 3.134© ISO/IEC 2011 – All rights reservedISO/IEC 14882:2011(E)— nothing (in the case of an empty-declaration).2A declaration is a definition unless it declares a function without specifying the function’s body (8.4), itcontains the extern specifier (7.1.1) or a linkage-specification 25 (7.5) and neither an initializer nor a functionbody, it declares a static data member in a class definition (9.2, 9.4), it is a class name declaration (9.1), it isan opaque-enum-declaration (7.2), it is a template-parameter (14.1), it is a parameter-declaration (8.3.5) in afunction declarator that is not the declarator of a function-definition, or it is a typedef declaration (7.1.3),an alias-declaration (7.1.3), a using-declaration (7.3.3), a static_assert-declaration (Clause 7), an attributedeclaration (Clause 7), an empty-declaration (Clause 7), or a using-directive (7.3.4).[ Example: all but one of the following are definitions:int a;extern const int c = 1;int f(int x) { return x+a; }struct S { int a; int b; };struct X {int x;static int y;X(): x(0) { }};int X::y = 1;enum { up, down };namespace N { int d; }namespace N1 = N;X anX;////////////////defines adefines cdefines f and defines xdefines S, S::a, and S::bdefines Xdefines non-static data member xdeclares static data member ydefines a constructor of X//////////definesdefinesdefinesdefinesdefines//////////////declaresdeclaresdeclaresdeclaresdeclaresdeclaresdeclaresX::yup and downN and N::dN1anXwhereas these are just declarations:extern int a;extern const int c;int f(int);struct S;typedef int Int;extern X anotherX;using N::d;acfSIntanotherXd— end example ]3[ Note: In some circumstances, C++ implementations implicitly define the default constructor (12.1), copyconstructor (12.8), move constructor (12.8), copy assignment operator (12.8), move assignment operator (12.8), or destructor (12.4) member functions.
— end note ] [ Example: given#include <string>struct C {std::string s;};intCCb}// std::string is the standard library class (Clause 21)main() {a;b = a;= a;25) Appearing inside the braced-enclosed declaration-seq in a linkage-specification does not affect whether a declaration is adefinition.§ 3.1© ISO/IEC 2011 – All rights reserved35ISO/IEC 14882:2011(E)the implementation will implicitly define functions to make the definition of C equivalent tostruct C {std::string s;C() : s() { }C(const C& x): s(x.s) { }C(C&& x): s(static_cast<std::string&&>(x.s)) { }// : s(std::move(x.s)) { }C& operator=(const C& x) { s = x.s; return *this; }C& operator=(C&& x) { s = static_cast<std::string&&>(x.s); return *this; }// { s = std::move(x.s); return *this; }~C() { }};— end example ]4[ Note: A class name can also be implicitly declared by an elaborated-type-specifier (7.1.6.3).