16 Library introduction [library]

16.3 Method of description [description]

16.3.1 General [description.general]

Subclause [description] describes the conventions used to specify the C++ standard library.
[structure] describes the structure of [support] through [exec] and [depr].
[conventions] describes other editorial conventions.

16.3.2 Structure of each clause [structure]

16.3.2.1 Elements [structure.elements]

Each library clause contains the following elements, as applicable:136
136)136)
To save space, items that do not apply to a Clause are omitted.
For example, if a Clause does not specify any requirements, there will be no “Requirements” subclause.

16.3.2.2 Summary [structure.summary]

The Summary provides a synopsis of the category, and introduces the first-level subclauses.
Each subclause also provides a summary, listing the headers specified in the subclause and the library entities provided in each header.
The contents of the summary and the detailed specifications include:

16.3.2.3 Requirements [structure.requirements]

Requirements describe constraints that shall be met by a C++ program that extends the standard library.
Such extensions are generally one of the following:
  • Template arguments
  • Derived classes
  • Containers, iterators, and algorithms that meet an interface convention or model a concept
The string and iostream components use an explicit representation of operations required of template arguments.
They use a class template char_traits to define these constraints.
Interface convention requirements are stated as generally as possible.
Instead of stating “class X has to define a member function operator++()”, the interface requires “for any object x of class X, ++x is defined”.
That is, whether the operator is a member is unspecified.
Requirements are stated in terms of well-defined expressions that define valid terms of the types that meet the requirements.
For every set of well-defined expression requirements there is either a named concept or a table that specifies an initial set of the valid expressions and their semantics.
Any generic algorithm ([algorithms]) that uses the well-defined expression requirements is described in terms of the valid expressions for its template type parameters.
The library specification uses a typographical convention for naming requirements.
Names in italic type that begin with the prefix Cpp17 refer to sets of well-defined expression requirements typically presented in tabular form, possibly with additional prose semantic requirements.
For example, Cpp17Destructible (Table 35) is such a named requirement.
Names in constant width type refer to library concepts which are presented as a concept definition ([temp]), possibly with additional prose semantic requirements.
For example, destructible ([concept.destructible]) is such a named requirement.
Template argument requirements are sometimes referenced by name.
In some cases the semantic requirements are presented as C++ code.
Such code is intended as a specification of equivalence of a construct to another construct, not necessarily as the way the construct must be implemented.137
Required operations of any concept defined in this document need not be total functions; that is, some arguments to a required operation may result in the required semantics failing to be met.
[Example 1: 
The required < operator of the totally_ordered concept ([concept.totallyordered]) does not meet the semantic requirements of that concept when operating on NaNs.
— end example]
This does not affect whether a type models the concept.
A declaration may explicitly impose requirements through its associated constraints ([temp.constr.decl]).
When the associated constraints refer to a concept ([temp.concept]), the semantic constraints specified for that concept are additionally imposed on the use of the declaration.
137)137)
Although in some cases the code given is unambiguously the optimum implementation.

16.3.2.4 Detailed specifications [structure.specifications]

The detailed specifications each contain the following elements:
  • name and brief description
  • synopsis (class definition or function declaration, as appropriate)
  • restrictions on template arguments, if any
  • description of class invariants
  • description of function semantics
Descriptions of class member functions follow the order (as appropriate):138
  • constructor(s) and destructor
  • copying, moving & assignment functions
  • comparison operator functions
  • modifier functions
  • observer functions
  • operators and other non-member functions
Descriptions of function semantics contain the following elements (as appropriate):139
  • Constraints: the conditions for the function's participation in overload resolution ([over.match]).
    [Note 1: 
    Failure to meet such a condition results in the function's silent non-viability.
    — end note]
    [Example 1: 
    An implementation can express such a condition via a constraint-expression ([temp.constr.decl]).
    — end example]
  • Mandates: the conditions that, if not met, render the program ill-formed.
    [Example 2: 
    An implementation can express such a condition via the constant-expression in a static_assert-declaration ([dcl.pre]).
    If the diagnostic is to be emitted only after the function has been selected by overload resolution, an implementation can express such a condition via a constraint-expression ([temp.constr.decl]) and also define the function as deleted.
    — end example]
  • Preconditions: the conditions that the function assumes to hold whenever it is called; violation of any preconditions results in undefined behavior.
  • Effects: the actions performed by the function.
  • Synchronization: the synchronization operations ([intro.multithread]) applicable to the function.
  • Postconditions: the conditions (sometimes termed observable results) established by the function.
  • Result: for a typename-specifier, a description of the named type; for an expression, a description of the type and value category of the expression; the expression is an lvalue if the type is an lvalue reference type, an xvalue if the type is an rvalue reference type, and a prvalue otherwise.
  • Returns: a description of the value(s) returned by the function.
  • Throws: any exceptions thrown by the function, and the conditions that would cause the exception.
  • Complexity: the time and/or space complexity of the function.
  • Remarks: additional semantic constraints on the function.
  • Error conditions: the error conditions for error codes reported by the function.
Whenever the Effects element specifies that the semantics of some function F are Equivalent to some code sequence, then the various elements are interpreted as follows.
If F's semantics specifies any Constraints or Mandates elements, then those requirements are logically imposed prior to the equivalent-to semantics.
Next, the semantics of the code sequence are determined by the Constraints, Mandates, Preconditions, Effects, Synchronization, Postconditions, Returns, Throws, Complexity, Remarks, and Error conditions specified for the function invocations contained in the code sequence.
The value returned from F is specified by F's Returns element, or if F has no Returns element, a non-void return from F is specified by the return statements ([stmt.return]) in the code sequence.
If F's semantics contains a Throws, Postconditions, or Complexity element, then that supersedes any occurrences of that element in the code sequence.
For non-reserved replacement and handler functions, [support] specifies two behaviors for the functions in question: their required and default behavior.
The default behavior describes a function definition provided by the implementation.
The required behavior describes the semantics of a function definition provided by either the implementation or a C++ program.
Where no distinction is explicitly made in the description, the behavior described is the required behavior.
If the formulation of a complexity requirement calls for a negative number of operations, the actual requirement is zero operations.140
Complexity requirements specified in the library clauses are upper bounds, and implementations that provide better complexity guarantees meet the requirements.
Error conditions specify conditions where a function may fail.
The conditions are listed, together with a suitable explanation, as the enum class errc constants ([syserr]).
138)138)
To save space, items that do not apply to a class are omitted.
For example, if a class does not specify any comparison operator functions, there will be no “Comparison operator functions” subclause.
139)139)
To save space, elements that do not apply to a function are omitted.
For example, if a function specifies no preconditions, there will be no Preconditions: element.
140)140)
This simplifies the presentation of complexity requirements in some cases.

16.3.2.5 C library [structure.see.also]

Paragraphs labeled “See also” contain cross-references to the relevant portions of other standards ([intro.refs]).

16.3.3 Other conventions [conventions]

16.3.3.1 General [conventions.general]

Subclause [conventions] describes several editorial conventions used to describe the contents of the C++ standard library.
These conventions are for describing implementation-defined types, and member functions.

16.3.3.2 Exposition-only entities, etc. [expos.only.entity]

Several entities and typedef-names defined in [support] through [exec] and [depr] are only defined for the purpose of exposition.
The declaration of such an entity or typedef-name is followed by a comment ending in exposition only.
The following are defined for exposition only to aid in the specification of the library: namespace std { template<class T> requires convertible_to<T, decay_t<T>> constexpr decay_t<T> decay-copy(T&& v) // exposition only noexcept(is_nothrow_convertible_v<T, decay_t<T>>) { return std::forward<T>(v); } constexpr auto synth-three-way = // exposition only []<class T, class U>(const T& t, const U& u) requires requires { { t < u } -> boolean-testable; { u < t } -> boolean-testable; } { if constexpr (three_way_comparable_with<T, U>) { return t <=> u; } else { if (t < u) return weak_ordering::less; if (u < t) return weak_ordering::greater; return weak_ordering::equivalent; } }; template<class T, class U=T> using synth-three-way-result = // exposition only decltype(synth-three-way(declval<T&>(), declval<U&>())); }
An object dst is said to be decay-copied from a subexpression src if the type of dst is decay_t<decltype((src))>

16.3.3.3 Type descriptions [type.descriptions]

16.3.3.3.1 General [type.descriptions.general]

The Requirements subclauses may describe names that are used to specify constraints on template arguments.141
These names are used in library Clauses to describe the types that may be supplied as arguments by a C++ program when instantiating template components from the library.
Certain types defined in [input.output] are used to describe implementation-defined types.
They are based on other types, but with added constraints.
141)141)
Examples from [utility.requirements] include: Cpp17EqualityComparable, Cpp17LessThanComparable, Cpp17CopyConstructible.
Examples from [iterator.requirements] include: Cpp17InputIterator, Cpp17ForwardIterator.

16.3.3.3.2 Enumerated types [enumerated.types]

Several types defined in [input.output] are enumerated types.
Each enumerated type may be implemented as an enumeration or as a synonym for an enumeration.142
The enumerated type enumerated can be written: enum enumerated { , , , , }; inline const (); inline const (); inline const (); inline const (); ⋮
Here, the names , , etc. represent enumerated elements for this particular enumerated type.
All such elements have distinct values.
142)142)
Such as an integer type, with constant integer values ([basic.fundamental]).

16.3.3.3.3 Bitmask types [bitmask.types]

Several types defined in [support] through [exec] and [depr] are bitmask types.
Each bitmask type can be implemented as an enumerated type that overloads certain operators, as an integer type, or as a bitset.
The bitmask type bitmask can be written: // For exposition only. // int_type is an integral type capable of representing all values of the bitmask type. enum bitmask : int_type { = 1 << 0, = 1 << 1, = 1 << 2, = 1 << 3, }; inline constexpr (); inline constexpr (); inline constexpr (); inline constexpr (); ⋮ constexpr bitmask operator&(bitmask X, bitmask Y) { return static_cast<bitmask>( static_cast<int_type>(X) & static_cast<int_type>(Y)); } constexpr bitmask operator|(bitmask X, bitmask Y) { return static_cast<bitmask>( static_cast<int_type>(X) | static_cast<int_type>(Y)); } constexpr bitmask operator^(bitmask X, bitmask Y) { return static_cast<bitmask>( static_cast<int_type>(X) ^ static_cast<int_type>(Y)); } constexpr bitmask operator~(bitmask X) { return static_cast<bitmask>(~static_cast<int_type>(X)); } bitmask& operator&=(bitmask& X, bitmask Y) { X = X & Y; return X; } bitmask& operator|=(bitmask& X, bitmask Y) { X = X | Y; return X; } bitmask& operator^=(bitmask& X, bitmask Y) { X = X ^ Y; return X; }
Here, the names , , etc. represent bitmask elements for this particular bitmask type.
All such elements have distinct, nonzero values such that, for any pair and where i  ≠ j, & is nonzero and & is zero.
Additionally, the value 0 is used to represent an empty bitmask, in which no bitmask elements are set.
The following terms apply to objects and values of bitmask types:
  • To set a value Y in an object X is to evaluate the expression X |= Y.
  • To clear a value Y in an object X is to evaluate the expression X &= ~Y.
  • The value Y is set in the object X if the expression X & Y is nonzero.

16.3.3.3.4 Character sequences [character.seq]

16.3.3.3.4.1 General [character.seq.general]

The C standard library makes widespread use of characters and character sequences that follow a few uniform conventions:
  • Properties specified as locale-specific may change during program execution by a call to setlocale(int, const char*) ([clocale.syn]), or by a change to a locale object, as described in [locales] and [input.output].
  • The execution character set and the execution wide-character set are supersets of the basic literal character set ([lex.charset]).
    The encodings of the execution character sets and the sets of additional elements (if any) are locale-specific.
    Each element of the execution wide-character set is encoded as a single code unit representable by a value of type wchar_t.
    [Note 1: 
    The encodings of the execution character sets can be unrelated to any literal encoding.
    — end note]
  • A letter is any of the 26 lowercase or 26 uppercase letters in the basic character set.
  • The decimal-point character is the locale-specific (single-byte) character used by functions that convert between a (single-byte) character sequence and a value of one of the floating-point types.
    It is used in the character sequence to denote the beginning of a fractional part.
    It is represented in [support] through [exec] and [depr] by a period, '.', which is also its value in the "C" locale.
  • A character sequence is an array object A that can be declared as T A[N], where T is any of the types char, unsigned char, or signed char ([basic.fundamental]), optionally qualified by any combination of const or volatile.
    The initial elements of the array have defined contents up to and including an element determined by some predicate.
    A character sequence can be designated by a pointer value S that points to its first element.

16.3.3.3.4.2 Byte strings [byte.strings]

A null-terminated byte string, or ntbs, is a character sequence whose highest-addressed element with defined content has the value zero (the terminating null character); no other element in the sequence has the value zero.143
The length of an ntbs is the number of elements that precede the terminating null character.
An empty ntbs has a length of zero.
The value of an ntbs is the sequence of values of the elements up to and including the terminating null character.
A static ntbs is an ntbs with static storage duration.144
143)143)
Many of the objects manipulated by function signatures declared in <cstring> are character sequences or ntbss.
The size of some of these character sequences is limited by a length value, maintained separately from the character sequence.
144)144)
A string-literal, such as "abc", is a static ntbs.

16.3.3.3.4.3 Multibyte strings [multibyte.strings]

A multibyte character is a sequence of one or more bytes representing the code unit sequence for an encoded character of the execution character set.
A null-terminated multibyte string, or ntmbs, is an ntbs that constitutes a sequence of valid multibyte characters, beginning and ending in the initial shift state.145
A static ntmbs is an ntmbs with static storage duration.
145)145)
An ntbs that contains characters only from the basic literal character set is also an ntmbs.
Each multibyte character then consists of a single byte.

16.3.3.3.5 Customization Point Object types [customization.point.object]

A customization point object is a function object ([function.objects]) with a literal class type that interacts with program-defined types while enforcing semantic requirements on that interaction.
The type of a customization point object, ignoring cv-qualifiers, shall model semiregular ([concepts.object]).
All instances of a specific customization point object type shall be equal ([concepts.equality]).
The effects of invoking different instances of a specific customization point object type on the same arguments are equivalent.
The type T of a customization point object, ignoring cv-qualifiers, shall model invocable<T&, Args...>, invocable<const T&, Args...>, invocable<T, Args...>, and invocable<const T, Args...> ([concept.invocable]) when the types in Args... meet the requirements specified in that customization point object's definition.
When the types of Args... do not meet the customization point object's requirements, T shall not have a function call operator that participates in overload resolution.
For a given customization point object o, let p be a variable initialized as if by auto p = o;.
Then for any sequence of arguments args..., the following expressions have effects equivalent to o(args...):
  • p(args...)
  • as_const(p)(args...)
  • std​::​move(p)(args...)
  • std​::​move(as_const(p))(args...)
Each customization point object type constrains its return type to model a particular concept.

16.3.3.4 Functions within classes [functions.within.classes]

For the sake of exposition, [support] through [exec] and [depr] do not describe copy/move constructors, assignment operators, or (non-virtual) destructors with the same apparent semantics as those that can be generated by default ([class.copy.ctor], [class.copy.assign], [class.dtor]).
It is unspecified whether the implementation provides explicit definitions for such member function signatures, or for virtual destructors that can be generated by default.

16.3.3.5 Private members [objects.within.classes]

[support] through [exec] and [depr] do not specify the representation of classes, and intentionally omit specification of class members.
An implementation may define static or non-static class members, or both, as needed to implement the semantics of the member functions specified in [support] through [exec] and [depr].
For the sake of exposition, some subclauses provide representative declarations, and semantic requirements, for private members of classes that meet the external specifications of the classes.
The declarations for such members are followed by a comment that ends with exposition only, as in: streambuf* sb; // exposition only
An implementation may use any technique that provides equivalent observable behavior.

16.3.3.6 Freestanding items [freestanding.item]

A freestanding item is a declaration, entity, typedef-name, or macro that is required to be present in a freestanding implementation and a hosted implementation.
Unless otherwise specified, the requirements on freestanding items for a freestanding implementation are the same as the corresponding requirements for a hosted implementation, except that not all of the members of those items are required to be present.
Function declarations and function template declarations followed by a comment that include freestanding-deleted are freestanding deleted functions.
On freestanding implementations, it is implementation-defined whether each entity introduced by a freestanding deleted function is a deleted function ([dcl.fct.def.delete]) or whether the requirements are the same as the corresponding requirements for a hosted implementation.
[Note 1: 
Deleted definitions reduce the chance of overload resolution silently changing when migrating from a freestanding implementation to a hosted implementation.
— end note]
[Example 1: double abs(double j); // freestanding-deleted — end example]
A declaration in a synopsis is a freestanding item if
  • it is followed by a comment that includes freestanding,
  • it is followed by a comment that includes freestanding-deleted, or
  • the header synopsis begins with a comment that includes freestanding and the declaration is not followed by a comment that includes hosted.
    [Note 2: 
    Declarations followed by hosted in freestanding headers are not freestanding items.
    As a result, looking up the name of such functions can vary between hosted and freestanding implementations.
    — end note]
[Example 2: // all freestanding namespace std { — end example]
An entity, deduction guide, or typedef-name is a freestanding item if it is:
  • introduced by a declaration that is a freestanding item,
  • a member of a freestanding item other than a namespace,
  • an enumerator of a freestanding item,
  • a deduction guide of a freestanding item,
  • an enclosing namespace of a freestanding item,
  • a friend of a freestanding item,
  • denoted by a typedef-name that is a freestanding item, or
  • denoted by an alias template that is a freestanding item.
A macro is a freestanding item if it is defined in a header synopsis and
  • the definition is followed by a comment that includes freestanding, or
  • the header synopsis begins with a comment that includes freestanding and the definition is not followed by a comment that includes hosted.
[Example 3: #define NULL see below // freestanding — end example]
[Note 3: 
Freestanding annotations follow some additional exposition conventions that do not impose any additional normative requirements.
Header synopses that begin with a comment containing "all freestanding" contain no hosted items and no freestanding deleted functions.
Header synopses that begin with a comment containing "mostly freestanding" contain at least one hosted item or freestanding deleted function.
Classes and class templates followed by a comment containing "partially freestanding" contain at least one hosted item or freestanding deleted function.
— end note]
[Example 4: template<class T, size_t N> struct array; // partially freestanding template<class T, size_t N> struct array { constexpr reference operator[](size_type n); constexpr const_reference operator[](size_type n) const; constexpr reference at(size_type n); // freestanding-deleted constexpr const_reference at(size_type n) const; // freestanding-deleted }; — end example]