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.ISO/IEC 14882:2003(E) Programming Languages – C++ §17-27
Overview 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 "", but their use was deprecated (reverted the deprecation since C++23).ISO/IEC 14882:2003(E) Programming Languages – C++ §D.5 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 (STL), 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 naming conventions of the standard library use snake_case, with the exception of std::ios_base::Init, std::text_encoding::id enumerators, and month/weekday constants. 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. An implementation for a C++ standard library header is described as "freestanding" if the execution of the program does not rely on an operating system.
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."Generic Algorithms ", David Musser 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 or linearithmic time , but in some cases higher bounds are allowed, such as quasilinear time for stable sort (to allow in-place merge sort). Previously, sorting was only required to take 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), 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"C++ IS Schedule ", Herb Sutter with each revision of the C++ standard.
C++20 specifies the introduction of standard library header units, and C++23 adds full module support for the standard library.
Implementations Name Organization Homepage Acronym Licence Latest release GNU C++ Standard Library GNU Project and Free Software Foundation libstdc++ GPLv3 with GCC Runtime Library Exception New major release once per year LLVM C++ Standard Library LLVM Developer Group libc++ Apache License 2.0 with LLVM Exceptions Every 2 weeks NVIDIA C++ Standard Library Nvidia libcudacxx Apache License 2.0 with LLVM Exceptions Microsoft C++ Standard Library Microsoft MSVC STL Apache License 2.0 with LLVM Exceptions Daily HPX C++ Standard Library for Parallelism and Concurrency STELLAR Group HPX Boost Software License 1.0 Electronic Arts Standard Template Library Electronic Arts EASTL BSD 3-Clause License Dinkum C++ Library Dinkumware Unknown Commercial Unknown Cray C++ Standard Library Cray User Group Unknown Commercial Unknown
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.
See also The following libraries implement much of the C++ Standard Library: Name Homepage Description Abseil An open source collection of libraries used internally by Google Folly A variety of C++17 libraries that are used extensively by Facebook Bareflank Support Library A C++ library where everything can be executed at compile time
Namespace organisation The C++ standard library is placed inside the std namespace. std was historically a flat namespace (unlike other languages like Java and C#, which extensively divide their respective standard libraries along nomenclatural, hierarchical lines), but since C++11 it has been further divided into sub-namespaces within it: std (the main namespace of the standard library) std::chrono (contains facilities for the date and time library) std::contracts (contains facilities for reporting information on contract violations) std::execution (contains the execution control library for asynchronous execution, including task<T>) std::execution::system_context_replaceability (allows for replacement of the default implement of the parallel scheduler) std::filesystem (contains facilities for working with file system manipulation, including directory_entry, path, etc.) std::linalg (contains facilities for linear algebra) std::literals (inlined namespace containing various operators for creating literals of an object) std::literals::chrono_literals (inlined namespace containing various operators for creating literals of duration objects) std::literals::complex_literals (inlined namespace containing various operators for creating literals of imaginary numbers) std::literals::string_literals (inlined namespace containing various operators for creating literals of string objects) std::literals::string_view_literals (inlined namespace containing various operators for creating literals of string-view objects) std::meta (contains facilities for static (compile-time) reflection with the info type representing reflection metadata) std::numbers (contains all numeric constants, such as pi, e, etc.) std::placeholders (contains all placeholder objects _1, _2, ..., up to an implementation-defined maximum _N) std::pmr (contains symbols for polymorphic memory resources, for flexible runtime-configured allocation, as well as versions of the standard library types using polymorphic_allocator as the allocator) std::ranges (contains symbols for working over ranges, which extend the algorithm/iterator libraries) std::ranges::views (contains symbols for range adapters for creating views, for lazy collection manipulation without copies; also aliased as std::views) std::regex_constants (contains various regular expression customisation constants, such as ECMAScript, awk, grep, etc.) std::rel_ops (contains automatically generated comparison operators, deprecated since C++20) std::this_thread (contains facilities for manipulating the current thread)
There is also a std::experimental namespace, with further sub-namespaces in std::experimental::* for various pre-standardised/technical specification features which may be implemented by some compiler vendors.
The posix namespace is reserved, presumably for use of POSIX APIs, but it currently remains unused. Identifiers beginning with two underscores, or with one underscore immediately followed by a capital letter, are reserved by the standard. Additionally, the std and posix namespaces are reserved, and adding declarations/definitions into any of those namespaces (or nested namespaces within) constitute undefined behavior, with a few exceptions (such as std::hash<> and std::formatter<>).
Standard modules Although modules were first introduced in C++20, standard library modules were only standardised as part of the language in C++23. Prior to that, standard library header units were specified for C++20, but most compiler vendors support backporting standard library modules to C++20. 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,C++ Standards Committee. (2022). P2465R3 - C++ Modules: Design and Evolution. Retrieved from https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2465r3.pdf however most compilers allow a flag to override this.
The standard library modules are: Name Since Description C++23 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 (although declared in standard namespace). C++23 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.
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). Despite there being only one module for the entire standard library, it has been proposed that additional modules providing other subsets of the standard library be added.C++ Standards Committee. (2018). P0581R1 - Modules for C++. Retrieved from https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0581r1.pdfC++ Standards Committee. (2021). P2412R0 - Further refinements to the C++ Modules Design. Retrieved from https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2412r0.pdf
Standard headers The following files contain the declarations of the C++ Standard Library.
Legend: : Deprecated : Removed
General Components that C++ programs may use for increased features.