Difference between revisions of "cpp/utility"
(+debugging section (right after source_location because relevant)) |
YexuanXiao (Talk | contribs) m |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 11: | Line 11: | ||
===[[cpp/types|Type support]]=== | ===[[cpp/types|Type support]]=== | ||
− | Basic types (e.g. {{lc|std::size_t}}, {{lc|std::nullptr_t}}), RTTI (e.g. {{lc|std::type_info}}) | + | Basic types (e.g. {{lc|std::size_t}}, {{lc|std::nullptr_t}}), RTTI (e.g. {{lc|std::type_info}}) |
+ | |||
+ | ===[[cpp/meta|Metaprogramming]]=== | ||
+ | Type traits (e.g. {{lc|std::is_integral}}, {{lc|std::rank}}), compile-time constants (e.g. {{lc|std::integer_sequence}}, {{lc|std::ratio}}) | ||
===Constant evaluation context=== | ===Constant evaluation context=== | ||
Line 38: | Line 41: | ||
{{dsc header|source_location}} | {{dsc header|source_location}} | ||
{{dsc inc|cpp/utility/dsc source_location}} | {{dsc inc|cpp/utility/dsc source_location}} | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
{{dsc end}} | {{dsc end}} | ||
Line 79: | Line 74: | ||
===[[cpp/utility/variadic|Variadic functions]]=== | ===[[cpp/utility/variadic|Variadic functions]]=== | ||
− | Support for functions that take an arbitrary number of parameters (via e.g. {{lc|va_start}}, {{lc|va_arg}}, {{lc|va_end}}) | + | Support for functions that take an arbitrary number of parameters (via e.g. {{lc|va_start}}, {{lc|va_arg}}, {{lc|va_end}}). |
==General-purpose utilities== | ==General-purpose utilities== | ||
− | |||
===Swap=== | ===Swap=== | ||
{{dsc begin}} | {{dsc begin}} | ||
Line 116: | Line 110: | ||
{{dsc namespace|std::rel_ops}} | {{dsc namespace|std::rel_ops}} | ||
{{dsc inc|cpp/utility/rel_ops/dsc operator_cmp}} | {{dsc inc|cpp/utility/rel_ops/dsc operator_cmp}} | ||
+ | {{dsc end}} | ||
+ | |||
+ | ===Construction tags=== | ||
+ | {{dsc begin}} | ||
+ | {{dsc header|utility}} | ||
+ | {{dsc inc|cpp/utility/dsc piecewise_construct}} | ||
+ | {{dsc inc|cpp/utility/dsc in_place}} | ||
+ | {{dsc inc|cpp/utility/dsc nontype}} | ||
{{dsc end}} | {{dsc end}} | ||
Line 122: | Line 124: | ||
{{dsc header|utility}} | {{dsc header|utility}} | ||
{{dsc inc|cpp/utility/dsc pair}} | {{dsc inc|cpp/utility/dsc pair}} | ||
− | |||
− | |||
{{dsc header|tuple}} | {{dsc header|tuple}} | ||
{{dsc inc|cpp/utility/dsc tuple}} | {{dsc inc|cpp/utility/dsc tuple}} | ||
Line 133: | Line 133: | ||
{{dsc header|array}} | {{dsc header|array}} | ||
{{dsc header|ranges}} | {{dsc header|ranges}} | ||
+ | {{dsc header|complex}} | ||
{{dsc inc|cpp/utility/dsc tuple_size}} | {{dsc inc|cpp/utility/dsc tuple_size}} | ||
{{dsc inc|cpp/utility/dsc tuple_element}} | {{dsc inc|cpp/utility/dsc tuple_element}} | ||
Line 150: | Line 151: | ||
{{dsc header|any}} | {{dsc header|any}} | ||
{{dsc inc|cpp/utility/dsc any}} | {{dsc inc|cpp/utility/dsc any}} | ||
− | |||
− | |||
− | |||
{{dsc end}} | {{dsc end}} | ||
Line 173: | Line 171: | ||
Time tracking (e.g. {{lc|std::chrono::time_point}}, {{lc|std::chrono::duration}}), C-style date and time (e.g. {{lc|std::time}}, {{lc|std::clock}}) | Time tracking (e.g. {{lc|std::chrono::time_point}}, {{lc|std::chrono::duration}}), C-style date and time (e.g. {{lc|std::time}}, {{lc|std::clock}}) | ||
− | === | + | ===Primitive string conversions=== |
In addition to sophisticated locale-dependent parsers and formatters provided by the [[cpp/io|C++ I/O]] library, the [[cpp/io/c|C I/O]] library, [[cpp/string/basic_string#Numeric conversions|C++ string converters]], and [[cpp/string/byte#Conversions to numeric formats|C string converters]], the header {{header|charconv}} provides light-weight, locale-independent, non-allocating, non-throwing parsers and formatters for arithmetic types. | In addition to sophisticated locale-dependent parsers and formatters provided by the [[cpp/io|C++ I/O]] library, the [[cpp/io/c|C I/O]] library, [[cpp/string/basic_string#Numeric conversions|C++ string converters]], and [[cpp/string/byte#Conversions to numeric formats|C string converters]], the header {{header|charconv}} provides light-weight, locale-independent, non-allocating, non-throwing parsers and formatters for arithmetic types. | ||
{{dsc begin}} | {{dsc begin}} |
Latest revision as of 01:42, 14 November 2024
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.
[edit] Language support
Language support libraries provide classes and functions that interact closely with language features and support common language idioms.
[edit] Type support
Basic types (e.g. std::size_t, std::nullptr_t), RTTI (e.g. std::type_info)
[edit] Metaprogramming
Type traits (e.g. std::is_integral, std::rank), compile-time constants (e.g. std::integer_sequence, std::ratio)
[edit] Constant evaluation context
Defined in header
<type_traits> | |
(C++20) |
detects whether the call occurs within a constant-evaluated context (function) |
(C++26) |
checks whether a pointer is within the object's lifetime at compile time (function) |
[edit] Implementation properties
The header <version> 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. |
(since C++20) |
[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] Source code information capture
Defined in header
<source_location> | |
(C++20) |
a class representing information about the source code, such as file names, line numbers, and function names (class) |
[edit] Initializer lists
Defined in header
<initializer_list> | |
(C++11) |
references a temporary array created in list-initialization (class template) |
[edit] Three-way comparison
Defined in header
<compare> | |
specifies that operator <=> produces consistent result on given types (concept) | |
(C++20) |
the result type of 3-way comparison that supports all 6 operators, is not substitutable, and allows incomparable values (class) |
(C++20) |
the result type of 3-way comparison that supports all 6 operators and is not substitutable (class) |
(C++20) |
the result type of 3-way comparison that supports all 6 operators and is substitutable (class) |
named comparison functions (function) | |
(C++20) |
constrained function object implementing x <=> y (class) |
(C++20) |
obtains the result type of the three-way comparison operator <=> on given types (class template) |
(C++20) |
the strongest comparison category to which all of the given types can be converted (class template) |
(C++20) |
performs 3-way comparison and produces a result of type std::strong_ordering (customization point object) |
(C++20) |
performs 3-way comparison and produces a result of type std::weak_ordering (customization point object) |
(C++20) |
performs 3-way comparison and produces a result of type std::partial_ordering (customization point object) |
performs 3-way comparison and produces a result of type std::strong_ordering , even if operator<=> is unavailable(customization point object) | |
(C++20) |
performs 3-way comparison and produces a result of type std::weak_ordering , even if operator<=> is unavailable(customization point object) |
performs 3-way comparison and produces a result of type std::partial_ordering , even if operator<=> is unavailable(customization point object) |
[edit] Coroutine support
Types for coroutine support, e.g. std::coroutine_traits, std::coroutine_handle. |
(since C++20) |
[edit] Variadic functions
Support for functions that take an arbitrary number of parameters (via e.g. va_start, va_arg, va_end).
[edit] General-purpose utilities
[edit] Swap
Defined in header
<utility> | |
swaps the values of two objects (function template) | |
(C++14) |
replaces the argument with a new value and returns its previous value (function template) |
Defined in header
<concepts> | |
(C++20) |
swaps the values of two objects (customization point object) |
[edit] Type operations
Defined in header
<utility> | |
(C++11) |
forwards a function argument and use the type template argument to preserve its value category (function template) |
(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) |
(C++11) |
converts the argument to an xvalue (function template) |
(C++11) |
converts the argument to an xvalue if the move constructor does not throw (function template) |
(C++17) |
obtains a reference to const to its argument (function template) |
(C++11) |
obtains a reference to an object of the template type argument for use in an unevaluated context (function template) |
(C++23) |
converts an enumeration to its underlying type (function template) |
[edit] Integer comparison functions
Defined in header
<utility> | |
compares two integer values, ensuring that signed negative numbers are less than unsigned numbers (function template) | |
(C++20) |
checks if an integer value is in the range of a given integer type (function template) |
[edit] Relational operators
Defined in header
<utility> | |
Defined in namespace
std::rel_ops | |
(deprecated in C++20) |
automatically generates comparison operators based on user-defined operator== and operator< (function template) |
[edit] Construction tags
Defined in header
<utility> | |
piecewise construction tag (tag) | |
in-place construction tag (tag) | |
(C++26) |
value construction tag (tag) |
[edit] Pairs and tuples
Defined in header
<utility> | |
implements binary tuple, i.e. a pair of values (class template) | |
Defined in header
<tuple> | |
(C++11) |
implements fixed size container, which holds elements of possibly different types (class template) |
(C++17) |
calls a function with a tuple of arguments (function template) |
(C++17) |
construct an object with a tuple of arguments (function template) |
Tuple protocol | |
Defined in header
<tuple> | |
Defined in header
<utility> | |
Defined in header
<array> | |
Defined in header
<ranges> | |
Defined in header
<complex> | |
(C++11) |
obtains the number of elements of a tuple-like type (class template) |
(C++11) |
obtains the element types of a tuple-like type (class template) |
[edit] Sum types and type erased wrappers
Defined in header
<optional> | |
(C++17) |
a wrapper that may or may not hold an object (class template) |
Defined in header
<expected> | |
(C++23) |
a wrapper that contains either an expected or error value (class template) |
Defined in header
<variant> | |
(C++17) |
a type-safe discriminated union (class template) |
Defined in header
<any> | |
(C++17) |
objects that hold instances of any CopyConstructible type (class) |
[edit] Bitset
Defined in header
<bitset> | |
implements constant length bit array (class template) |
[edit] Function objects
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.
[edit] Hash support
Defined in header
<functional> | |
(C++11) |
hash function object (class template) |
[edit] Date and time
Time tracking (e.g. std::chrono::time_point, std::chrono::duration), C-style date and time (e.g. std::time, std::clock)
[edit] Primitive string conversions
In addition to sophisticated locale-dependent parsers and formatters provided by the C++ I/O library, the C I/O library, C++ string converters, and C string converters, the header <charconv> provides light-weight, locale-independent, non-allocating, non-throwing parsers and formatters for arithmetic types.
Defined in header
<charconv> | |
(C++17) |
converts an integer or floating-point value to a character sequence (function) |
(C++17) |
the return type of std::to_chars (class) |
(C++17) |
converts a character sequence to an integer or floating-point value (function) |
(C++17) |
the return type of std::from_chars (class) |
(C++17) |
specifies formatting for std::to_chars and std::from_chars (enum) |
[edit] Formatting library
Facilities for type-safe string formatting.
Defined in header
<format> | |
(C++20) |
stores formatted representation of the arguments in a new string (function template) |
(C++20) |
writes out formatted representation of its arguments through an output iterator (function template) |
(C++20) |
writes out formatted representation of its arguments through an output iterator, not exceeding specified size (function template) |
(C++20) |
determines the number of characters necessary to store the formatted representation of its arguments (function template) |
(C++20) |
non-template variant of std::format using type-erased argument representation (function) |
(C++20) |
non-template variant of std::format_to using type-erased argument representation (function template) |
(C++20) |
defines formatting rules for a given type (class template) |
(C++20) |
exception type thrown on formatting errors (class) |
[edit] See also
C documentation for Utility library
|