Skip to content
Surf Wiki
Save to docs
general/c-standard-library

From Surf Wiki (app.surf) — the open knowledge base

C++ Standard Library

Collection of classes and functions used in the C++ programming language


Summary

Collection of classes and functions used in the C++ programming language

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 (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). 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 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(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), 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

NameOrganizationHomepageAcronymLicenceLatest release
GNU C++ Standard Library
LLVM C++ Standard Library
NVIDIA C++ Standard Library
Microsoft C++ Standard Library
HPX C++ Standard Library for Parallelism and Concurrency
Electronic Arts Standard Template Library
Dinkum C++ Library
Cray C++ Standard Library

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 (although declared in standard namespace).
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 (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. 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 (STL), 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:

: Deprecated

: Removed

General

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

NameDescription
Added in C++17. Provides a type-erased class `std::any`.
Related to `[](errno-h)`. 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 `[](setjmp-h)`. Declares the macros `setjmp` and `longjmp`, which are used for non-local exits.
Related to `[](signal-h)`. Defines signal-handling functions.
Related to ``. For querying and specifying the alignment of objects. Deprecated in C++17, removed in C++20.
Related to `[](stdbool-h)`. Defines a Boolean data type. Deprecated in C++17, removed in C++20.
Related to `[](stddef-h)`. Defines several useful types and macros.
Related to `[](stdint-h)`. Defines exact-width integer types.
Related to `[](time-h)`. 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` (two-member tuples), 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.

Language support

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

NameDescription
Related to `[](assert-h)`. Declares the assert macro, used to assist with detecting logical errors and other types of bugs while debugging a program.
Related to `[](errno-h)`. Defines a set of functions for controlling floating-point environment.
Related to `[](float-h)`. Defines macro constants specifying the implementation-specific properties of the floating-point library.
Related to `[](inttypes-h)`. Defines exact-width integer types.
Related to `[](iso646-h)`. Defines several macros that implement alternative ways to express several standard tokens. For programming in ISO 646 variant character sets. Removed in C++20.
Related to `[](limits-h)`. Defines macro constants specifying the implementation-specific properties of the integer types.
Added in C++20. Provides three-way comparison operator support.
Added in C++20. Provides coroutine support.
Added in C++26. Provides debugging support, such as breakpoints and other mechanisms to aid debuggers.
Provides several types and functions related to exception handling, including `std::exception`, the base class of all exceptions thrown by the Standard Library.
Added in C++11. Provides initializer list support.
Provides the class template `std::numeric_limits`, used for describing properties of fundamental numeric types.
Added in C++26. Provides reflective programming capabilities as well as symbol metadata and annotations.
Provides operators `new` and `delete` and other functions and types composing the fundamentals of C++ memory management.
Added in C++20. Provides capturing source location information as alternative to predefined macros such as `__LINE__`.
Added in C++23. Provides conditional support for extended floating-point types.
Provides facilities for working with C++ run-time type information.
Added in C++20. Provides information about the implementation of the C++ standard library.

Containers/collections

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

NameDescription
Added in C++11 and TR1. Provides the container class template `std::array`, a container for a fixed sized array.
Provides the specialized container class `std::bitset`, a bit array.
Provides the container class template `std::deque`, a double-ended queue.
Added in C++23. Provides the container adapter class templates `std::flat_map` and `std::flat_multimap`.
Added in C++23. Provides the container adapter class templates `std::flat_set` and `std::flat_multiset`.
Added in C++11 and TR1. Provides the container class template `std::forward_list`, a singly linked list.
Added in C++26. Provides the class `std::inplace_vector`, analogous to `std::vector` with a fixed capacity defined at compile time.
Added in C++26. Provides the class `std::hive`, which reuses erased elements' memory
Provides the container class templates `std::map` and `std::multimap`, sorted associative array and multimap.
Added in C++23. Provides the class template `std::mdspan`, analogous to `std::span` but the view is multidimensional.
Provides the container adapter class `std::queue`, a single-ended queue, and `std::priority_queue`, a priority queue.
Provides the container class templates `std::set` and `std::multiset`, sorted associative containers or sets.
Added in C++20. Provides the class template `std::span`, a non-owning view that refers to any contiguous range.
Provides the container adapter class `std::stack`, a stack.
Added in C++11 and TR1. Provides the container class template `std::unordered_map` and `std::unordered_multimap`, hash tables.
Added in C++11 and TR1. Provides the container class template `std::unordered_set` and `std::unordered_multiset`.
Provides the container class template `std::vector`, a dynamic array.

Iterators and ranges

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

NameDescription
Provides definitions of many algorithms for use with containers and other ranges.
Added in C++17. Provides execution policies for parallelized algorithms.
Provides classes and templates for working with iterators.
Generalized numeric algorithms.
Added in C++20. Provides ranges facilities and lazily evaluated adapters.

Localisation

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

NameDescription
Related to ``. Defines localization functions.
Provides code conversion facets for various character encodings. Deprecated since C++17, removed in C++26.
Defines classes and declares functions that encapsulate and manipulate the information peculiar to a locale.
Added in C++26. Provides text encoding identifications with the IANA Character Sets registry.

Strings

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

NameDescription
Related to `[](ctype-h)`. Defines set of functions used to classify characters by their types or to convert between upper and lower case in a way that is independent of the used character set (typically ASCII or one of its extensions, although implementations utilizing EBCDIC are also known).
Added in C++17. Provides a locale-independent, non-allocating, and non-throwing string conversion utilities from/to integers and floating point.
Related to `[](string-h)`. Defines string-handling functions.
Related to ``. Types and functions for manipulating Unicode characters.
Related to `[](wchar-h)`. Defines wide-string-handling functions.
Related to `[](wctype-h)`. Defines set of functions used to classify wide characters by their types or to convert between upper and lower case.
Added in C++20. Provides a modern way of formatting strings including `std::format`.
Provides the C++ standard string classes and templates.
Added in C++17. Provides class template `std::basic_string_view`, an immutable non-owning view to any string.
Added in C++11. Provides utilities for pattern matching strings using regular expressions.

Streams, files, and input/output

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

NameDescription
Related to `[](stdio-h)`. Defines core input and output functions.
Added in C++17. Provides facilities for file system operations and their components.
Provides facilities for file-based input and output. See fstream.
Provides facilities to manipulate output formatting, such as the base used when formatting integers and the precision of floating-point values.
Provides several types and functions basic to the operation of iostreams.
Provides forward declarations of several I/O-related class templates.
Provides C++ input and output fundamentals. See iostream.
Provides `std::istream` and other supporting classes for input.
Provides `std::ostream` and other supporting classes for output.
Added in C++23. Provides formatted output utilities such as `std::print` supported for both C and C++ streams.
Added in C++23. Provides `std::spanstream` and other fixed character buffer I/O streams.
Provides `std::stringstream` and other supporting classes for string manipulation.
Provides reading and writing functionality to/from certain types of character sequences, such as external files or strings.
Provides input/output operations on array-backed streams. Deprecated in C++98, removed in C++26.
Added in C++20. Provides `std::osyncstream` and other supporting classes for synchronized output streams.

Thread support library

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

NameDescription
Added in C++11. Provides class template `std::atomic`, its several template specializations, and more atomic operations.
Added in C++20. Provides `std::barrier`, a reusable thread barrier.
Related to `[](stdarg-h)`. For atomic operations on data shared between threads.
Added in C++11. In 32.9.1-1, this section describes components that a C++ program can use to retrieve in one thread the result (value or exception) from a function that has run in the same thread or another thread.
Added in C++26. Provides hazard pointers via `std::hazard_pointer`.
Added in C++20. Provides `std::latch`, a single-use thread barrier.
Added in C++11. In 32.5-1, this section provides mechanisms for mutual exclusion: mutexes, locks, and call once.
Added in C++26. Provides read-copy-update mechanisms for safe reclamation.
Added in C++14. Provides facility for shared mutual exclusion.
Added in C++20. Provides semaphore that models non-negative resource count.
Added in C++20. In 32.3.1-1, this section describes components that can be used to asynchronously request that an operation stops execution in a timely manner, typically because the result is no longer required. Such a request is called a stop request.
Added in C++11. Provide class and namespace for working with threads.

Numerics library

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

NameDescription
Added in C++20. Provides bit manipulation facilities.
Related to `[](complex-h)`. Defines a set of functions for manipulating complex numbers. Deprecated in C++17, removed in C++20.
Related to `[](math-h)`. Defines common mathematical functions. Extends ``, containing special mathematical functions such as Bessel functions and the Riemann zeta function.
Defines a class template `std::complex`, and numerous functions for representing and manipulating complex numbers.
Related to `[](tgmath-h)`. Defines type-generic mathematical functions. Deprecated in C++17, removed in C++20.
Added in C++26. Provides linear algebra facilities.
Added in C++20. Provides mathematical constants defined in namespace `std::numbers`.
Added in C++26. Provides data-parallel types (Single instruction, multiple data or SIMD) and operations on these types.
Added in C++11. Facility for generating (pseudo-)random numbers and distributions.
Added in C++11. Provides compile-time rational arithmetic based on class templates.
Defines five class templates (`std::valarray`, `std::slice_array`, `std::gslice_array`, `std::mask_array`, and `std::indirect_array`), two classes (`std::slice` and `std::gslice`), and a series of related function templates for representing and manipulating arrays of values.

C standard library

Main article: 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 '' file extension, and adding a '' 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 '' file extension is legal in C++ and used for compatibility.

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.

NameDescription
Added in C++23. For atomic operations on data shared between threads.
Added in C++26. For manipulating and processing bits and bit sequences.
Added in C++26. For checked integers.
Added in C++26. For determining the length of a C array.

The C headers and 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 "" at the beginning of the name, and all contain the suffix in the header name. Most headers in the POSIX library typically have a C++ equivalent implementation, such as rather than.

References

References

  1. ISO/IEC 14882:2003(E) ''Programming Languages – C++'' §17-27
  2. Köppe, Thomas. (2021-06-11). "Clarifying the status of the "C headers"".
  3. ISO/IEC 14882:2003(E) ''Programming Languages – C++'' §D.5
  4. Stroustrup, Bjarne. (1994). "The Design and Evolution of C++ §8.5". Addison Wesley.
  5. (1 August 1994). "The Standard Template Library". HP Labs.
  6. "[http://www.cs.rpi.edu/~musser/gp/algorithms.html Generic Algorithms] {{Webarchive. link. (3 June 2023 ", [[David Musser]])
  7. "std::nth_element". cppreference.com.
  8. "[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p1000r5.pdf C++ IS Schedule] {{Webarchive. link. (5 May 2024 ", [[Herb Sutter]])
  9. "Apache C++ Standard Library".
  10. Porter, Brett. (18 July 2013). "Apache C++ Standard Library and the Attic". stdcxx-dev mailing list.
  11. 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 https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2465r3.pdf] {{Webarchive. link. (18 November 2022)
  12. "Standard C++ modules".
  13. C++ Standards Committee. (2018). ''P0581R1 - Modules for C++''. Retrieved from [https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0581r1.pdf https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0581r1.pdf]
  14. C++ 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 https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2412r0.pdf] {{Webarchive. link. (20 November 2024)
  15. Filipek, Bartlomiej. "Polymorphic Allocators, std::vector Growth and Hacking".
  16. (2020-04-01). "Working Draft, Standard for Programming Language C++". ISO/IEC.
Wikipedia Source

This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page.

Want to explore this topic further?

Ask Mako anything about C++ Standard Library — get instant answers, deeper analysis, and related topics.

Research with Mako

Free with your Surf account

Content sourced from Wikipedia, available under CC BY-SA 4.0.

This content may have been generated or modified by AI. CloudSurf Software LLC is not responsible for the accuracy, completeness, or reliability of AI-generated content. Always verify important information from primary sources.

Report