The Wayback Machine - https://web.archive.org/web/20201102050247/https://en.cppreference.com/w/cpp/header/utility
Namespaces
Variants
Actions

Standard library header <utility>

From cppreference.com
< cpp‎ | header
 
 
 

This header is part of the general utility library.

Contents

Includes

(C++20)
Three-way comparison operator support [edit]
std::initializer_list class template [edit]

Namespaces

rel_ops Provide automatic comparison operators
Defined in namespace std::rel_ops
automatically generates comparison operators based on user-defined operator== and operator<
(function template)[edit]

Functions

swaps the values of two objects
(function template)[edit]
(C++14)
replaces the argument with a new value and returns its previous value
(function template)[edit]
(C++11)
forwards a function argument
(function template)[edit]
(C++11)
obtains an rvalue reference
(function template)[edit]
obtains an rvalue reference if the move constructor does not throw
(function template)[edit]
(C++17)
obtains a reference to const to its argument
(function template)[edit]
(C++11)
obtains a reference to its argument for use in unevaluated context
(function template)[edit]
compares two integer values without value change caused by conversion
(function template)[edit]
(C++20)
checks if an integer value is in the range of a given integer type
(function template)[edit]
creates a pair object of type, defined by the argument types
(function template)[edit]
(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
lexicographically compares the values in the pair
(function template)[edit]
specializes the std::swap algorithm
(function template)[edit]
accesses an element of a pair
(function template)[edit]

Classes

implements binary tuple, i.e. a pair of values
(class template)[edit]
implements compile-time sequence of integers
(class template)[edit]
Forward declarations
Defined in header <tuple>
(C++11)
implements fixed size container, which holds elements of possibly different types
(class template)[edit]

Helpers

tag type used to select correct function overload for piecewise construction
(class)[edit]
an object of type piecewise_construct_t used to disambiguate functions for piecewise construction
(constant)[edit]
in-place construction tag
(class template)[edit]

[edit]Synopsis

#include <compare>#include <initializer_list>   namespace std {// swaptemplate<class T>constexprvoid swap(T& a, T& b)noexcept(/* see description */);template<class T, size_t N>constexprvoid swap(T (&a)[N], T (&b)[N])noexcept(is_nothrow_swappable_v<T>);   // exchangetemplate<class T, class U = T>constexpr T exchange(T& obj, U&& new_val);   // forward/movetemplate<class T>constexpr T&& forward(remove_reference_t<T>& t)noexcept;template<class T>constexpr T&& forward(remove_reference_t<T>&& t)noexcept;template<class T>constexpr remove_reference_t<T>&& move(T&&)noexcept;template<class T>constexpr conditional_t<!is_nothrow_move_constructible_v<T>&& is_copy_constructible_v<T>, const T&, T&&> move_if_noexcept(T& x)noexcept;   // as_consttemplate<class T>constexpr add_const_t<T>& as_const(T& t)noexcept;template<class T>void as_const(const T&&)= delete;   // declvaltemplate<class T> add_rvalue_reference_t<T> declval()noexcept;// as unevaluated operand   // integer comparison functionstemplate<class T, class U>constexprbool cmp_equal(T t, U u)noexcept;template<class T, class U>constexprbool cmp_not_equal(T t, U u)noexcept;   template<class T, class U>constexprbool cmp_less(T t, U u)noexcept;template<class T, class U>constexprbool cmp_greater(T t, U u)noexcept;template<class T, class U>constexprbool cmp_less_equal(T t, U u)noexcept;template<class T, class U>constexprbool cmp_greater_equal(T t, U u)noexcept;   template<class R, class T>constexprbool in_range(T t)noexcept;   // compile-time integer sequencestemplate<class T, T...>struct integer_sequence;template<size_t... I>using index_­sequence = integer_sequence<size_t, I...>;   template<class T, T N>using make_integer_sequence = integer_sequence<T, /* see description */>;template<size_t N>using make_index_sequence = make_integer_sequence<size_t, N>;   template<class... T>using index_sequence_for = make_index_sequence<sizeof...(T)>;   // class template pairtemplate<class T1, class T2>struct pair;   // pair specialized algorithmstemplate<class T1, class T2>constexprbool operator==(const pair<T1, T2>&, const pair<T1, T2>&);template<class T1, class T2>constexpr common_comparison_category_t</*synth-three-way-result*/<T1>, /*synth-three-way-result*/<T2>> operator<=>(const pair<T1, T2>&, const pair<T1, T2>&);   template<class T1, class T2>constexprvoid swap(pair<T1, T2>& x, pair<T1, T2>& y)noexcept(noexcept(x.swap(y)));   template<class T1, class T2>constexpr/* see description */ make_pair(T1&&, T2&&);   // tuple-like access to pairtemplate<class T>struct tuple_size;template<size_t I, class T>struct tuple_element;   template<class T1, class T2>struct tuple_size<pair<T1, T2>>;template<size_t I, class T1, class T2>struct tuple_element<I, pair<T1, T2>>;   template<size_t I, class T1, class T2>constexpr tuple_element_t<I, pair<T1, T2>>& get(pair<T1, T2>&)noexcept;template<size_t I, class T1, class T2>constexpr tuple_element_t<I, pair<T1, T2>>&& get(pair<T1, T2>&&)noexcept;template<size_t I, class T1, class T2>constexprconst tuple_element_t<I, pair<T1, T2>>& get(const pair<T1, T2>&)noexcept;template<size_t I, class T1, class T2>constexprconst tuple_element_t<I, pair<T1, T2>>&& get(const pair<T1, T2>&&)noexcept;template<class T1, class T2>constexpr T1& get(pair<T1, T2>& p)noexcept;template<class T1, class T2>constexprconst T1& get(const pair<T1, T2>& p)noexcept;template<class T1, class T2>constexpr T1&& get(pair<T1, T2>&& p)noexcept;template<class T1, class T2>constexprconst T1&& get(const pair<T1, T2>&& p)noexcept;template<class T2, class T1>constexpr T2& get(pair<T1, T2>& p)noexcept;template<class T2, class T1>constexprconst T2& get(const pair<T1, T2>& p)noexcept;template<class T2, class T1>constexpr T2&& get(pair<T1, T2>&& p)noexcept;template<class T2, class T1>constexprconst T2&& get(const pair<T1, T2>&& p)noexcept;   // pair piecewise constructionstruct piecewise_construct_t {explicit piecewise_construct_t()=default;};inlineconstexpr piecewise_construct_t piecewise_construct{};template<class... Types>class tuple;// defined in <tuple>   // in-place constructionstruct in_place_t {explicit in_place_t()=default;};inlineconstexpr in_place_t in_place{};   template<class T>struct in_place_type_t {explicit in_place_type_t()=default;};template<class T>inlineconstexpr in_place_type_t<T> in_place_type{};   template<size_t I>struct in_place_index_t {explicit in_place_index_t()=default;};template<size_t I>inlineconstexpr in_place_index_t<I> in_place_index{};}   // deprecatednamespace std::rel_ops{template<class T>bool operator!=(const T&, const T&);template<class T>bool operator>(const T&, const T&);template<class T>bool operator<=(const T&, const T&);template<class T>bool operator>=(const T&, const T&);}

[edit]Class template std::integer_sequence

namespace std {template<class T, T... I>struct integer_sequence {using value_type = T;staticconstexpr size_t size()noexcept{return sizeof...(I);}};}

[edit]Class template std::pair

namespace std {template<class T1, class T2>struct pair {using first_type = T1;using second_type = T2;   T1 first; T2 second;   pair(const pair&)=default; pair(pair&&)=default;constexprexplicit(/* see description */) pair();constexprexplicit(/* see description */) pair(const T1& x, const T2& y);template<class U1, class U2>constexprexplicit(/* see description */) pair(U1&& x, U2&& y);template<class U1, class U2>constexprexplicit(/* see description */) pair(const pair<U1, U2>& p);template<class U1, class U2>constexprexplicit(/* see description */) pair(pair<U1, U2>&& p);template<class... Args1, class... Args2>constexpr pair(piecewise_construct_t, tuple<Args1...> first_args, tuple<Args2...> second_args);   constexpr pair& operator=(const pair& p);template<class U1, class U2>constexpr pair& operator=(const pair<U1, U2>& p);constexpr pair& operator=(pair&& p)noexcept(/* see description */);template<class U1, class U2>constexpr pair& operator=(pair<U1, U2>&& p);   constexprvoid swap(pair& p)noexcept(/* see description */);};   template<class T1, class T2> pair(T1, T2)-> pair<T1, T2>;}

[edit]See also

(C++11)
std::tuple class template [edit]
Utility library
close