The class pair treats two values as a single unit.
Element Access as follow:
namespace std {
template <typename T1, typename T2>
struct pair {
// member
T1 first;
T2 second;
...
};
}
Assignment Operators
#include <functional> //for std::ref()
float a=0.1,b=0.2;
std::pair<float, float> p1{a,b};
auto z1 = std::make_pair(std::move(12),std::move(b));
auto z2 = std::make_pair(a,std::move(b));
auto z3 = std::make_pair(std::ref(a),std::ref(b));
float t1;
std::tie(t1, std::ignore) = z3;
// pass the tuple as a whole to the constructor of Foo:
pair<int,Foo> p1 (42, t);
// pass the elements of the tuple to the constructor of Foo:
pair<int,Foo> p2 (piecewise_construct, make_tuple(42), t);
piecewise_construct用于打开后面参数的tuple, 将大开的数据以typename... Args的形式作为参数。