C++ Standard Library


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.

Overview

The C++ Standard Library provides several generic containers, functions to use and manipulate these containers, function objects, generic strings and streams, 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 "", but their use was deprecated. 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 "". 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, and has been influenced by research in generic programming and developers of the STL such as Alexander Stepanov and Meng Lee. Although the C++ Standard Library and the STL share many features, neither is a strict superset of the other. 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. For more features, some third-party libraries such as Boost libraries and POCO C++ Libraries, which offer additional features, may be used to supplement the 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. 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 or linearithmic time O, but in some cases higher bounds are allowed, such as quasilinear time O for stable sort. Previously, sorting was only required to take O 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, 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 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.

Implementations

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. 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.

Standard modules

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, or can be alternatively exported as compile-time constants.
The C++ standard has reserved std and std.* as module names, however most compilers allow a flag to override this.
The current standard library modules defined by the standard as of C++23 are:
NameDescription
Exports all declarations in namespace std and global storage allocation and deallocation functions that are provided by the importable C++ library headers including C library facilities.
Exports the same declarations as the named module std, and additionally exports functions in global namespace in C library facilities. It thus contains "compat" in the name, meaning compatibility with C.

The above modules export the entire C++ standard library, meaning that as of currently, the standard library must be imported in its entirety. Importing a module imports all symbols marked with export.
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.
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. These include:
NameDescription
Exports the utility facilities within the C++ standard library.
Exports everything in, as well as container facilities and the Standard Template Library, and other data types such as strings, regular expressions, and smart pointers.
Exports facilities for input/output.
Exports facilities for interfacing with the operating system as well as filesystem manipulation.
Exports facilities for concurrent programming.
Exports facilities for mathematics and pseudorandom number generation.

Standard headers

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

General

Components that C++ programs may use for increased features.
NameDescription
Added in C++17. Provides a type-erased class std::any.
Related to . For testing error codes reported by library functions.
Added in C++11. Provides time elements, such as std::chrono::duration, std::chrono::time_point, and clocks. Since C++20, a hefty amount of temporal features were added: calendars, time zones, more clocks, and string chrono formatting.
Added in C++20. Provides fundamental library concepts.
Added in C++26. Provides design by contract features.
Related to . Declares the macros setjmp and longjmp, which are used for non-local exits.
Related to . Defines signal-handling functions.
Related to . For querying and specifying the alignment of objects. Deprecated in C++17, removed in C++20.
Related to . Defines a Boolean data type. Deprecated in C++17, removed in C++20.
Related to . Defines several useful types and macros.
Related to . Defines exact-width integer types.
Related to . Defines date- and time-handling functions.
Added in C++26. Provides fundamental library concepts.
Added in C++23. Provides class template std::expected, a result type.
Provides several function objects, designed for use with the standard algorithms.
Added in C++23. Provides a coroutine generator that additionally supports nested yield operations on ranges.
Provides facilities for memory management in C++, including the class template std::unique_ptr.
Added in C++17. Provides facilities for creating polymorphic memory allocators whose behaviors can change at runtime.
Added in C++17. Provides class template std::optional, an optional type.
Added in C++11. Provides std::scoped_allocator_adaptor.
Added in C++23. Provides stack trace operations.
Contains standard exception classes such as std::logic_error and std::runtime_error, both derived from std::exception.
Added in C++11. Defines std::error_code
Added in C++11 and TR1. Provides a class template std::tuple, a tuple.
Added in C++11. Provides metaprogramming facilities working with types.
The utility file provides various utilities: class template std::pair, compile-time integer sequences, helpers in constructing vocabulary types, functions such as std::move and std::forward, and many more. The namespace std::rel_ops for automatically generating comparison operators is deprecated in C++20 in favor of new defaulted comparison operators.
Added in C++17. Provides a class template std::variant, a tagged union type.