September 2017
Beginner to intermediate
384 pages
9h 18m
English
Recall that, with std::list, we were able to splice lists together, move elements from one list to another, and so on, by using the "particular set of skills" of std::list. As of C++17, the tree-based containers have acquired similar skills!
The syntax for merging two sets or maps (or multisets or multimaps) is deceptively similar to the syntax for merging sorted std::list:
std::map<std::string, std::string> m = { {"hello", "world"}, {"quick", "brown"}, }; std::map<std::string, std::string> otherm = { {"hello", "dolly"}, {"sad", "clown"}, }; // This should look familiar! m.merge(otherm); assert((otherm == decltype(m){ {"hello", "dolly"}, })); assert((m == decltype(m){ {"hello", "world"}, {"quick", "brown"}, ...Read now
Unlock full access