Namespaces
Variants

C++ Standard Library

From cppreference.com
< cpp
Revision as of 07:09, 7 September 2022 by Xmcgcg (talk | contribs) (Minor fix.)

The C++ standard library provides a wide range of facilities that are usable in standard C++.

Category

The language support library provides components that are required by certain parts of the C++ language, such as memory allocation (new/delete) and exception processing.

The concepts library describes library components that C++ programs may use to perform compile-time validation of template arguments and perform function dispatch based on properties of types.

(since C++20)

The diagnostics library provides a consistent framework for reporting errors in a C++ program, including predefined exception classes.

The memory management library provides components for memory management, including smart pointers and scoped allocator(since C++11).

The metaprogramming library describes facilities for use in templates and during constant evaluation, including type traits, integer sequence,(since C++14) and rational arithmetic.

(since C++11)

The general utilities library includes components used by other library elements, such as a predefined storage allocator for dynamic storage management, and components used as infrastructure in C++ programs, such as tuples and(since C++11) function wrappers.

The strings library provides support for manipulating text represented as homogeneous sequences of following types: char, char8_t(since C++20), char16_t, char32_t(since C++11), wchar_t, and any other character-like types.

The containers, iterators, ranges(since C++20), and algorithms libraries provide a C++ program with access to a subset of the most widely used algorithms and data structures.

The numerics library provides numeric algorithms and complex number components that extend support for numeric processing. The valarray component provides support for n-at-a-time processing, potentially implemented as parallel operations on platforms that support such processing. The random number component provides facilities for generating pseudo-random numbers.(since C++11)

The time library provides generally useful time utilities.

The localization library provides extended internationalization support for text processing.

Theinput/output library provides the iostream components that are the primary mechanism for C++ program input and output. They can be used with other elements of the library, particularly strings, locales, and iterators.

The regular expressions library provides regular expression matching and searching.

The thread support library provides components to create and manage threads, including atomic operations, mutual exclusion, and inter-thread communication.

(since C++11)

Library contents

The C++ standard library provides definitions for the entities and macros described in the synopses of the C++ standard library headers, unless otherwise specified.

All library entities except operator new and operator delete are defined within the namespace std or namespaces nested within namespace std (except the entities for the C standard library facilities, see below). It is unspecified whether names declared in a specific namespace are declared directly in that namespace or in an inline namespace inside that namespace.(since C++11)

Headers

Each element of the C++ standard library is declared or defined (as appropriate) in a header . A header is not necessarily a source file, nor are the sequences delimited by < and > in header names necessarily valid source file names.

The C++ standard library provides the C++ library headers and additional C++ headers for C library facilities (see 'headers' page for descriptions):

C++ library headers
<algorithm> <iomanip> <list> <queue> <string>
<bitset> <ios> <locale> <set> <strstream>
<complex> <iosfwd> <map> <sstream> <typeinfo>
<deque> <iostream> <memory> <stack> <utility>
<exception> <istream> <new> <stdexcept> <valarray>
<fstream> <iterator> <numeric> <streambuf> <vector>
<functional> <limits> <ostream>
Headers added in C++11
<array> <condition_variable> <mutex> <scoped_allocator> <type_traits>
<atomic> <forward_list> <random> <system_error> <typeindex>
<chrono> <future> <ratio> <thread>
<codecvt> <initializer_list> <regex> <tuple>
Headers added in C++17
<any> <filesystem> <optional> <string_view> <variant>
<execution> <memory_resource> <shared_mutex>
Headers added in C++20
<barrier> <compare> <format> <ranges> <span>
<bit> <concepts> <latch> <semaphore> <stop_token>
<charconv> <coroutine> <numbers> <source_location> <syncstream>
Headers added in C++23
<expected> <flat_set> <mdspan> <spanstream> <stdfloat>
<flat_map> <generator> <print> <stacktrace>
C++ headers for C library facilities
<cassert> <clocale> <cstdarg> <cstring>
<cctype> <cmath> <cstddef> <ctime>
<cerrno> <csetjmp> <cstdio> <cwchar>
<cfloat> <csignal> <cstdlib> <cwctype>
<climits>
Headers removed in C++20
<ciso646>
Headers added in C++11
<cfenv> <cinttypes> <cstdint> <cuchar>
Headers added in C++11, deprecated in C++17, and removed in C++20
<ccomplex> <cstdalign> <cstdbool> <ctgmath>

A freestanding implementation has an implementation-defined set of headers, see here for the minimal requirement on the set of headers.

C standard library

The C++ standard library also makes available the facilities of the C standard library, suitably adjusted to ensure static type safety. The descriptions of many library functions rely on the C standard library for the semantics of those functions.

In some cases, the signatures specified in standard C++ may be different from the signatures in the C standard library, and additional overloads may be declared, but the behavior and the preconditions are the same unless otherwise stated.

For compatibility with the C standard library, the C++ standard library provides the C headers listed below. The intended use of these headers is for interoperability only. It is possible that C++ source files need to include one of these headers in order to be valid ISO C. Source files that are not intended to also be valid ISO C should not use any of the C headers. See here for descriptions.

C headers
<assert.h> <limits.h> <stdarg.h> <string.h>
<ctype.h> <locale.h> <stddef.h> <time.h>
<errno.h> <math.h> <stdio.h> <wchar.h>
<float.h> <setjmp.h> <stdlib.h> <wctype.h>
<iso646.h> <signal.h>
Headers added in C++11
<complex.h> <inttypes.h> <stdbool.h> <tgmath.h>
<fenv.h> <stdalign.h>