Name
pair class template — Represents a pair of related objects
Synopsis
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
asT1( )
andsecond
asT2( )
-
pair
(const T1& x, const T2& y)
Initializes
first
withx
andsecond
withy
template<typename
U
,typename
V>
pair
(const
pair<U
,V>
&p)
Initializes
first
withp.first
andsecond
withp.second
, performing implicit conversions as needed
See Also
Get C++ In a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.