pair class template — Represents a pair of related objects
template <typename T1, typename T2> struct pair { typedef T1 first_type; typedef T2 second_type; T1 first; T2 second; pair( ); pair(const T1& x, const T2& y); template<typename U, typename V> pair(const pair<U, V> &p); };
The pair
class template
represents a pair of related objects, in which the relationship is
defined by the programmer. The most common use of pairs is by the
map
class template, which stores
pairs of keys and associated objects.
The Boost project has a generalization of pair
, called tuple
. See Appendix B for information about
Boost.
The pair
constructors are
straightforward:
pair
( )
Initializes first
as
T1( )
and second
as T2( )
pair
(const T1& x, const T2&
y)
Initializes first
with x
and second
with y
template<typename
U
, typename
V>
, pair
(const
pair<U
, V>
&p)
Initializes first
with p.first
and second
with p.second
, performing implicit
conversions as needed