editing 15 notes

This commit is contained in:
Jidong Xiao
2024-03-01 13:29:35 -05:00
parent eba29b1de4
commit 0f520ed3eb

View File

@@ -69,8 +69,7 @@ changed. It can only be erased (together with the associated value).
The mechanics of using std::pairs are relatively straightforward: The mechanics of using std::pairs are relatively straightforward:
- std::pairs are a templated struct with just two members, called first and second. Reminder: a struct - std::pairs are a templated struct with just two members, called first and second. Reminder: a struct
is basically a wimpy class and in this course you arent allowed to create new structs. You should use classes is basically a wimpy class.
instead.
- To work with pairs, you must #include <utility>. Note that the header file for maps (#include <map>) - To work with pairs, you must #include <utility>. Note that the header file for maps (#include <map>)
itself includes utility, so you dont have to include utility explicitly when you use pairs with maps. itself includes utility, so you dont have to include utility explicitly when you use pairs with maps.
- Here are simple examples of manipulating pairs: - Here are simple examples of manipulating pairs:
@@ -87,7 +86,7 @@ p3.second = -1.5;
// p3.first = std::string("illegal"); // (a) // p3.first = std::string("illegal"); // (a)
// p1 = p3; // (b) // p1 = p3; // (b)
``` ```
- The function std::make pair creates a pair object from the given values. It is really just a simplified - The function std::make_pair creates a pair object from the given values. It is really just a simplified
constructor, and as the example shows there are other ways of constructing pairs. constructor, and as the example shows there are other ways of constructing pairs.
- Most of the statements in the above code show accessing and changing values in pairs. - Most of the statements in the above code show accessing and changing values in pairs.
The two statements at the end are commented out because they cause syntax errors: The two statements at the end are commented out because they cause syntax errors: