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
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access