[utility.syn] # 22 General utilities library [[utilities]](./#utilities) ## 22.2 Utility components [[utility]](utility#syn) ### 22.2.1 Header synopsis [utility.syn] [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L29) The header contains some basic function and class templates that are used throughout the rest of the library[.](#1.sentence-1) // all freestanding#include // see [[compare.syn]](compare.syn "17.12.1 Header synopsis")#include // see [[initializer.list.syn]](initializer.list.syn "17.11.2 Header synopsis")namespace std {// [[utility.swap]](utility.swap "22.2.2 swap"), swaptemplateconstexpr void swap(T& a, T& b) noexcept(*see below*); templateconstexpr void swap(T (&a)[N], T (&b)[N]) noexcept(is_nothrow_swappable_v); // [[utility.exchange]](utility.exchange "22.2.3 exchange"), exchangetemplateconstexpr T exchange(T& obj, U&& new_val) noexcept(*see below*); // [[forward]](forward "22.2.4 Forward/move helpers"), forward/movetemplateconstexpr T&& forward(remove_reference_t& t) noexcept; templateconstexpr T&& forward(remove_reference_t&& t) noexcept; templateconstexpr auto forward_like(U&& x) noexcept -> *see below*; templateconstexpr remove_reference_t&& move(T&&) noexcept; templateconstexpr conditional_t && is_copy_constructible_v, const T&, T&&> move_if_noexcept(T& x) noexcept; // [[utility.as.const]](utility.as.const "22.2.5 Function template as_­const"), as_consttemplateconstexpr add_const_t& as_const(T& t) noexcept; templatevoid as_const(const T&&) = delete; // [[declval]](declval "22.2.6 Function template declval"), declvaltemplate add_rvalue_reference_t declval() noexcept; // as unevaluated operand// [[utility.intcmp]](utility.intcmp "22.2.7 Integer comparison functions"), integer comparison functionstemplateconstexpr bool cmp_equal(T t, U u) noexcept; templateconstexpr bool cmp_not_equal(T t, U u) noexcept; templateconstexpr bool cmp_less(T t, U u) noexcept; templateconstexpr bool cmp_greater(T t, U u) noexcept; templateconstexpr bool cmp_less_equal(T t, U u) noexcept; templateconstexpr bool cmp_greater_equal(T t, U u) noexcept; templateconstexpr bool in_range(T t) noexcept; // [[utility.underlying]](utility.underlying "22.2.8 Function template to_­underlying"), to_underlyingtemplateconstexpr underlying_type_t to_underlying(T value) noexcept; // [[utility.undefined]](utility.undefined "22.2.9 Undefined behavior"), undefined behavior[[noreturn]] void unreachable(); void observable_checkpoint() noexcept; // [[intseq]](intseq "21.2 Compile-time integer sequences"), compile-time integer sequencestemplatestruct integer_sequence; templateusing [index_sequence](#lib:index_sequence "22.2.1 Header synopsis [utility.syn]") = integer_sequence; templateusing make_integer_sequence = integer_sequence; templateusing [make_index_sequence](#lib:make_index_sequence "22.2.1 Header synopsis [utility.syn]") = make_integer_sequence; templateusing [index_sequence_for](#lib:index_sequence_for "22.2.1 Header synopsis [utility.syn]") = make_index_sequence; // [[pairs]](pairs "22.3 Pairs"), class template pairtemplatestruct pair; template class TQual, template class UQual>requires requires { typename pair, UQual>, common_reference_t, UQual>>; }struct basic_common_reference, pair, TQual, UQual> {using type = pair, UQual>, common_reference_t, UQual>>; }; templaterequires requires { typename pair, common_type_t>; }struct common_type, pair> {using type = pair, common_type_t>; }; // [[pairs.spec]](pairs.spec "22.3.3 Specialized algorithms"), pair specialized algorithmstemplateconstexpr bool operator==(const pair&, const pair&); templateconstexpr common_comparison_category_t<*synth-three-way-result*, *synth-three-way-result*>operator<=>(const pair&, const pair&); templateconstexpr void swap(pair& x, pair& y) noexcept(noexcept(x.swap(y))); templateconstexpr void swap(const pair& x, const pair& y)noexcept(noexcept(x.swap(y))); templateconstexpr *see below* make_pair(T1&&, T2&&); // [[pair.astuple]](pair.astuple "22.3.4 Tuple-like access to pair"), tuple-like access to pairtemplate struct tuple_size; template struct tuple_element; template struct tuple_size>; template struct tuple_element>; templateconstexpr tuple_element_t>& get(pair&) noexcept; templateconstexpr tuple_element_t>&& get(pair&&) noexcept; templateconstexpr const tuple_element_t>& get(const pair&) noexcept; templateconstexpr const tuple_element_t>&& get(const pair&&) noexcept; templateconstexpr T1& get(pair& p) noexcept; templateconstexpr const T1& get(const pair& p) noexcept; templateconstexpr T1&& get(pair&& p) noexcept; templateconstexpr const T1&& get(const pair&& p) noexcept; templateconstexpr T2& get(pair& p) noexcept; templateconstexpr const T2& get(const pair& p) noexcept; templateconstexpr T2&& get(pair&& p) noexcept; templateconstexpr const T2&& get(const pair&& p) noexcept; // [[pair.piecewise]](pair.piecewise "22.3.5 Piecewise construction"), pair piecewise constructionstruct piecewise_construct_t {explicit piecewise_construct_t() = default; }; inline constexpr piecewise_construct_t piecewise_construct{}; template class tuple; // defined in [](tuple.syn#header:%3ctuple%3e "22.4.2 Header synopsis [tuple.syn]")// in-place constructionstruct in_place_t {explicit in_place_t() = default; }; inline constexpr in_place_t in_place{}; templatestruct in_place_type_t {explicit in_place_type_t() = default; }; template constexpr in_place_type_t in_place_type{}; templatestruct in_place_index_t {explicit in_place_index_t() = default; }; template constexpr in_place_index_t in_place_index{}; // nontype argument tagtemplatestruct nontype_t {explicit nontype_t() = default; }; template constexpr nontype_t nontype{}; // [[variant.monostate]](variant.monostate "22.6.8 Class monostate"), class monostatestruct monostate; // [[variant.monostate.relops]](variant.monostate.relops "22.6.9 monostate relational operators"), monostate relational operatorsconstexpr bool operator==(monostate, monostate) noexcept; constexpr strong_ordering operator<=>(monostate, monostate) noexcept; // [[variant.hash]](variant.hash "22.6.12 Hash support"), hash supporttemplate struct hash; template<> struct hash;}