Skip to content

Latest commit

 

History

History
1513 lines (922 loc) · 69.2 KB

std_library.md

File metadata and controls

1513 lines (922 loc) · 69.2 KB

The standard library and proposals

Table of contents


General information

The standard library

🔗

🎥

📖

Implementations

🔗


Design principles

🎥


Algorithms

🔗

🎥

std::iota

🔗

std::min, std::max, std::minmax

🎥

std::midpoint

🎥

std::next_permutation / std::prev_permutation / std::is_permutation

std::[stable_]sort / std::is_sorted

🔗

std::[stable_]partition

🔗

std::[transform_]exclusive_scan / std::[transform_]inclusive_scan

🔗


Concepts

See also Concepts – Templates.

Why does same_as concept check type equality twice? – Stack Overflow


Containers

🎥

Associative containers

Associative containers are: std::set (collection of unique keys, sorted by keys), std::map (collection of key-value pairs, sorted by keys, keys are unique), std::multiset (collection of keys, sorted by keys), and std::multimap (collection of key-value pairs, sorted by keys).

🔗

std::set

🔗

std::map

Sequence containers

Sequence containers are: std::array (static contiguous array), std::vector (dynamic contiguous array), std::deque (double-ended queue), std::forward_list (singly-linked list), and std::list (doubly-linked list).

See also Arrays and vectors – Sequence data structures and algorithms.

🔗

std::array

std::deque

std::forward_list

Before this container was standardized, some Standard library implementations provided std::slist container as an extention.

🔗

std::list

🔗

std::vector

🔗

📖

std::vector<bool>

🔗

std::bitset

The class template bitset represents a fixed-size sequence of N bits. Bitsets can be manipulated by standard logic operators and converted to and from strings and integers.

Strings

std::string

The class template std::basic_string stores and manipulates sequences of char-like objects, which are non-array objects of trivial standard-layout type.

📝

  • std::basic_string<T, ...> is the only container in the standard library that requires T to be a trivial standard-layout type.

🔗

🎥

Short string optimization

See also Local buffer optimization – Patterns, idioms, and design principles.

std::string_view

The class template std::basic_string_view describes an object that can refer to a constant contiguous sequence of char-like objects.

🔗

🎥

C-strings

Unordered containers

Unordered containers are: std::unordered_set (collection of unique keys, hashed by keys), std::unordered_map (collection of key-value pairs, hashed by keys, keys are unique), std::unordered_multiset (collection of keys, hashed by keys), and std::unordered_multimap (collection of key-value pairs, hashed by keys).

🔗

🎥

std::hash

🔗

Container adaptors

std::stack

std::queue

std::priority_queue

Container views

std::span

The class template std::span describes an object that can refer to a contiguous sequence of objects with the first element of the sequence at position zero. A span can either have a static extent or a dynamic extent.

🔗

🎥

std::mdspan

🎥

Transparent comparators

Transparent comparators make it possible to avoid constructing an object of the type key_type to do the lookup using member functions like find, lower_bound, etc.

Erasing from containers

🔗

Signedness vs unsignedness of size

🔗

🎥

Non-standard containers

🔗


Exceptions

See also Exceptions – Core language and Exceptions – Patterns, idioms, and design principles.

🔗

noexcept specifier

std::bad_alloc


Input/output

🎥

Input/output manipulators

std::endl

🔗

Output formatting

🔗

Standard formatting library

🔗

std::stringstream

std::ios_base::Init

The class std::ios_base::Init is used to ensure that the default C++ streams (std::cin, std::cout, etc.) are properly initialized and destructed; the class tracks how many instances of it are created and initializes the C++ streams when the first instance is constructed as well as flushes the output streams when the last instance is destructed. The nifty counter idiom is typically used in implementations.


Iterators

See also Iterator – Patterns, idioms, and design principles and Boost.Iterator – Applications.

🔗

🎥

Reverse iterators


Ranges

🔗

🎥

Views

🎥

std::ranges::views::filter

🎥


Memory

See also Memory – Optimization and hardware.

std::malloc / std::calloc / std::free

📖

Allocators

🎥

Smart pointers

See also Boost.SmartPtr – Applications.

A smart pointer is a class that simulates a raw C++ pointer, and provides automatic exception-safe object lifetime management.

🔗

🎥

std::unique_ptr

The std::unique_ptr class is a smart pointer with unique ownership. std::unique_ptr<T> is almost as cheap as a raw pointer T*. For the Itanium ABI, any type with a destructor that is passed by value must be passed in memory: the address held in the std::unique_ptr​ must be written out to memory, rather than passed in registers as it would be for a raw ​T*​.

🔗

std::shared_ptr

The std::unique_ptr class is a smart pointer with shared ownership.

🔗

std::enable_shared_from_this

std::enable_shared_from_this allows a member function of an object that is currently managed by a std::shared_ptr to extend the lifetime of that object dynamically by generating additional std::shared_ptr instances.

🔗

std::weak_ptr

std::auto_ptr

std::auto_ptr is a smart pointer with unique ownership that had been designed before rvalue references and move semantics were introduced into the language. It was deprecated in C++11 and removed in C++17.

🔗

std::observer_ptr

std::observer_ptr is a smart pointer that takes no ownership responsibility for its pointees (non-owning pointer).

std::out_ptr and std::inout_ptr adaptors

std::out_ptr and std::inout_ptr are a thing convertible to a T** that updates (with a reset() call or semantically equivalent behavior) the smart pointer it is created with when it goes out of scope.

🔗

🎥


Numerics

Bit manipulation functions

std::bit_cast

Linear algebra support

🔗

🎥

Random numbers

🔗

🎥

Random engines

Random distributions

See Randomized algorithms and probabilistic data structures – Distributions.


Regular expressions

🔗

🎥


Type support

std::type_info

This class holds implementation-specific information about a type, including the name of the type and means to compare two types for equality or collating order. This is the class returned by the typeid operator.

Additional basic types

std::nullptr_t

std::nullptr_t is the type of the null pointer literal nullptr. It is a distinct type that is not itself a pointer type or a pointer to member type. An object of this type can be converted to any pointer or pointer-to-member type by a standard conversion.

🔗

Fixed-width integer types

std::int8_t, std::int16_t, std::int32_t, and std::int64_t are guaranteed to use 2’s complement to represent negative values. They are provided only if the implementation directly supports the type.

🔗

Uninitialized storage

std::aligned_storage defines the type suitable for use as uninitialized storage for types of given size, aligned_union defines the type suitable for use as uninitialized storage for all given types.

std::byte

Type traits

See also Type traits – Templates.

📝

  • There 14 primary type categories: is_void, is_null_pointer, is_integral, is_floating_point, is_array, is_enum, is_union, is_class, is_function, is_pointer, is_lvalue_reference, is_rvalue_reference, is_member_object_pointer, is_null_pointer. Each type belongs to exactly one of them.

🎥

std::is_class

std::is_base_of

std::is_trivial*

🎥

std::type_identity

🔗


Utilities

🔗

Integer comparison functions

Integer comparison functions std::cmp_equal, std::cmp_not_equal, std::cmp_less, std::cmp_greater, std::cmp_less_equal, std::cmp_greater_equal compare the values of two integers; unlike builtin comparison operators, negative signed integers always compare less than (and not equal to) unsigned integers: the comparison is safe against lossy integer conversion.

Function objects

🎥

std::reference_wrapper

std::reference_wrapper is a class template that wraps a reference in a copyable, assignable object; it can be used as a mechanism to store references inside standard containers, which cannot normally hold references.

🎥

std::initializer_list

An object of type std::initializer_list<T> is a lightweight proxy object that provides access to an array of objects of type const T.

Algebraic data types

🎥

Pairs and tuples

🎥

std::optional

The class template std::optional<T> is a type that may or may not store a value of type T in its storage space. It is recommended to be used in situations where there is exactly one and clear reason for having no value of type T, and where the lack of value is as natural as having any regular value of T. It is not recommended to use optional to indicate that we were not able to compute a value because of a failure.

🔗

std::variant

🔗

🎥

std::any

See also Type erasure – Patterns, idioms, and design principles.

🔗

std::expected

A utility class to represent expected monad.

🔗

🎥

std::launder

std::source_location

🔗


Date and time utilities

🔗

🎥


Filesystem


Tricks and subtleties

🔗

🎥

Self-assignment

🔗

C standard library

🔗


The Standard Template Library (STL)

🔗

📖

📄

🎥