##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# Standard library header <utility>

From cppreference.com
< cpp‎ | header

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`
operator!=operator>operator<=operator>= | automatically generates comparison operators based on user-defined operator== and operator< (function template) [edit]
### Functions
swap | swaps the values of two objects (function template) [edit]
forward (C++11) | forwards a function argument (function template) [edit]
move (C++11) | obtains an rvalue reference (function template) [edit]
move_if_noexcept (C++11) | obtains an rvalue reference if the move constructor does not throw (function template) [edit]
declval (C++11) | obtains the type of expression in unevaluated context (function template) [edit]
make_pair | creates a `pair` object of type, defined by the argument types (function template) [edit]
operator==operator!=operator<operator<=operator>operator>= | lexicographically compares the values in the pair (function template) [edit]
std::swap(std::pair) (C++11) | specializes the std::swap algorithm (function template) [edit]
std::get(std::pair) (C++11) | accesses an element of a `pair` (function template) [edit]
### Classes
pair | implements binary tuple, i.e. a pair of values (class template) [edit]
piecewise_construct_t (C++11) | tag type used to select correct function overload for piecewise construction (class) [edit]
##### Forward declarations
tuple (C++11) | implements fixed size container, which holds elements of possibly different types (class template) [edit]
##### Objects
piecewise_construct (C++11) | an object of type `piecewise_construct_t` used to disambiguate functions for piecewise construction (constant) [edit]

### [edit] 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(noexcept(a.swap(b));
        template <class T, size_t N>
            void swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b)));

        // forward/move:
        template <class T> T&& forward(typename remove_reference<T>::type& t) noexcept;
        template <class T> T&& forward(typename remove_reference<T>::type&& t) noexcept;
        template <class T> typename remove_reference<T>::type&& move(T&&) noexcept;
        template <class T> typename conditional<
            !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value,
            const T&, T&&>::type move_if_noexcept(T& x) noexcept;

        // declval, as unevaluated operand:
        template <class T>
            typename add_rvalue_reference<T>::type declval() noexcept;

        // pairs:
        template <class T1, class T2> struct pair;

        // pair specialized algorithms:
        template <class T1, class T2>
            bool operator==(const pair<T1,T2>&, const
        template <class T1, class T2>
            bool operator< (const pair<T1,T2>&, const pair<T1,T2>&);
        template <class T1, class T2>
            bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&);
        template <class T1, class T2>
            bool operator> (const pair<T1,T2>&, const pair<T1,T2>&);
        template <class T1, class T2>
            bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&);
        template <class T1, class T2>
            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>
            pair<V1,V2> 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<std::pair<T1, T2> >;
        template <class T1, class T2> struct tuple_element<0, std::pair<T1, T2> >;
        template <class T1, class T2> struct tuple_element<1, std::pair<T1, T2> >;

        template<size_t I, class T1, class T2>
            typename tuple_element<I, std::pair<T1, T2> >::type&
            get(std::pair<T1, T2>&) noexcept;
        template<size_t I, class T1, class T2>
            typename tuple_element<I, std::pair<T1, T2> >::type&&
            get(std::pair<T1, T2>&&) noexcept;
        template<size_t I, class T1, class T2>
            const typename tuple_element<I, std::pair<T1, T2> >::type&
                get(const std::pair<T1, T2>&) noexcept;

        // pair piecewise construction
        struct piecewise_construct_t { };
        constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();

        template <class... Types> class tuple; // defined in <tuple>
    }

#### [edit] Class std::pair

    template <class T1, class T2>
    struct pair {
        typedef T1 first_type;
        typedef T2 second_type;

        T1 first;
        T2 second;
        pair(const pair&) = default;
        pair(pair&&) = default;

        constexpr pair();
        pair(const T1& x, const T2& y);
        template<class U, class V> pair(U&& x, V&& y);
        template<class U, class V> pair(const pair<U, V>& p);
        template<class U, class V> 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 below);
        template<class U, class V> pair& operator=(pair<U, V>&& p);

        void swap(pair& p) noexcept( noexcept(swap(first, p.first)) &&
                                     noexcept(swap(second, p.second)) );
    };

### [edit] See also

`<tuple>` | Defines std::tuple
Utility library

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/header/utility&oldid=57551"