Difference between revisions of "cpp/header/utility"
From cppreference.com
(+as_const, in_place_*, synopsys from n4606) |
m (Remove duplicate as_const) |
||
Line 23: | Line 23: | ||
{{dsc inc | cpp/utility/pair/dsc swap2}} | {{dsc inc | cpp/utility/pair/dsc swap2}} | ||
{{dsc inc | cpp/utility/pair/dsc get}} | {{dsc inc | cpp/utility/pair/dsc get}} | ||
− | |||
{{dsc h1|Classes}} | {{dsc h1|Classes}} | ||
{{dsc inc | cpp/utility/dsc pair}} | {{dsc inc | cpp/utility/dsc pair}} |
Revision as of 09:22, 25 November 2016
This header is part of the general utility library.
Includes | ||
<initializer_list>(C++11) | ||
Namespaces | ||
rel_ops
|
Provide automatic comparison operators | |
Defined in namespace
std::rel_ops | ||
(deprecated in C++20) |
automatically generates comparison operators based on user-defined operator== and operator< (function template) | |
Functions | ||
swaps the values of two objects (function template) | ||
(C++14) |
replaces the argument with a new value and returns its previous value (function template) | |
(C++11) |
forwards a function argument and use the type template argument to preserve its value category (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) | |
creates a pair object of type, determined by the argument types (function template) | ||
(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) | |
(C++11) |
specializes the std::swap algorithm (function template) | |
(C++11) |
accesses an element of a pair (function template) | |
Classes | ||
implements binary tuple, i.e. a pair of values (class template) | ||
(C++14) |
implements compile-time sequence of integers (class template) | |
Helpers | ||
(C++11) |
tag type used to select correct function overload for piecewise construction (class) | |
piecewise construction tag (tag) | ||
in-place construction tag (tag) | ||
Forward declarations | ||
(C++11) |
implements fixed size container, which holds elements of possibly different types (class template) |
Synopsis
#include <initializer_list> namespace std { // operators: namespace 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&); } // swap: template <class T> void swap(T& a, T& b) noexcept(/*see definition*/ ); template <class T, size_t N> void swap(T (&a)[N], T (&b)[N]) noexcept(is_nothrow_swappable_v<T>); // exchange: template <class T, class U=T> T exchange(T& obj, U&& new_val); // forward/move: template <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_const: template <class T> constexpr add_const_t<T>& as_const(T& t) noexcept; template <class T> void as_const(const T&&) = delete; // declval: template <class T> add_rvalue_reference_t<T> declval() noexcept; // as unevaluated operand // Compile-time integer sequences template<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 definition*/ >; 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)>; // pairs: template <class T1, class T2> struct pair; // pair specialized algorithms: template <class T1, class T2> constexpr bool operator==(const pair<T1, T2>&, const pair<T1, T2>&); template <class T1, class T2> constexpr bool operator< (const pair<T1, T2>&, const pair<T1, T2>&); template <class T1, class T2> constexpr bool operator!=(const pair<T1, T2>&, const pair<T1, T2>&); template <class T1, class T2> constexpr bool operator> (const pair<T1, T2>&, const pair<T1, T2>&); template <class T1, class T2> constexpr bool operator>=(const pair<T1, T2>&, const pair<T1, T2>&); template <class T1, class T2> constexpr bool operator<=(const pair<T1, T2>&, const pair<T1, T2>&); template <class T1, class T2> void swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y))); template <class T1, class T2> constexpr /*see definition*/ make_pair(T1&&, T2&&); // tuple-like access to pair: template <class T> class tuple_size; template <size_t I, class T> class tuple_element; template <class T1, class T2> struct tuple_size<pair<T1, T2>>; template <class T1, class T2> struct tuple_element<0, pair<T1, T2>>; template <class T1, class T2> struct tuple_element<1, 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> constexpr const tuple_element_t<I, pair<T1, T2>>& get(const pair<T1, T2>&) noexcept; template<size_t I, class T1, class T2> constexpr const tuple_element_t<I, pair<T1, T2>>&& get(const pair<T1, T2>&&) noexcept; template <class T, class U> constexpr T& get(pair<T, U>& p) noexcept; template <class T, class U> constexpr const T& get(const pair<T, U>& p) noexcept; template <class T, class U> constexpr T&& get(pair<T, U>&& p) noexcept; template <class T, class U> constexpr const T&& get(const pair<T, U>&& p) noexcept; template <class T, class U> constexpr T& get(pair<U, T>& p) noexcept; template <class T, class U> constexpr const T& get(const pair<U, T>& p) noexcept; template <class T, class U> constexpr T&& get(pair<U, T>&& p) noexcept; template <class T, class U> constexpr const T&& get(const pair<U, T>&& p) noexcept; // pair piecewise construction struct piecewise_construct_t { }; constexpr piecewise_construct_t piecewise_construct{}; template <class... Types> class tuple; // defined in <tuple> // in-place construction struct in_place_tag { in_place_tag() = delete; }; using in_place_t = in_place_tag(&)(unspecified ); template <class T> using in_place_type_t = in_place_tag(&)(unspecified <T>); template <size_t I> using in_place_index_t = in_place_tag(&)(unspecified <I>); in_place_tag in_place(unspecified ); template <class T> in_place_tag in_place(unspecified <T>); template <size_t I> in_place_tag in_place(unspecified <I>); }
Class template std::integer_sequence
namespace std { template<class T, T... I> struct integer_sequence { using value_type = T; static constexpr size_t size() noexcept { return sizeof...(I); } }; }
Class 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; constexpr pair(); /*conditionally-explicit*/ constexpr pair(const T1& x, const T2& y); template<class U, class V> /*conditionally-explicit*/ constexpr pair(U&& x, V&& y); template<class U, class V> /*conditionally-explicit*/ constexpr pair(const pair<U, V>& p); template<class U, class V> /*conditionally-explicit*/ constexpr pair(pair<U, V>&& p); template <class... Args1, class... Args2> pair(piecewise_construct_t, tuple<Args1...> first_args, tuple<Args2...> second_args); pair& operator=(const pair& p); template<class U, class V> pair& operator=(const pair<U, V>& p); pair& operator=(pair&& p) noexcept(/*see definition*/ ); template<class U, class V> pair& operator=(pair<U, V>&& p); void swap(pair& p) noexcept(/*see definition*/); }; }
See also
<tuple> | Defines std::tuple |
Utility library |