Apache C++ Standard Library Reference Guide

## pair

Library: General utilities

    Does not inherit

- Local Index
- Summary
- Synopsis
- Description
- Interface
- Member Types
- Constructors
- Destructor
- Nonmember Operators
- Nonmember Functions
- See Also
- Standards Conformance

### Local Index

#### Members

first_type | pair() | second_type | ~pair()

#### Non-Members

make_pair() operator!=() | operator>() operator>=() | operator<() operator<=() | operator==()

### Summary

A template utility class for pairs of values that may be of different types

### Synopsis

    #include <utility>

    namespace std {
      template <class T1, class T2>
      struct pair;
    }

### Description

The pair class is a template for encapsulating pairs of values that may be of different types.

### Interface

    namespace std {

      template <class T1, class T2>
      struct pair {
         typedef T1 first_type;
         typedef T2 second_type;
         T1 first;
         T2 second;
         pair();
         pair(const T1&, const T2&);
         template <class V, class U>
         pair (const pair <V, U>& p);
         ~pair();
      };

      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>
      bool operator>=(const pair<T1, T2>&,
                     const pair T1, T2>&);

      template <class T1, class T2>
      pair<T1,T2> make_pair (const T1&, const T2&);
    }

### Member Types

    first_type

Type of the first element in a pair.

    second_type

Type of the second element in a pair.

### Constructors

    pair();

Default constructor. Initializes `first` and `second` using their default constructors.

    pair(const T1& x, const T2& y);

Creates a pair of types `T1` and `T2`, making the necessary conversions in`x` and `y`.

    template <class V, class U>
    pair(const pair <V, U>& p);

Copies `first` and `second` from the corresponding elements of `p`.

### Destructor

    ~pair ();

### Nonmember Operators

    template <class T1, class T2>
    bool operator== (const pair<T1, T2>& x,
                      const pair T1, T2>& y);

Returns `true` if `(x.first == y.first && x.second == y.second`) is `true`. Otherwise it returns `false`.

    template <class T1, class T2>
    bool operator!= (const pair<T1, T2>& x,
                      const pair T1, T2>& y);

Returns `!(x==y)`.

    template <class T1, class T2>
    bool operator< (const pair<T1, T2>& x,
                    const pair T1, T2>& y);

Returns `true` if `(x.first < y.first || (!(y.first < x.first) && x.second < y.second))` is `true`. Otherwise it returns `false`.

    template <class T1, class T2>
    bool operator> (const pair<T1, T2>& x,
                    const pair T1, T2>& y);

Returns `y < x`.

    template <class T1, class T2>
    bool operator<= (const pair<T1, T2>& x,
                    const pair T1, T2>& y);

Returns `!(y > x)`.

    template <class T1, class T2>
    bool operator>= (const pair<T1, T2>& x,
                    const pair T1, T2>& y);

Returns `!(x < y)`.

### Nonmember Functions

    template <class T1, class T2>
    pair<T1,T2>
    make_pair(x,y);

Creates a pair by deducing and returning the types of `x` and `y`.

### See Also

<utility>

### Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems --Programming Language C++, Section 20.2.2