# Utility library

From cppreference.com
< cpp

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.

## Language support

Language support libraries provide classes and functions that interact closely with language features and support common language idioms.

### Type support

Basic types (e.g. std::size_t, std::nullptr_t), RTTI (e.g. std::type_info), type traits (e.g. std::is_integral, std::rank)

### Dynamic memory management

Smart pointers (e.g. std::shared_ptr), allocators (e.g. std::allocator or std::memory_resource), C-style memory management (e.g. std::malloc)

### Error handling

Exceptions (e.g. std::exception, std::terminate), assertions (e.g. assert)

### Initializer lists

initializer_list (C++11) | allows the use of initializer list syntax to initialize non-aggregate types (class template)

### Variadic functions

Support for functions that take an arbitrary number of parameters (via e.g. va_start, va_arg, va_end)

### 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)

## General-purpose utilities

### Program utilities

Termination (e.g. std::abort, std::atexit), environment (e.g. std::system), signals (e.g. std::raise)

### 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)

### Bitset

bitset | implements constant length bit array (class)

### 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), method to function converters std::mem_fn.

### Optional, variant and any

Defined in header `<optional>`
optional (C++17) | a wrapper that may or may not hold an object (class template)
Defined in header `<variant>`
variant (C++17) | a type-safe discriminated union (class template)
Defined in header `<any>`
any (C++17) | Objects that hold instances of any CopyConstructible type. (class)
Defined in header `<utility>`
in_place in_place_type in_place_index in_place_t in_place_type_t in_place_index_t (C++17) | in-place construction tag (class template)

### Pairs and tuples

pair | implements binary tuple, i.e. a pair of values (class template)
tuple (C++11) | implements fixed size container, which holds elements of possibly different types (class template)
apply (C++17) | calls a function with a tuple of arguments (function template)
make_from_tuple (C++17) | Construct an object with a tuple of arguments (function template)
piecewise_construct_t (C++11) | tag type used to select correct function overload for piecewise construction (class)
piecewise_construct (C++11) | an object of type `piecewise_construct_t` used to disambiguate functions for piecewise construction (constant)
integer_sequence (C++14) | implements compile-time sequence of integers (class template)

### Swap, forward and move

Defined in header `<utility>`
swap | swaps the values of two objects (function template)
exchange (C++14) | replaces the argument with a new value and returns its previous value (function template)
forward (C++11) | forwards a function argument (function template)
move (C++11) | obtains an rvalue reference (function template)
move_if_noexcept (C++11) | obtains an rvalue reference if the move constructor does not throw (function template)
Defined in header `<concepts>`
ranges::swap (C++20) | swaps the values of two objects (customization point object)

### Type operations

Defined in header `<utility>`
declval (C++11) | obtains a reference to its argument for use in unevaluated context (function template)
as_const (C++17) | obtains a reference to const to its argument (function template)
Defined in header `<new>`
launder (C++17) | pointer optimization barrier (function template)

### Relational operators and comparison

Defined in header `<compare>`
weak_equality (C++20) | the result type of 3-way comparison that supports only equality/inequality and is not substitutable (class)
strong_equality (C++20) | the result type of 3-way comparison that supports only equality/inequality and is substitutable (class)
partial_ordering (C++20) | the result type of 3-way comparison that supports all 6 operators, is not substitutable, and allows incomparable values (class)
weak_ordering (C++20) | the result type of 3-way comparison that supports all 6 operators and is not substitutable (class)
strong_ordering (C++20) | the result type of 3-way comparison that supports all 6 operators and is substitutable (class)
is_eqis_neqis_ltis_lteqis_gtis_gteq (C++20) | named comparison functions (function)
common_comparison_category (C++20) | the strongest comparison category to which all of the given types can be converted (class template)
strong_order (C++20) | performs 3-way comparison and produces a result of type std::strong_ordering (function template)
weak_order (C++20) | performs 3-way comparison and produces a result of type std::weak_ordering (function template)
partial_order (C++20) | performs 3-way comparison and produces a result of type std::partial_ordering (function template)
strong_equal (C++20) | performs 3-way comparison and produces a result of type std::strong_equality (function template)
weak_equal (C++20) | performs 3-way comparison and produces a result of type std::weak_equality (function template)
Defined in header `<utility>`
Defined in namespace `std::rel_ops`
operator!=operator>operator<=operator>= (deprecated in C++20) | automatically generates comparison operators based on user-defined operator== and operator< (function template)

### Elementary 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, ASCII-only parsers and formatters for arithmetic types.

Defined in header `<charconv>`
to_chars (C++17) | converts an integer or floating-point value to a character sequence (function)
from_chars (C++17) | converts a character sequence to an integer or floating-point value (function)
chars_format (C++17) | specifies formatting for std::to_chars and std::from_chars (enum)

### Hash support

hash (C++11) | hash function object (class template)

Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility&oldid=109903"