Top Qs
Timeline
Chat
Perspective

C++ Standard Library

Collection of classes and functions used in the C++ programming language From Wikipedia, the free encyclopedia

Remove ads

In the C++ programming language, the C++ Standard Library is a collection of classes and functions, which are written in the core language and part of the C++ ISO Standard itself.[1]

Overview

Summarize
Perspective

The C++ Standard Library provides several generic containers, functions to use and manipulate these containers, function objects, generic strings and streams (including interactive and file I/O), support for some language features, and functions for common tasks such as finding the square root of a number. The C++ Standard Library also incorporates most headers of the ISO C standard library ending with ".h", but their use was deprecated (reverted the deprecation since C++23[2]).[3] C++23 instead considers these headers as useful for interoperability with C, and recommends against their usage outside of programs that are intended to be both valid C and C++ programs. No other headers in the C++ Standard Library end in ".h". Features of the C++ Standard Library are declared within the std namespace.

The C++ Standard Library is based upon conventions introduced by the Standard Template Library (STL), and has been influenced by research in generic programming and developers of the STL such as Alexander Stepanov and Meng Lee.[4][5] Although the C++ Standard Library and the STL share many features, neither is a strict superset of the other.[citation needed] The design of the C++ standard library, much like the C standard library, is minimalistic, and contains only core features for programming, lacking most of the more specialised features offered by the Java standard library or C# standard library.

A noteworthy feature of the C++ Standard Library is that it not only specifies the syntax and semantics of generic algorithms, but also places requirements on their performance.[6] These performance requirements often correspond to a well-known algorithm, which is expected but not required to be used. In most cases this requires linear time O(n) or linearithmic time O(n log n), but in some cases higher bounds are allowed, such as quasilinear time O(n log2 n) for stable sort (to allow in-place merge sort). Previously, sorting was only required to take O(n log n) on average, allowing the use of quicksort, which is fast in practice but has poor worst-case performance, but introsort was introduced to allow both fast average performance and optimal worst-case complexity, and as of C++11, sorting is guaranteed to be at worst linearithmic. In other cases requirements remain laxer, such as selection, which is only required to be linear on average (as in quickselect),[7] not requiring worst-case linear as in introselect.

The C++ Standard Library underwent ISO standardization as part of the C++ ISO Standardization effort in the 1990s. Since 2011, it has been expanded and updated every three years[8] with each revision of the C++ standard.

Since C++23, the C++ Standard Library can be imported using modules, which were introduced in C++20.

Remove ads

Implementations

Summarize
Perspective
More information Name, Organization ...

Discontinued

Apache C++ Standard Library

The Apache C++ Standard Library is another open-source implementation. It was originally developed commercially by Rogue Wave Software and later donated to the Apache Software Foundation.[9] However, after more than five years without a release, the board of the Apache Software Foundation decided to end this project and move it to Apache Attic.[10]

See also

The following libraries implement much of the C++ Standard Library:

More information Name, Homepage ...
Remove ads

Standard modules

Summarize
Perspective

Although modules were first introduced in C++20, standard library modules were only standardised as part of the language in C++23. These named modules were added to include all items declared in both global and std namespaces provided by the importable standard headers. Macros are not allowed to be exportable, so users have to manually include or import headers that emit macros for use.

The C++ standard has reserved std and std.* as module names,[11] however most compilers allow a flag to override this.[12]

The current standard library modules defined by the standard as of C++23 are:

More information Name, Description ...

The above modules export the entire C++ standard library, meaning that as of currently, the standard library must be imported in its entirety. Furthermore, modules do not allow for granular imports of specific namespaces, classes, or symbols within a module, unlike Java or Rust which do allow for the aforementioned. Importing a module imports all symbols marked with export, making it akin to a wildcard import in Java or Rust.

Like Java's packages, C++ modules do not have a hierarchical system, but typically use a hierarchical naming convention. In other words, C++ does not have "submodules", meaning the . symbol which may be included in a module name bears no syntactic meaning and is used only to suggest the association of a module. As an example, std.compat is not a submodule of std, but is named so to indicate the association the module bears to the std module (as a "compatibility" version of it).

It has been proposed that additional modules providing other subsets of the standard library be added, which may eventually be included in a future revision.[13][14] These include:

More information Name, Description ...
Remove ads

Standard headers

Summarize
Perspective

The following files contain the declarations of the C++ Standard Library.

Legend:
 : Deprecated
 : Removed

General

Components that C++ programs may use for increased features.

More information Name, Description ...

Language support

Components that C++ programs may use for support during development.

More information Name, Description ...

Containers

Components that C++ programs may use for container data structures.

More information Name, Description ...

Iterators and ranges

Components that C++ programs may use to manipulate iterators, ranges, and algorithms over ranges and containers.

More information Name, Description ...

Localisation

Components that C++ programs may use for localisation and character encoding manipulation.

More information Name, Description ...

Strings

Components that C++ programs may use for string manipulation.

More information Name, Description ...

Streams, files, and input/output

Components that C++ programs may use for input/output manipulation and file manipulation.

More information Name, Description ...

Thread support library

Components that C++ programs may use for threading and concurrent programming.

More information Name, Description ...

Numerics library

Components that C++ programs may use to perform seminumerical or mathematical operations.

More information Name, Description ...

C standard library

Each header from the C Standard Library is included in the C++ Standard Library under a different name, generated by removing the '.h' file extension, and adding a 'c' at the start; for example, 'time.h' becomes 'ctime'. The only difference between these headers and the traditional C Standard Library headers is that where possible the functions should be placed into the std:: namespace. In ISO C, functions in the standard library are allowed to be implemented by macros, which is not allowed by ISO C++.

Usage of the C headers with the '.h' file extension is legal in C++ and used for compatibility.

More information Name, Description ...

The following headers are special C compatibility headers which do not have a corresponding C++ naming convention, meaning that the C headers must be used if the header is necessary.

More information Name, Description ...

The C headers <stdnoreturn.h> and <threads.h> do not have C++ equivalents and their C headers are not supported in C++.

C++ does not provide the C POSIX library as part of any standard, however it is legal to use in a C++ program. If used in C++, the POSIX headers are not prepended with a "c" at the beginning of the name, and all contain the .h suffix in the header name. Most headers in the POSIX library typically have a C++ equivalent implementation, such as <regex> rather than <regex.h>.

Remove ads

See also

References

Further reading

Loading content...
Loading content...
Loading related searches...

Wikiwand - on

Seamless Wikipedia browsing. On steroids.

Remove ads