______________________________________________________________________ 17 Library introduction [lib.library] ______________________________________________________________________ 1 This clause describes the contents of the C++ Standard library, how a well-formed C++ program makes use of the library, and how a conforming implementation may provide the entities in the library. 2 The C++ Standard library provides an extensible framework, and con tains components for: language support, diagnostics, general utili ties, strings, locales, containers, iterators, algorithms, numerics, and input/output. The language support components are required by certain parts of the C++ language, such as memory allocation (_expr.new_, _expr.delete_) and exception processing (_except_). 3 The general utilities include components used by other library ele ments, such as a predefined storage allocator for dynamic storage man agement (_basic.stc.dynamic_). The diagnostics components provide a consistent framework for reporting errors in a C++ program, including predefined exception classes. 4 The strings components provide support for manipulating text repre sented as sequences of type char, sequences of type wchar_t, or sequences of any other ``character-like'' type. The localization com ponents extend internationalization support for such text processing. 5 The containers, iterators, and algorithms provide a C++ program with access to a subset of the most widely used algorithms and data struc tures. 6 Numeric algorithms and the complex number components extend support for numeric processing. The valarray components provide support for n-at-a-time processing, potentially implemented as parallel operations on platforms that support such processing. 7 The iostreams components are the primary mechanism for C++ program input/output. They can be used with other elements of the library, particularly strings, locales, and iterators. 8 This library also makes available the facilities of the Standard C library, suitably adjusted to ensure static type safety. 9 The following subclauses describe the definitions (_lib.definitions_), and method of description (_lib.description_) for the library. Sub clause _lib.requirements_ and Clauses _lib.language.support_ through _lib.input.output_ specify the contents of the library, and library requirements and constraints on both well-formed C++ programs and conforming implementations. 17.1 Definitions [lib.definitions] --category: A logical collection of library entities. Clauses _lib.language.support_ through _lib.input.output_ each describe a single category of entities within the library. --comparison function: An operator function (_over.oper_) for any of the equality (_expr.eq_) or relational (_expr.rel_) operators. --component: A group of library entities directly related as members, parameters, or return types. For example, the class template basic_string and the non-member template functions that operate on strings can be referred to as the string component. --default behavior: A description of replacement function and handler function semantics. Any specific behavior provided by the implemen tation, within the scope of the required behavior. --handler function: A non-reserved function whose definition may be provided by a C++ program. A C++ program may designate a handler function at various points in its execution, by supplying a pointer to the function when calling any of the library functions that install handler functions (_lib.language.support_). --modifier function: A class member function (_class.mfct_), other than constructors, assignment, or destructor, that alters the state of an object of the class. --object state: The current value of all nonstatic class members of an object (_class.mem_). The state of an object can be obtained by using one or more observer functions --observer function: A class member function (_class.mfct_) that accesses the state of an object of the class, but does not alter that state. Observer functions are specified as const member func tions (_class.this_). --replacement function: A non-reserved function whose definition is provided by a C++ program. Only one definition for such a function is in effect for the duration of the program's execution, as the result of creating the program (_lex.phases_) and resolving the def initions of all translation units (_basic.link_). --required behavior: A description of replacement function and handler function semantics, applicable to both the behavior provided by the implementation and the behavior that shall be provided by any func tion definition in the program. If a function defined in a C++ pro gram fails to meet the required behavior when it executes, the behavior is undefined. --reserved function: A function, specified as part of the C++ Standard library, that must be defined by the implementation. If a C++ pro gram provides a definition for any reserved function, the results are undefined. Subclause _intro.defs_ defines additional terms used elsewhere in this International Standard. 17.2 Method of description (Informative) [lib.description] 1 This subclause describes the conventions used to describe the C++ Standard library. It describes the structures of the normative Clauses _lib.language.support_ through _lib.input.output_ (_lib.structure_), and other editorial conventions (_lib.conventions_). 17.2.1 Structure of each subclause [lib.structure] 1 Subclause _lib.organization_ provides a summary of the C++ Standard library's contents. Other Library clauses provide detailed specifica tions for each of the components in the library, as shown in Table 1: Table 1--Library Categories +-------------------------------------------+ | Clause Category | +-------------------------------------------+ |_lib.language.support_ Language support | |_lib.diagnostics_ Diagnostics | |_lib.utilities_ General utilities | |_lib.strings_ Strings | |_lib.localization_ Localization | |_lib.containers_ Containers | |_lib.iterators_ Iterators | |_lib.algorithms_ Algorithms | |_lib.numerics_ Numerics | |_lib.input.output_ Input/output | +-------------------------------------------+ 2 Each Library clause contains the following elements, as applicable:1) --Summary --Requirements --Detailed specifications --References to the Standard C library _________________________ 1) To save space, items that do not apply to a clause are omitted. For example, if a clause does not specify any requirements on template arguments, there will be no ``Requirements'' subclause. 17.2.1.1 Summary [lib.structure.summary] 1 The Summary provides a synopsis of the category, and introduces the first-level subclauses. Each subclause also provides a summary, list ing the headers specified in the subclause and the library entities provided in each header. 2 Paragraphs labelled ``Note(s):'' or ``Example(s):'' are informative, other paragraphs are normative. 3 The summary and the detailed specifications are presented in the order: --Macros --Values --Types --Classes --Functions --Objects 17.2.1.2 Requirements [lib.structure.requirements] 1 The library can be extended by a C++ program. Each clause, as appli cable, describes the requirements that such extensions must meet. Such extensions are generally one of the following: --Template arguments --Derived classes --Containers, iterators, and/or algorithms that meet an interface con vention 2 The string and iostreams components use an explicit representation of operations required of template arguments. They use a template class name XXX_traits to define these constraints. 3 Interface convention requirements are stated as generally as possible. Instead of stating ``class X has to define a member function opera tor++(),'' the interface requires ``for any object x of class X, ++x is defined.'' That is, whether the operator is a member is unspeci fied. 4 Requirements are stated in terms of well-defined expressions, which define valid terms of the types that satisfy the requirements. For every set of requirements there is a table that specifies an initial set of the valid expressions and their semantics (_lib.allocator.requirements_, _lib.container.requirements_, _lib.iterator.requirements_). Any generic algorithm (_lib.algorithms_) that uses the requirements is described in terms of the valid expressions for its formal type parameters. 5 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.2) 17.2.1.3 Specifications [lib.structure.specifications] 1 The detailed specifications each contain the following elements:3) --Name and brief description --Synopsis (class definition or function prototype, as appropriate) --Restrictions on template arguments, if any --Decription of class invariants --Description of function semantics 2 Descriptions of class member functions follow the order (as appropriate):4) --Constructor(s) and destructor --Copying & assignment functions --Comparison functions --Modifier functions --Observer functions --Operators and other non-member functions 3 Descriptions of function semantics contain the following elements (as appropriate):5) --Requires: the preconditions for calling the function _________________________ 2) Although in some cases the code given is unambiguously the optimum implementation. 3) The form of these specifications was designed to follow the conven tions established by existing C++ library vendors. 4) To save space, items that do not apply to a class are omitted. For example, if a class does not specify any comparison functions, there will be no ``Comparison functions'' subclause. 5) To save space, items that do not apply to a function are omitted. For example, if a function does not specify any preconditions, there will be no ``Requires'' paragraph. --Effects: the actions performed by the function --Postconditions: the observable results established by the function --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 4 For non-reserved replacement and handler functions, Clause _lib.language.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 dis tinction is explicitly made in the description, the behavior described is the required behavior. 5 If an operation is required to be linear time, it means no worse than linear time, and a constant time operation satisfies the requirement. 17.2.1.4 C Library [lib.structure.see.also] 1 Paragraphs labelled ``SEE ALSO:'' contain cross-references to the rel evant portions of this Standard and the ISO C standard, which is incorporated into this Standard by reference. 17.2.2 Other conventions [lib.conventions] 1 This subclause describes several editorial conventions used to describe the contents of the C++ Standard library. These conventions are for describing implementation-defined types (_lib.type.descriptions_), and member functions (_lib.functions.within.classes_). 17.2.2.1 Type descriptions [lib.type.descriptions] 1 The Requirements subclauses describe names that are used to specify constraints on template arguments.6) These names are used in Clauses _lib.containers_, _lib.algorithms_, and _lib.numerics_ to describe the types that may be supplied as arguments by a C++ program when instan tiating template components from the library. 2 Certain types defined in Clause _lib.input.output_ are used to describe implementation-defined types. They are based on other types, but with added constraints. _________________________ 6) Examples include: InputIterator, ForwardIterator, Function, Predi cate, etc. See subclause _lib.iterator.requirements_. 17.2.2.1.1 Enumerated types [lib.enumerated.types] 1 Several types defined in Clause _lib.input.output_ are enumerated types. Each enumerated type may be implemented as an enumeration or as a synonym for an enumeration.7) 2 The enumerated type enumerated can be written: enum enumerated { V0, V1, V2, V3, .....}; static const enumerated C0(V0); static const enumerated C1(V1); static const enumerated C2(V2); static const enumerated C3(V3); ..... 3 Here, the names C0, C1, etc. represent enumerated elements for this particular enumerated type. All such elements have distinct values. 17.2.2.1.2 Bitmask types [lib.bitmask.types] 1 Several types defined in Clause _lib.input.output_ are bitmask types. Each bitmask type can be implemented as an enumerated type that over loads certain operators, as an integer type, or as a bitset (_lib.template.bitset_). 2 The bitmask type bitmask can be written: enum bitmask { V0 = 1 << 0, V1 = 1 << 1, V2 = 1 << 2, V3 = 1 << 3, ..... }; static const bitmask C0(V0); static const bitmask C1(V1); static const bitmask C2(V2); static const bitmask C3(V3); ..... bitmask& operator&=(bitmask& X, bitmask Y) { X = bitmask(X & Y); return X; } bitmask& operator|=(bitmask& X, bitmask Y) { X = bitmask(X | Y); return X; } bitmask& operator^=(bitmask& X, bitmask Y) { X = bitmask(X ^ Y); return X; } bitmask operator& (bitmask X, bitmask Y) { return bitmask(X & Y); } bitmask operator| (bitmask X, bitmask Y) { return bitmask(X | Y); } bitmask operator^ (bitmask X, bitmask Y) { return bitmask(X ^ Y); } bitmask operator~ (bitmask X) { return (bitmask)~X; } 3 Here, the names C0, C1, etc. represent bitmask elements for this par ticular bitmask type. All such elements have distinct values such that, for any pair Ci and Cj, Ci & Ci is nonzero and Ci & Cj is zero. 4 The following terms apply to objects and values of bitmask types: _________________________ 7) Such as an integer type, with constant integer values (_ba sic.fundamental_). --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. 17.2.2.1.3 Character sequences [lib.character.seq] 1 The Standard C library makes widespread use of characters and charac ter sequences that follow a few uniform conventions: --A letter is any of the 26 lowercase or 26 uppercase letters in the basic execution character set.8) --The decimal-point character is the (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 Clauses _lib.language.support_ through _lib.input.output_ by a period, '.', which is also its value in the "C" locale, but may change during program execution by a call to setlocale(int, const char*),9) or by a change to a locale object, as described in Clauses _lib.locales_ and _lib.input.output_. --A character sequence is an array object (_dcl.array_) 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. 17.2.2.1.3.1 Byte strings [lib.byte.strings] 1 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).10) 2 The length of an NTBS is the number of elements that precede the ter minating null character. An empty NTBS has a length of zero. _________________________ 8) Note that this definition differs from the definition in ISO C sub clause 7.1.1. 9) declared in <clocale> (_lib.c.locales_). 10) Many of the objects manipulated by function signatures declared in <cstring> (_lib.c.strings_) are character sequences or NTBSs. The size of some of these character sequences is limited by a length val ue, maintained separately from the character sequence. 3 The value of an NTBS is the sequence of values of the elements up to and including the terminating null character. 4 A static NTBS is an NTBS with static storage duration.11) 17.2.2.1.3.2 Multibyte strings [lib.multibyte.strings] 1 A null-terminated multibyte string, or NTMBS, is an NTBS that consti tutes a sequence of valid multibyte characters, beginning and ending in the initial shift state.12) 2 A static NTMBS is an NTMBS with static storage duration. 17.2.2.1.3.3 Wide-character sequences [lib.wide.characters] 1 A wide-character sequence is an array object (_dcl.array_) A that can be declared as T A[N], where T is type wchar_t (_basic.fundmental_), optionally qualified by any combination of const or volatile. The initial elements of the array have defined contents up to and includ ing an element determined by some predicate. A character sequence can be designated by a pointer value S that designates its first element. 2 A null-terminated wide-character string, or NTWCS, is a wide-character sequence whose highest-addressed element with defined content has the value zero.13) 3 The length of an NTWCS is the number of elements that precede the ter minating null wide character. An empty NTWCS has a length of zero. 4 The value of an NTWCS is the sequence of values of the elements up to and including the terminating null character. 5 A static NTWCS is an NTWCS with static storage duration.14) 17.2.2.2 Functions within classes [lib.functions.within.classes] 1 For the sake of exposition, Clauses _lib.language.support_ through _lib.input.output_ do not describe copy constructors, assignment oper ators, or (non-virtual) destructors with the same apparent semantics as those that can be generated by default (_class.ctor_, _class.dtor_, _class.copy_). 2 It is unspecified whether the implementation provides explicit defini tions for such member function signatures, or for virtual destructors _________________________ 11) A string literal, such as "abc", is a static NTBS. 12) An NTBS that contains characters only from the basic execution character set is also an NTMBS. Each multibyte character then con sists of a single byte. 13) Many of the objects manipulated by function signatures declared in <cwchar> are wide-character sequences or NTWCSs. 14) A wide string literal, such as L"abc", is a static NTWCS. that can be generated by default. 17.2.2.3 Private members [lib.objects.within.classes] 1 Clauses _lib.language.support_ through _lib.input.output_ do not spec ify the representation of classes, and intentionally omit specifica tion of class members (_class.mem_). An implementation may define static or non-static class members, or both, as needed to implement the semantics of the member functions specified in Clauses _lib.language.support_ through _lib.input.output_. 2 Objects of certain classes are sometimes required by the external specifications of their classes to store data, apparently in member objects. For the sake of exposition, subclauses _lib.locale_, _lib.template.bitset_, _lib.istreambuf.iterator_, _lib.ostreambuf.iterator_, _lib.ios.base_, _lib.stringbuf_, and _lib.filebuf_ provide representative declarations, and semantic requirements, for private member objects of classes that meet the external specifications of the classes. The declarations for such member objects and the definitions of related member types are enclosed in a comment that ends with exposition only, as in: // streambuf* sb; exposition only 3 Any alternate implementation that provides equivalent external behav ior is equally acceptable. 17.3 Library-wide requirements [lib.requirements] 1 This subclause specifies requirements that apply to the entire C++ Standard library. Clauses _lib.language.support_ through _lib.input.output_ specify the requirements of individual entities within the library. 2 The following subclauses describe the library's contents and organiza tion (_lib.organization_), how well-formed C++ programs gain access to library entities (_lib.using_), constraints on such programs (_lib.constraints_), and constraints on conforming implementations (_lib.conforming_). 17.3.1 Library contents and organization [lib.organization] 1 This subclause provides a summary of the entities defined in the C++ Standard library. Subclause _lib.contents_ provides an alphabetical listing of entities by type, while subclause _lib.headers_ provides an alphabetical listing of library headers. 17.3.1.1 Library contents [lib.contents] 1 The C++ Standard library provides definitions for the following types of entities: --Macros --Values --Types --Templates --Classes --Functions --Objects 2 All library entities shall be defined within the namespace std. 3 The C++ Standard library provides 54 standard macros from the C library (_diff.library_). 4 The C++ Standard library provides 45 standard values from the C library (_diff.library_). 5 The C++ Standard library provides 19 standard types from the C library (_diff.library_), and 28 additional types, as shown in Table 2: Table 2--Standard Types +-----------------------------------------------------------------+ |filebuf ostringstream wfilebuf wstreambuf | |ifstream streambuf wifstream wstreampos | |ios streamoff wios wstring | |istream streampos wistream wstringbuf | |istringstream string wistringstream | |new_handler stringbuf wofstream | |ofstream terminate_handler wostream | |ostream unexpected_handler wostringstream | +-----------------------------------------------------------------+ 6 The C++ Standard library provides 66 standard template classes, as shown in Table 3: Table 3--Standard Template classes +-------------------------------------------+ |allocator mask_array | |auto_ptr messages | |back_insert_iterator messages_byname | |basic_filebuf moneypunct | |basic_ifstream moneypunct_byname | |basic_ios money_get | |basic_istream money_put | |basic_istringstream multimap | |basic_ofstream multiset | |basic_ostream numeric_limits | |basic_ostringstream numpunct | |basic_streambuf num_get | |basic_string num_put | |basic_stringbuf ostreambuf_iterator | |binary_negate ostream_iterator | +-------------------------------------------+ +-------------------------------------------------------+ |binder1st pointer_to_binary_function | |binder2nd pointer_to_unary_function | |bitset priority_queue | |codecvt queue | |codecvt_byname raw_storage_iterator | |collate reverse_bidirectional_iterator | |collate_byname reverse_iterator | |complex set | |ctype slice_array | |ctype_byname stack | |deque time_get | |front_insert_iterator time_get_byname | |gslice_array time_put | |indirect_array time_put_byname | |insert_iterator unary_negate | |istreambuf_iterator valarray | |istream_iterator vector | |list | |map | +-------------------------------------------------------+ 7 The C++ Standard library provides 24 standard template structures, as shown in Table 4: Table 4--Standard Template structs +---------------------------------------------------------------+ |bidirectional_iterator less pair | |binary_function less_equal plus | |divides logical_and random_access_iterator | |equal_to logical_not string_char_traits | |forward_iterator logical_or times | |greater minus unary_function | |greater_equal modulus | |input_iterator negate | |ios_traits not_equal_to | +---------------------------------------------------------------+ 8 The C++ Standard library provides 86 standard template operator func tions, as shown in Table 5. 9 Types shown (enclosed in ( and ) ) indicate that the given function is overloaded by that type. Numbers shown (enclosed in [ and ] ) indi cate how many overloaded functions are overloaded by that type. Table 5--Standard Template operators +--------------------------------------------------------------------+ |operator!= (basic_string) [5] operator<< (basic_string) | |operator!= (complex) [3] operator<< (bitset) | |operator!= (istreambuf_iterator) operator<< (complex) | |operator!= (ostreambuf_iterator) operator<< (valarray) [3] | |operator!= (T) operator<<=(valarray) [2] | |operator!= (valarray) [3] operator<= (T) | |operator% (valarray) [3] operator<= (valarray) [3] | |operator%= (valarray) [2] operator== (basic_string) [5] | |operator& (bitset) operator== (complex) [3] | |operator& (valarray) [3] operator== (deque) | |operator&& (valarray) [3] operator== (istreambuf_iterator) | |operator&= (valarray) [2] operator== (istream_iterator) | |operator* (complex) [3] operator== (list) | |operator* (valarray) [3] operator== (map) | |operator*= (complex) operator== (multimap) | |operator*= (valarray) [2] operator== (multiset) | |operator+ (basic_string) [5] operator== (ostreambuf_iterator) | |operator+ (complex) [4] operator== (pair) | |operator+ (reverse_iterator) operator== (queue) | |operator+ (valarray) [3] operator== (restrictor) | |operator+= (complex) operator== (reverse_bidir_iter) | |operator+= (valarray) [2] operator== (reverse_iterator) | |operator- (complex) [4] operator== (set) | |operator- (reverse_iterator) operator== (stack) | |operator- (valarray) [3] operator== (valarray) [3] | |operator-= (complex) operator== (vector) | |operator-= (valarray) [2] operator> (T) | |operator/ (complex) [3] operator> (valarray) [3] | |operator/ (valarray) [3] operator>= (T) | |operator/= (complex) operator>= (valarray) [3] | |operator/= (valarray) [2] operator>> (basic_string) | |operator< (deque) operator>> (bitset) | |operator< (list) operator>> (complex) | |operator< (map) operator>> (valarray) [3] | |operator< (multimap) operator>>=(valarray) [2] | |operator< (multiset) operator^ (bitset) | |operator< (pair) operator^ (valarray) [3] | |operator< (queue) operator^= (valarray) [2] | |operator< (restrictor) operator| (bitset) | |operator< (reverse_iterator) operator| (valarray) [3] | |operator< (set) operator|= (valarray) [2] | |operator< (stack) operator|| (valarray) [3] | |operator< (valarray) [3] | |operator< (vector) | +--------------------------------------------------------------------+ 10The C++ Standard library provides 144 standard template functions, as shown in Table 6: Table 6--Standard Template functions +-------------------------------------------------------------------+ |abs (complex) lower_bound [2] | |abs (valarray) make_heap [2] | |accumulate [2] make_pair | |acos (complex) max [2] | |acos (valarray) max_element [2] | |adjacent_difference [2] merge [2] | |adjacent_find [2] min [2] | |advance min_element [2] | |allocate mismatch [2] | |arg (complex) next_permutation [2] | |asin (complex) norm (complex) | |asin (valarray) not1 | |atan (complex) not2 | |atan (valarray) nth_element [2] | |atan2(complex) [3] partial_sort [2] | |atan2(valarray) [3] partial_sort_copy [2] | |back_inserter partial_sum [2] | |binary_search [2] partition | |bind1st polar(complex) | |bind2nd pop_heap [2] | |conj (complex) pow (complex) | |construct pow (complex) [3] | |copy pow (valarray) [3] | |copy_backward prev_permutation [2] | |cos (complex) ptr_fun [2] | |cos (valarray) push_heap [2] | |cosh (complex) random_shuffle [2] | |cosh (valarray) real (complex) | |count remove | |count_if remove_copy | |deallocate remove_copy_if | |destroy [2] remove_if | |distance replace | |distance_type (istreambuf_iterator) replace_copy | |distance_type [5] replace_copy_if | |equal [2] replace_if | |equal_range [2] reverse | |exp (complex) reverse_copy | |exp (valarray) rotate | |fill rotate_copy | |fill_n search [4] | |find set_difference [2] | |find_end [4] set_intersection [2] | |find_first_of [2] set_symmetric_difference [2] | |find_if set_union [2] | +-------------------------------------------------------------------+ +---------------------------------------------------+ |for_each sin (complex) | |front_inserter sin (valarray) | |generate sinh (complex) | |generate_n sinh (valarray) | |getline sort [2] | |get_temporary_buffer sort_heap [2] | |imag (complex) sqrt (complex) | |includes [2] sqrt (valarray) | |inner_product [2] stable_partition | |inplace_merge [2] stable_sort [2] | |inserter swap | |isalnum swap_ranges | |isalpha tan (complex) | |iscntrl tan (valarray) | |isdigit tanh (complex) | |isgraph tanh (valarray) | |islower tolower | |isprint toupper | |ispunct transform [2] | |isspace uninitialized_copy | |isupper uninitialized_fill_n | |isxdigit unique [2] | |iterator_category [7] unique_copy [2] | |lexicographical_compare [2] unititialized_fill | |log (complex) upper_bound [2] | |log (valarray) value_type [7] | |log10(complex) | |log10(valarray) | +---------------------------------------------------+ 11The C++ Standard library provides 28 standard classes, as shown in Table 7. 12Type names (enclosed in < and > ) indicate that these are specific instances of templates. Table 7--Standard Classes +--------------------------------------------------------------------+ |bad_alloc ctype_byname<char> logic_error | |bad_cast domain_error out_of_range | |bad_exception exception overflow_error | |bad_typeid gslice range_error | |basic_string<char> invalid_argument runtime_error | |basic_string<wchar_t> ios_base slice | |complex<double> length_error type_info | |complex<float> locale vector<bool,allocator> | |complex<long double> locale::facet | |ctype<char> locale::id | +--------------------------------------------------------------------+ 13The C++ Standard library provides 2 standard structures from the C library (_diff.library_), and 16 additional structures, as shown in Table 8: Table 8--Standard Structs +---------------------------------------------------------+ |bidirectional_iterator_tag nothrow | |codecvt_base output_iterator | |ctype_base output_iterator_tag | |forward_iterator_tag random_access_iterator_tag | |input_iterator_tag string_char_traits<char> | |ios_traits<char> string_char_traits<wchar_t> | |ios_traits<wchar_t> time_base | |money_base | |money_base::pattern | +---------------------------------------------------------+ 14The C++ Standard library provides 12 standard operator functions, as shown in Table 9: Table 9--Standard Operator functions +---------------------------------------------------------------+ |operator delete operator new[] (void*) | |operator delete[] operator< (vector<bool,allocator>) | |operator new operator<< (locale) | |operator new (nothrow) operator== (vector<bool,allocator>) | |operator new (void*) operator>> (locale) | |operator new[] | |operator new[] (nothrow) | +---------------------------------------------------------------+ 15The C++ Standard library provides 208 standard functions from the C library (_diff.library_), and 78 additional functions, as shown in Table 10: Table 10--Standard Functions +-----------------------------------------------------------------+ |abs (float) mod (long double) | |abs (long double) modf (float,float*) | |abs (long) modf (long double,long double*) | |acos (float) noshowbase | |acos (long double) noshowpoint | |asin (float) noshowpos | |asin (long double) noskipws | |atan (float) nouppercase | |atan (long double) oct | |atan2(float,float) pow (float) [2] | |atan2(long double,long double) pow (long double) [2] | |ceil (float) resetiosflags | |ceil (long double) right | |cos (float) scientific | |cos (long double) setbase | |cosh (float) setfill | |cosh (long double) setiosflags | |dec setprecision | |div (long,long) setw | |endl set_new_handler | |ends set_terminate | |exp (float) set_unexpected | |exp (long double) showbase | |fixed showpoint | |floor(float) showpos | |floor(long double) sin (float) | |flush sin (long double) | |frexp(float,int*) sinh (float) | |frexp(long double,int*) sinh (long double) | |hex skipws | |internal tan (float) | |iterator_category tan (long double) | |ldexp(float,int) tanh (float) | |ldexp(long double,int) tanh (long double) | |left terminate | |log (float) unexpected | |log (long double) uppercase | |log10(float) ws | |log10(long double) | |mod (float) | +-----------------------------------------------------------------+ 16The C++ Standard library provides 8 standard objects, as shown in Table 11: Table 11--Standard Objects +-------------------------+ |cerr cin clog cout | |werr win wlog wout | +-------------------------+ 17.3.1.2 Headers [lib.headers] 1 The elements of the C++ Standard library are declared or defined (as appropriate) in a header.15) 2 The C++ Standard library provides 32 C++ headers, as shown in Table 12: Table 12--C++ Library Headers +-----------------------------------------------------------------+ |<algorithm> <iomanip> <list> <queue> <typeinfo> | |<bitset> <ios> <locale> <set> <utility> | |<complex> <iosfwd> <map> <sstream> <valarray> | |<deque> <iostream> <memory> <stack> <vector> | |<exception> <istream> <new> <stdexcept> | |<fstream> <iterator> <numeric> <streambuf> | |<functional> <limits> <ostream> <string> | +-----------------------------------------------------------------+ 3 The facilities of the Standard C Library are provided in 18 additional headers, as shown in Table 13: Table 13--C++ Headers for C Library Facilities +--------------------------------------------------+ |<cassert> <ciso646> <csetjmp> <cstdio> <cwchar> | |<cctype> <climits> <csignal> <cstdlib> <cwctype> | |<cerrno> <clocale> <cstdarg> <cstring> | |<cfloat> <cmath> <cstddef> <ctime> | +--------------------------------------------------+ 4 Except as noted in Clauses _lib.language.support_ through _lib.input.output_, the contents of each header cname shall be the _________________________ 15) A header is not necessarily a source file, nor are the sequences delimited by < and > in header names necessarily valid source file names (_cpp.include_). same as that of the corresponding header name.h, as specified in ISO C (Clause 7), or Amendment 1, (Clause 7), as appropriate. In this C++ Standard library, however, the declarations and definitions are within namespace scope (_basic.scope.namespace_) of the namespace std. 5 Subclause _depr.c.headers_, Standard C library headers, describes the effects of using the name.h (C header) form in a C++ program.16) 17.3.1.3 Freestanding implementations [lib.compliance] 1 Two kinds of implementations are defined: hosted and freestanding (_intro.compliance_). For a hosted implementation, this International Standard describes the set of available headers. 2 A freestanding implementation has has an implementation-defined set of headers. This set shall include at least the following headers, as shown in Table 14: Table 14--C++ Headers for Freestanding Implementations +--------------------------------------------------------------+ | Subclause Header(s) | +--------------------------------------------------------------+ |_lib.support.types_ Types <cstddef> | +--------------------------------------------------------------+ |_lib.support.limits_ Implementation properties <limits> | +--------------------------------------------------------------+ |_lib.support.start.term_ Start and termination <cstdlib> | +--------------------------------------------------------------+ |_lib.support.dynamic_ Dynamic memory management <new> | +--------------------------------------------------------------+ |_lib.support.rtti_ Type identification <typeinfo> | +--------------------------------------------------------------+ |_lib.support.exception_ Exception handling <exception> | +--------------------------------------------------------------+ |_lib.support.runtime_ Other runtime support <cstdarg> | +--------------------------------------------------------------+ 3 The supplied version of the header <cstdlib> shall declare at least the functions abort(), atexit(), and exit() (_lib.support.start.term_). _________________________ 16) The ".h" headers dump all their names into the global namespace, whereas the newer forms keep their names in namespace std. Therefore, the newer forms are the preferred forms for all uses except for C++ programs which are intended to be strictly compatible with C. 17.3.2 Using the library [lib.using] 1 This subclause describes how a C++ program gains access to the facili ties of the C++ Standard library. Subclause _lib.using.headers_ describes effects during translation phase 4, while subclause _lib.using.linkage_ describes effects during phase 8 (_lex.phases_). 17.3.2.1 Headers [lib.using.headers] 1 The entities in the C++ Standard library are defined in headers, whose contents are made available to a translation unit when it contains the appropriate #include preprocessing directive (_cpp.include_). 2 A translation unit may include library headers in any order (_lex_). Each may be included more than once, with no effect different from being included exactly once, except that the effect of including either <cassert> or <assert.h> depends each time on the lexically cur rent definition of NDEBUG.17) 3 A translation unit shall include a header only outside of any external declaration or definition, and shall include the header lexically before the first reference to any of the entities it declares or first defines in that translation unit. 17.3.2.2 Linkage [lib.using.linkage] 1 Entities in the C++ Standard library have external linkage (_basic.link_). Unless otherwise specified, objects and functions have the default extern "C++" linkage (_dcl.link_). 2 It is unspecified whether a name from the Standard C library declared with external linkage has either extern "C" or extern "C++" linkage.18) 3 Objects and functions defined in the library and required by a C++ program are included in the program prior to program startup. SEE ALSO: replacement functions (_lib.replacement.functions_), run- time changes (_lib.handler.functions_). 17.3.3 Constraints on programs [lib.constraints] 1 This subclause describes restrictions on C++ programs that use the facilities of the C++ Standard library. The following subclauses specify constraints on the program's namespace (_lib.reserved.names_), its use of headers (_lib.alt.headers_), classes derived from standard _________________________ 17) This is the same as the Standard C library. 18) The only reliable way to declare an object or function signature from the Standard C library is by including the header that declares it, notwithstanding the latitude granted in subclause 7.1.7 of the C Standard. library classes (_lib.derived.classes_), definitions of replacement functions (_lib.replacement.functions_), and installation of handler functions during execution (_lib.handler.functions_). 17.3.3.1 Reserved names [lib.reserved.names] 1 A C++ program shall not extend the namespace std. 2 The C++ Standard library reserves the following kinds of names: --Macros --Global names --Names with external linkage 3 If the program declares or defines a name in a context where it is reserved, other than as explicitly allowed by this clause, the behav ior is undefined. 17.3.3.1.1 Macro names [lib.macro.names] 1 Each name defined as a macro in a header is reserved to the implemen tation for any use if the translation unit includes the header.19) 2 A translation unit that includes a header shall not contain any macros that define names declared or defined in that header. Nor shall such a translation unit define macros for names lexically identical to key words. 17.3.3.1.2 Global names [lib.global.names] 1 Each header also optionally declares or defines names which are always reserved to the implementation for any use and names reserved to the implementation for use at file scope. 2 Certain sets of names and function signatures are reserved whether or not a translation unit includes a header: 3 Each name that begins with an underscore and either an uppercase let ter or another underscore (_lex.key_) is reserved to the implementa tion for any use. 4 Each name that begins with an underscore is reserved to the implemen tation for use as a name with file scope or within the namespace std in the ordinary name space. _________________________ 19) It is not permissible to remove a library macro definition by us ing the #undef directive. 17.3.3.1.3 External linkage [lib.extern.names] 1 Each name declared as an object with external linkage in a header is reserved to the implementation to designate that library object with external linkage.20) 2 Each global function signature declared with external linkage in a header is reserved to the implementation to designate that function signature with external linkage.21) 3 Each name having two consecutive underscores (_lex.key_) is reserved to the implementation for use as a name with both extern "C" and extern "C++" linkage. 4 Each name from the Standard C library declared with external linkage is reserved to the implementation for use as a name with extern "C" linkage. 5 Each function signature from the Standard C library declared with external linkage is reserved to the implementation for use as a func tion signature with both extern "C" and extern "C++" linkage.22) 17.3.3.2 Headers [lib.alt.headers] 1 If a file has a name equivalent to the derived file name for one of the C++ Standard library headers, is not provided as part of the implementation, and is placed in any of the standard places for a source file to be included (_cpp.include_), the behavior is undefined. 17.3.3.3 Derived classes [lib.derived.classes] 1 Virtual member function signatures defined for a base class in the C++ Standard library may be overridden in a derived class defined in the program (_class.virtual_). 17.3.3.4 Replacement functions [lib.replacement.functions] 1 Clauses _lib.language.support_ through _lib.input.output_ describe the behavior of numerous functions defined by the C++ Standard library. Under some circumstances, however, certain of these function descrip tions also apply to replacement functions defined in the program (_lib.definitions_). _________________________ 20) The list of such reserved names includes errno, declared or de fined in <cerrno>. 21) The list of such reserved function signatures with external link age includes setjmp(jmp_buf), declared or defined in <csetjmp>, and va_end(va_list), declared or defined in <cstdarg>. 22) The function signatures declared in <cwchar> and <cwctype> are al ways reserved, notwithstanding the restrictions imposed in subclause 4.5.1 of Amendment 1 to the C Standard for these headers. 2 A C++ program may provide the definition for any of six (6) dynamic memory allocation function signatures declared in header <new> (_basic.stc.dynamic_, _lib.language.support_):23) --operator new(size_t) --operator new(size_t,nothrow) --operator new[](size_t) --operator new[](size_t,nothrow) --operator delete(void*) --operator delete[](void*) 3 The program's definitions are used instead of the default versions supplied by the implementation (_dcl.fct.def_). Such replacement occurs prior to program startup (_basic.def.odr_, _basic.start_). 17.3.3.5 Handler functions [lib.handler.functions] 1 The C++ Standard library provides default versions of the three han dler functions (_lib.language.support_): --new_handler --unexpected_handler --terminate_handler 2 A C++ program may install different handler functions during execu tion, by supplying a pointer to a function defined in the program or the library as an argument to (respectively): --set_new_handler --set_unexpected --set_terminate SEE ALSO: subclauses _lib.alloc.errors_, Storage allocation errors, and _lib.support.exception_, Exception handling. 17.3.3.6 Other functions [lib.res.on.functions] 1 In certain cases (replacement functions, handler functions, operations on types used to instantiate standard library template components), the C++ Standard library depends on components supplied by a C++ pro gram. If these components do not meet their requirements, the Stan dard places no requirements on the implementation. 2 In particular, the effects are undefined in the following cases: --for replacement functions (_lib.new.delete_), if the installed han dler function does not implement the semantics of the applicable Required behavior paragraph. --for handler functions (_lib.new.handler_, _lib.terminate.handler_, _lib.unexpected.handler_), if the installed handler function does not implement the semantics of the applicable Required behavior paragraph --for types used as template arguments when instantiating a template component, if the operations on the type do not implement the seman tics of the applicable Requirements subclause (_lib.allocator.requirements_, _lib.container.requirements_, _lib.iterator.requirements_, _lib.numeric.requirements_). --if any of these functions or operations throws an exception, unless specifically allowed in the applicable Required behavior paragraph. 17.3.3.7 Function arguments [lib.res.on.arguments] 1 Each of the following statements applies to all arguments to functions defined in the C++ Standard library, unless explicitly stated other wise. --If an argument to a function has an invalid value (such as a value outside the domain of the function, or a pointer invalid for its intended use), the behavior is undefined. --If a function argument is described as being an array, the pointer actually passed to the function shall have a value such that all address computations and accesses to objects (that would be valid if the pointer did point to the first element of such an array) are in fact valid. 17.3.4 Conforming implementations [lib.conforming] 1 This subclause describes the constraints upon, and latitude of, imple mentations of the C++ Standard library. The following subclauses describe an implementation's use of headers (_lib.res.on.headers_), macros (_lib.res.on.macro.definitions_), global functions (_lib.global.functions_), member functions (_lib.member.functions_), reentrancy (_lib.reentrancy_), access specifiers (_lib.protection.within.classes_), class derivation (_lib.derivation_), and exceptions (_lib.res.on.exception.handling_). 17.3.4.1 Headers [lib.res.on.headers] 1 Certain types and macros are defined in more than one header. For such an entity, a second or subsequent header that also defines it may be included after the header that provides its initial definition (_basic.def.odr_). 2 Header inclusion is limited as follows: --None of the C++ headers includes any of the C headers. However, any of the C++ headers can include any of the other C++ headers, and must include a C++ header that contains any needed definition.23) --The C headers ( .h form, described in Annex D, _depr.c.headers_) shall include only their corresponding C++ header, as described above (_lib.headers_). --The C++ headers listed in Table 21, C++ Library Headers, shall include the header(s) listed in their respective Synopsis subclause (_lib.support.dynamic_, _lib.support.rtti_, _lib.support.exception_, _lib.std.exceptions_, _lib.utility_, _lib.function.objects_, _lib.memory_, _lib.string.classes_, _lib.locales_, _lib.sequences_, _lib.iterators_, _lib.algorithms_, _lib.complex.numbers_, _lib.numarray_, _lib.iostream.objects_, _lib.iostreams.base_, _lib.stream.buffers_, _lib.iostream.format_, _lib.string.streams_, _lib.fstreams_).24) 3 However, any of the C++ headers can include any of the other C++ head ers, and must include a C++ header that contains any needed definition.25) 17.3.4.2 Restrictions on macro [lib.res.on.macro.definitions] definitions 1 The names or global function signatures described in subclause _lib.contents_ are reserved to the implementation.26) 2 All object-like macros defined by the Standard C library and described in this clause as expanding to integral constant expressions are also suitable for use in #if preprocessing directives, unless explicitly stated otherwise. _________________________ 23) Including any one of the C++ headers can introduce all of the C++ headers into a translation unit, or just the one that is named in the #include preprocessing directive. 24) C++ headers must include a C++ header that contains any needed definition (_basic.def.odr_). 25) Including any one of the C++ headers can introduce all of the C++ headers into a translation unit, or just the one that is named in the #include preprocessing directive. 26) A global function cannot be declared by the implementation as tak ing additional default arguments. Also, the use of masking macros for function signatures declared in C headers is disallowed, notwithstand ing the latitude granted in subclause 7.1.7 of the C Standard. The use of a masking macro can often be replaced by defining the function signature as inline. 17.3.4.3 Global functions [lib.global.functions] 1 It is unspecified whether any global functions in the C++ Standard library are defined as inline (_dcl.fct.spec_). 2 A call to a global function signature described in Clauses _lib.language.support_ through _lib.input.output_ behaves the same as if the implementation declares no additional global function signatures.27) 17.3.4.4 Member functions [lib.member.functions] 1 It is unspecified whether any member functions in the C++ Standard library are defined as inline (_dcl.fct.spec_). 2 An implementation can declare additional non-virtual member function signatures within a class: --by adding arguments with default values to a member function signature;28) The same latitude does not extend to the implementa tion of virtual or global functions, however. --by replacing a member function signature with default values by two or more member function signatures with equivalent behavior; --by adding a member function signature for a member function name. 3 A call to a member function signature described in the C++ Standard library behaves the same as if the implementation declares no addi tional member function signatures.29) 17.3.4.5 Reentrancy [lib.reentrancy] 1 Which of the functions in the C++ Standard Library are not reentrant subroutines is implementation-defined. 17.3.4.6 Protection within [lib.protection.within.classes] classes 1 It is unspecified whether a function signature or class described in Clauses _lib.language.support_ through _lib.input.output_ is a friend of another class in the C++ Standard Library. _________________________ 27) A valid C++ program always calls the expected library global func tion. An implementation may also define additional global functions that would otherwise not be called by a valid C++ program. 28) Hence, taking the address of a member function has an unspecified type. 29) A valid C++ program always calls the expected library member func tion, or one with equivalent behavior. An implementation may also de fine additional member functions that would otherwise not be called by a valid C++ program. 2 It is unspecified whether a member described in this clause as private is private, protected, or public. It is unspecified whether a member described as protected is protected or public. A member described as public is always public. 17.3.4.7 Derived classes [lib.derivation] 1 Certain classes defined in the C++ Standard Library are derived from other classes in the C++ Standard library: --It is unspecified whether a class in the C++ Standard Library as a base class is itself derived from other base classes (with names reserved to the implementation). --It is unspecified whether a class described in the C++ Standard Library as derived from another class is derived from that class directly, or through other classes (with names reserved to the implementation) that are derived from the specified base class. 2 In any case: --A base class described as virtual is always virtual; --A base class described as non-virtual is never virtual; --Unless explicitly stated otherwise, types with distinct names are distinct types.30) 17.3.4.8 Restrictions on [lib.res.on.exception.handling] exception handling 1 Any of the functions defined in the C++ Standard library can report a failure by throwing an exception of the type(s) described in their Throws: paragraph and/or their exception-specification (_except.spec_). 2 Any of the functions defined in the C++ Standard library that do not have an exception-specification prohibiting it, can report a failure to allocate storage by throwing an exception of type bad_alloc, or a class derived from bad_alloc (_lib.bad.alloc_). _________________________ 30) An implicit exception to this rule are types described as synonyms for basic integral types, such as size_t (_lib.support.types_) and streamoff (_lib.stream.types_).