<tuple>

Description
Synopsis
Classes
Functions

Description

Include the TR1 header <tuple> to define a template tuple whose instances hold objects of varying types.

Note:
With the next revision of the C++ Standard (C++0X), this header makes extensive use of variadic templates, indicated by various uses of ellipsis (...). The descriptions below use C++0X notation, but still apply to older compilers, provided the number of parameters in a varying-length list does not exceed ten.
Note:
To enable this header file, you must define the macro __IBMCPP_TR1__ .

Synopsis

namespace std {
    namespace tr1 {

    // TEMPLATE CLASSES
 template<class... Types>
    class tuple;

 template<int Idx, class Ty>
     class tuple_element; // not defined
 template<int Idx, class... Types>
     class tuple_element<Idx, tuple<Types...>>;

template<class Ty>
     class tuple_size; // not defined
 template<class... Types>
     class tuple_size<tuple<Types...>>;

    // TEMPLATE Functions
 template<int Idx, class Types>
     typename tuple_element <Idx, tuple<Types...>>::type&
         get(tuple<Types...&> tpl);
 template<int Idx, class Types>
     typename tuple_element <Idx, tuple<Types...>>::type&
         get(const tuple<Types...&> tpl);

 template<class... Types>
     tuple<Types2...>
         make_tuple(Types...);
 template<class... Types>
     tuple<Types&...>
         Tie(Types&...);

    // TEMPLATE COMPARISON OPERATORS
 template<class... Types1, class... Types2>
    bool operator==(const tuple<Types1...>& tpl1,
    const tuple<Types2...>& tpl2;
 template<class... Types1, class... Types2>
    bool operator!=(const tuple<Types1...>& tpl1,
    const tuple<Types2...>& tpl2;
 template<class... Types1, class... Types2>
    bool operator<(const tuple<Types1...>& tpl1,
    const tuple<Types2...>& tpl2;
 template<class... Types1, class... Types2>
    bool operator<=(const tuple<Types1...>& tpl1,
    const tuple<Types2...>& tpl2;
 template<class... Types1, class... Types2>
    bool operator>(const tuple<Types1...>& tpl1,
    const tuple<Types2...>& tpl2;
 template<class... Types1, class... Types2>
    bool operator>=(const tuple<Types1...>& tpl1,
    const tuple<Types2...>& tpl2;

    //CONST OBJECTS
const T1 ignore;

    }  // namespace tr1
}  // namespace std

Classes

tuple
tuple_element
tuple_size

tuple

Description
Synopsis
Constructor
tuple::tuple
Operators
tuple::operator=
Description

The template class describes an object that stores zero or more objects of types specified by Types. The extent of a tuple instance is the number N of its template arguments. The index of the template argument Ti (counting from zero) and of the corresponding stored value of that type is i.

Synopsis
template<class... Types>
class tuple {
public:
    tuple();
    explicit tuple(const Types&...);
    tuple(const tuple& right);
    template <class... Types2>
        tuple(const tuple<Types2...>& right);
    template <class U1, class U2>
        tuple(const pair<U1, U2>& right);

    tuple(tuple&& right)
    template <class... Types2>
        tuple(tuple<Types2...>&& right);
    template <class U1, class U2>
        tuple(pair<U1, U2>&& right);

    tuple& operator=(const tuple& right);
    template <class... Types2>
        tuple& operator=(const tuple<Types2...>& right);
    template <class U1, class U2>
        tuple& operator=(const pair<U1, U2>& right);

    tuple& operator=(tuple&& right);
    template <class... Types2>
        tuple& operator=(tuple<Types2...>&& right);
    template <class U1, class U2>
        tuple& operator=(pair<U1, U2>&& right);
    };
Constructor
tuple::tuple

tuple();
    explicit tuple(const Types&...);
    tuple(const tuple& right);
    template <class... Types2>
        tuple(const tuple<Types2...>& right);
    template <class U1, class U2>
        tuple(const pair<U1, U2>& right);

tuple(tuple&& right)
    template <class... Types2>
        tuple(tuple<Types2...>&& right);
    template <class U1, class U2>
        tuple(pair<U1, U2>&& right);

The first constructor constructs an object whose elements are default constructed. The second constructor constructs an object whose elements are copy constructed from the argument list. The third and fourth constructors construct an object whose elements are copy constructed from the corresponding element of right. The fifth constructor constructs an object whose element at index 0 is copy constructed from right.first and whose element at index 1 is copy constructed from right.second.

Operators
tuple::operator=

tuple& operator=(const tuple& right);
    template <class... Types2>
        tuple& operator=(const tuple<Types2...>& right);
    template <class U1, class U2>
        tuple& operator=(const pair<U1, U2>& right);

    tuple& operator=(tuple&& right);
    template <class... Types2>
        tuple& operator=(tuple<Types2...>&& right);
    template <class U1, class U2>
        tuple& operator=(pair<U1, U2>&& right);

The first two member operators assign the elements of right to the corresponding elements of *this. The third member operator assigns right.first to the element at index 0 of *this and right.second to the element at index 1. All three member operators return *this.

tuple_element

template<int Idx, class Ty>
    class tuple_element; // not defined
template<int Idx, class... Types>
    class tuple_element<Idx, tuple<Types...>>;

The template class has a member type Type that is a synonym for the type at index Idx of the type Tuple<Types...>.

tuple_size

template<class Ty>
    class tuple_size; // not defined
template<class... Types>
    class tuple_size<tuple<Types...>>;   

The template class has a member const int value whose value is the extent of the type Tuple<Types...>.

Functions

get
make_tuple
operator==
operator!=
operator<
operator<=
operator>
operator>=
tie

get

template<int Idx, class... Types>
    typename tuple_element <Idx, tuple<Types...>>::type&
        get(tuple<Types...&> tpl);
 template<int Idx, class Types>
     typename tuple_element <Idx, tuple<Types...>>::type&
        get(const tuple<Types...&> tpl);

The template functions return a reference to the value at index Idx in the tuple object tpl. If the corresponding type Ti in Types is a reference type, both functions return Ti; otherwise the first function returns Ti& and the second function returns const Ti&.

make_tuple

template<class... Types>
    tuple<Types2...>
    make_tuple(Types...);

The template function returns a tuple object constructed from the argument list, where each type T2i in Types2 is the same as Ti in Types, except where Ti is reference_wrapper<X>, in which case T2i is X.

operator==

template<class... Types1, class... Types2>
    bool operator==(const tuple<Types1...>& tpl1,
    const tuple<Types2...>& tpl2;

The function returns true only when both tuples are empty, or when get<0>(tpl1) == get<0>(tpl2) &&... for all corresponding elements.

operator!=

template<class... Types1, class... Types2>
    bool operator!=(const tuple<Types1...>& tpl1,
    const tuple<Types2...>& tpl2;

The function returns !(tpl1 == tpl2).

operator<

template<class... Types1, class... Types2>
    bool operator<(const tuple<Types1...>& tpl1,
    const tuple<Types2...>& tpl2;

The function returns true only when both tuples are not empty and get<0>(tpl1) < get<0>(tpl2) || !(get<0>(tpl2) < get<0>(tpl1)) &&... for all corresponding elements.

operator<=

template<class... Types1, class... Types2>
    bool operator<=(const tuple<Types1...>& tpl1,
    const tuple<Types2...>& tpl2;

The function returns !(tpl2 < tpl1).

operator>

template<class... Types1, class... Types2>
    bool operator>(const tuple<Types1...>& tpl1,
    const tuple<Types2...>& tpl2;

The function returns tpl2 < tpl1.

operator>=

template<class... Types1, class... Types2>
    bool operator>=(const tuple<Types1...>& tpl1,
    const tuple<Types2...>& tpl2;

The function returns !(tpl1 < tpl2).

tie

template<class... Types>
     tuple<Types&...>
         Tie(Types&...);

The template function returns a tuple object constructed from the argument list, where each element is a reference. Note that a reference to ignore can be assigned anything and will do nothing.

Copyright note

Certain materials included or referred to in this document are copyright P.J. Plauger and/or Dinkumware, Ltd. or are based on materials that are copyright P.J. Plauger and/or Dinkumware, Ltd.

Notwithstanding the meta-data for this document, copyright information for this document is as follows:

Copyright © IBM Corp. 1999, 2010. & Copyright © P.J. Plauger and/or Dinkumware, Ltd. 1992-2006.