Utility library - cppreference.com (original) (raw)
C++ includes a variety of utility libraries that provide functionality ranging from bit-counting to partial function application. These libraries can be broadly divided into two groups:
- language support libraries, and
- general-purpose libraries.
Contents
- 1 Language support
- 1.1 Implementation properties (since C++20)
- 1.2 Type support
- 1.3 Program utilities
- 1.4 Dynamic memory management
- 1.5 Error handling
- 1.6 Variadic functions
- 1.7 Initializer lists (since C++11)
- 1.8 Source code information capture (since C++20)
- 1.9 Three-way comparison (since C++20)
- 1.10 Coroutine support (since C++20)
- 1.11 Contract support (since C++26)
- 2 General-purpose utilities
- 2.1 Swap
- 2.2 Type operations (since C++11)
- 2.3 Integer comparison functions (since C++20)
- 2.4 Relational operators (until C++20)
- 2.5 Construction tags (since C++11)
- 2.6 Pairs and tuples
* 2.6.1 Tuple protocol (since C++11) - 2.7 Sum types and type erased wrappers (since C++17)
- 2.8 Bitset
- 2.9 Bit manipulation (since C++20)
- 2.10 Function objects (since C++11)
- 2.11 Hash support (since C++11)
- 2.12 See also
[edit] Language support
Language support libraries provide classes and functions that interact closely with language features and support common language idioms.
[edit] Implementation properties (since C++20)
The header supplies implementation-dependent information about the C++ standard library (such as the version number and release date). It also defines the library feature-test macros.
[edit] Type support
Basic types (e.g. std::size_t, std::nullptr_t), RTTI (e.g. std::type_info)
[edit] Program utilities
Termination (e.g. std::abort, std::atexit), environment (e.g. std::system), signals (e.g. std::raise).
[edit] Dynamic memory management
Smart pointers (e.g. std::shared_ptr), allocators (e.g. std::allocator or std::pmr::memory_resource), C-style memory management (e.g. std::malloc).
[edit] Error handling
Exceptions (e.g. std::exception, std::terminate), assertions (e.g. assert).
[edit] Variadic functions
Support for functions that take an arbitrary number of parameters (via e.g. va_start, va_arg, va_end).
[edit] Initializer lists (since C++11)
[edit] Source code information capture (since C++20)
[edit] Three-way comparison (since C++20)
Defined in header | |
---|---|
three_way_comparablethree_way_comparable_with(C++20) | specifies that operator <=> produces consistent result on given types (concept) [edit] |
partial_ordering(C++20) | the result type of 3-way comparison that supports all 6 operators, is not substitutable, and allows incomparable values (class) [edit] |
weak_ordering(C++20) | the result type of 3-way comparison that supports all 6 operators and is not substitutable (class) [edit] |
strong_ordering(C++20) | the result type of 3-way comparison that supports all 6 operators and is substitutable (class) [edit] |
is_eqis_neqis_ltis_lteqis_gtis_gteq(C++20) | named comparison functions (function) [edit] |
compare_three_way(C++20) | constrained function object implementing x <=> y (class) [edit] |
compare_three_way_result(C++20) | obtains the result type of the three-way comparison operator <=> on given types (class template) [edit] |
common_comparison_category(C++20) | the strongest comparison category to which all of the given types can be converted (class template) [edit] |
strong_order(C++20) | performs 3-way comparison and produces a result of type std::strong_ordering(customization point object)[edit] |
weak_order(C++20) | performs 3-way comparison and produces a result of type std::weak_ordering(customization point object)[edit] |
partial_order(C++20) | performs 3-way comparison and produces a result of type std::partial_ordering(customization point object)[edit] |
compare_strong_order_fallback(C++20) | performs 3-way comparison and produces a result of type std::strong_ordering, even if operator<=> is unavailable(customization point object)[edit] |
compare_weak_order_fallback(C++20) | performs 3-way comparison and produces a result of type std::weak_ordering, even if operator<=> is unavailable(customization point object)[edit] |
compare_partial_order_fallback(C++20) | performs 3-way comparison and produces a result of type std::partial_ordering, even if operator<=> is unavailable(customization point object)[edit] |
[edit] Coroutine support (since C++20)
Types for coroutine support (e.g. std::coroutine_traits, std::coroutine_handle).
[edit] Contract support (since C++26)
Types for contract support (e.g. std::contracts::contract_violation).
[edit] General-purpose utilities
[edit] Swap
[edit] Type operations (since C++11)
Defined in header | |
---|---|
forward(C++11) | forwards a function argument and use the type template argument to preserve its value category (function template) [edit] |
forward_like(C++23) | forwards a function argument as if casting it to the value category and constness of the expression of specified type template argument (function template) [edit] |
move(C++11) | converts the argument to an xvalue (function template) [edit] |
move_if_noexcept(C++11) | converts the argument to an xvalue if the move constructor does not throw (function template) [edit] |
as_const(C++17) | obtains a reference to const to its argument (function template) [edit] |
declval(C++11) | obtains a reference to an object of the template type argument for use in an unevaluated context (function template) [edit] |
to_underlying(C++23) | converts an enumeration to its underlying type (function template) [edit] |
[edit] Integer comparison functions (since C++20)
[edit] Relational operators (until C++20)
[edit] Construction tags (since C++11)
[edit] Pairs and tuples
Defined in header | |
---|---|
pair | implements binary tuple, i.e. a pair of values (class template) [edit] |
Defined in header | |
tuple(C++11) | implements fixed size container, which holds elements of possibly different types (class template) [edit] |
apply(C++17) | calls a function with a tuple of arguments (function template) [edit] |
make_from_tuple(C++17) | construct an object with a tuple of arguments (function template) [edit] |
Tuple protocol (since C++11) | |
Defined in header | |
Defined in header | |
Defined in header | |
Defined in header | |
Defined in header | |
tuple_size(C++11) | obtains the number of elements of a tuple-like type (class template) [edit] |
tuple_element(C++11) | obtains the element types of a tuple-like type (class template) [edit] |
[edit] Sum types and type erased wrappers (since C++17)
Defined in header | |
---|---|
optional(C++17) | a wrapper that may or may not hold an object (class template) [edit] |
Defined in header | |
expected(C++23) | a wrapper that contains either an expected or error value (class template) [edit] |
Defined in header | |
variant(C++17) | a type-safe discriminated union (class template) [edit] |
Defined in header | |
any(C++17) | objects that hold instances of any CopyConstructible type (class) [edit] |
[edit] Bitset
[edit] Bit manipulation (since C++20)
The header provides several function templates to access, manipulate, and process individual bits and bit sequences. The byte ordering (endianness) of scalar types can be inspected via std::endian facility.
[edit] Function objects (since C++11)
Partial function application (e.g. std::bind) and related utilities: utilities for binding such as std::ref and std::placeholders, polymorphic function wrappers: std::function, predefined functors (e.g. std::plus, std::equal_to), pointer-to-member to function converters std::mem_fn.