The Floating-Point Environment Library

The pair Class

The pair class is used to house pairs of objects, such as might be stored in an associative container. It has this template specification:

template <class Ktype, class Vtype> struct pair {   typedef Ktype first_type;    typedef Vtype second_type;    Ktype first;    Vtype second;    // constructors   pair();   pair(const Ktype &k, const Vtype &v);   template<class A, class B> pair(const<A, B> &ob); } 

The value in first typically contains a key, and the value in second typically contains the value associated with that key.

The following operators are defined for pair: ==, !=, <, <=, >, and >=.

You can construct a pair using either one of pair’s constructors or by using make_pair( ), which constructs a pair object based upon the types of the data used as parameters. make_pair( ) is a generic function that has this prototype:

      template <class Ktype, class Vtype>
         pair<Ktype, Vtype> make_pair(const Ktype &k, const Vtype &v);

It returns a pair object consisting of values of the types specified by Ktype and Vtype. The advantage of make_pair( ) is that the types of the objects being stored are determined automatically by the compiler rather than being explicitly specified by you.

The pair class and the make_pair( ) function require the header <utility>.

C(s)C++ Programmer's Reference
C Programming on the IBM PC (C Programmers Reference Guide Series)
ISBN: 0673462897
EAN: 2147483647
Year: 2002
Pages: 539 © 2008-2017.
If you may any questions please contact us: