Standard library header <tuple> - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# Standard library header <tuple>

From cppreference.com
< cpp‎ | header

This header is part of the general utility library.

### Classes
tuple (C++11) | implements fixed size container, which holds elements of possibly different types (class template) [edit]
tuple_size | obtains the size of `tuple` at compile time (class template specialization) [edit]
tuple_element | obtains the type of the specified element (class template specialization) [edit]
std::uses_allocator<std::tuple> (C++11) | specializes the std::uses_allocator type trait (class template specialization) [edit]
### Constants
ignore | placeholder to skip an element when unpacking a `tuple` using `tie` (constant) [edit]
### Functions
make_tuple | creates a `tuple` object of the type defined by the argument types (function template) [edit]
tie | creates a `tuple` of lvalue references or unpacks a tuple into individual objects (function template) [edit]
forward_as_tuple | creates a `tuple` of rvalue references (function template) [edit]
tuple_cat | creates a `tuple` by concatenating any number of tuples (function template) [edit]
std::get(std::tuple) | tuple accesses specified element (function template) [edit]
operator==operator!=operator<operator<=operator>operator>= | lexicographically compares the values in the tuple (function template) [edit]
std::swap(std::tuple) (C++11) | specializes the std::swap algorithm (function template) [edit]

### [edit] Synopsis

    namespace std {

        // class template tuple:
        template <class... Types> class tuple;

        // tuple creation functions:
        const /*unspecified*/ ignore;
        template <class... Types>
            tuple<VTypes...> make_tuple(Types&&...);
        template <class... Types>
            tuple<Types...> forward_as_tuple(Types&&...) noexcept;
        template<class... Types>
            tuple<Types&...> tie(Types&...) noexcept;
        template <class... Tuples>
            tuple<Ctypes...> tuple_cat(Tuples&&...);

        //  tuple helper classes:
        template <class T> class tuple_size; // undefined
        template <class T> class tuple_size<const T>;
        template <class T> class tuple_size<volatile T>;
        template <class T> class tuple_size<const volatile T>;
        template <class... Types> class tuple_size<tuple<Types...> >;

        template    <size_t I,  class   T>  class   tuple_element; // undefined
        template    <size_t I,  class   T>  class   tuple_element<I, const T>;
        template    <size_t I,  class   T>  class   tuple_element<I, volatile T>;
        template    <size_t I,  class   T>  class   tuple_element<I, const volatile T>;
        template <size_t I, class... Types> class tuple_element<I, tuple<Types...> >;

        //  element access:
        template <size_t I, class... Types>
            typename tuple_element<I, tuple<Types...> >::type& get(tuple<Types...>&) noexcept;
        template <size_t I, class... types>
            typename tuple_element<I, tuple<Types...> >::type&& get(tuple<Types...>&&) noexcept;
        template <size_t I, class... types>
            typename tuple_element<I, tuple<Types...> >::type const& get(const tuple<Types...>&) noexcept;

        //relational operators:
        template<class... TTypes, class... UTypes>
            bool operator==(const tuple<TTypes...>&, const tuple<UTypes...>&);
        template<class... TTypes, class... UTypes>
            bool operator<(const tuple<TTypes...>&, const tuple<UTypes...>&);
        template<class... TTypes, class... UTypes>
            bool operator!=(const tuple<TTypes...>&, const tuple<UTypes...>&);
        template<class... TTypes, class... UTypes>
            bool operator>(const tuple<TTypes...>&, const tuple<UTypes...>&);
        template<class... TTypes, class... UTypes>
            bool operator<=(const tuple<TTypes...>&, const tuple<UTypes...>&);
        template<class... TTypes, class... UTypes>
            bool operator>=(const tuple<TTypes...>&, const tuple<UTypes...>&);

        // allocator-related traits
        template <class... Types, class Alloc>
            struct uses_allocator<tuple<Types...>, Alloc>;
        // specialized algorithms:
        template <class... Types>
            void swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(x.swap(y));
    }

#### [edit] Class std::tuple

    template <class... Types>
    class tuple {
    public:
        // tuple construction
        constexpr tuple();
        explicit tuple(const Types&...);
        template <class... UTypes>
            explicit tuple(UTypes&&...);
        tuple(const tuple&) = default;
        tuple(tuple&&) = default;
        template <class... UTypes>
            tuple(const tuple<UTypes...>&);
        template <class... UTypes>
            tuple(tuple<UTypes...>&&);
        template <class U1, class U2>
            tuple(const pair<U1, U2>&);  // iff sizeof...(Types) == 2
        template <class U1, class U2>
            tuple(pair<U1, U2>&&);       // iff sizeof...(Types) == 2

        // allocator-extended constructors
        template <class Alloc>
            tuple(allocator_arg_t, const Alloc& a);
        template <class Alloc>
            tuple(allocator_arg_t, const Alloc& a, const Types&...);
        template <class Alloc, class... UTypes>
            tuple(allocator_arg_t, const Alloc& a, const UTypes&&...);
        template <class Alloc>
            tuple(allocator_arg_t, const Alloc& a, const tuple&);
        template <class Alloc>
            tuple(allocator_arg_t, const Alloc& a, tuple&&);
        template <class Alloc, class... UTypes>
            tuple(allocator_arg_t, const Alloc& a, const tuple<UTypes...>&);
        template <class Alloc, class... UTypes>
            tuple(allocator_arg_t, const Alloc& a, tuple<UTypes...>&&);
        template <class Alloc, class U1, class U2>
            tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&);
        template <class Alloc, class U1, class U2>
            tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&);

        // tuple assignment
        tuple& operator=(const tuple&);
        tuple& operator=(tuple&&) noexcept(see below);
        template <class... UTypes>
            tuple& operator=(const tuple<UTypes...>&);
        template <class... UTypes>
            tuple& operator=(tuple<UTypes...>&&);
        template <class U1, class U2>
            tuple& operator=(const pair<U1, U2>&); // iff sizeof...(Types) == 2
        template <class U1, class U2>
            tuple& operator=(pair<U1, U2>&&) noexcept; // iff sizeof...(Types) == 2

        // tuple swap
        void swap(tuple&) noexcept(see below);
    };

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