11.2.3. The pair
Type
Before we look at the operations on associative containers, we need to know about the library type named pair
, which is defined in the utility
header.
A pair
holds two data members. Like the containers, pair
is a template from which we generate specific types. We must supply two type names when we create a pair
. The data members of the pair
have the corresponding types. There is no requirement that the two types be the same:
pair<string, string> anon; // holds two stringspair<string, size_t> word_count; // holds a string and an size_tpair<string, vector<int>> line; // holds string and vector<int>
The default pair
constructor value initializes (§ 3.3.1, p. 98) the data members. Thus, anon
is a pair
of two empty
Get C++ Primer, Fifth Edition 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.