1.简介
Pair与Tuple都是标准库提供的通用工具,主要用来组合两个或者多个值。
2.Pair
Pair可以由<utility>引入,定义在bits/stl_pair.h中
/**
* @brief Struct holding two objects of arbitrary type.
*
* @tparam _T1 Type of first object.
* @tparam _T2 Type of second object.
*/
template<typename _T1, typename _T2>
struct pair
: private __pair_base<_T1, _T2>
{
typedef _T1 first_type; /// @c first_type is the first bound type
typedef _T2 second_type; /// @c second_type is the second bound type
_T1 first; /// @c first is a copy of the first object
_T2 second;
}
2.1 默认构造函数
pair<T1,T2> p:默认构造函数,建立一个pair,其元素类型分别为T1和T2,各自以其default默认构造函数初始化
#include <iostream>
#include <utility>
u