federico-busato / Modern-CPP-Programming

Modern C++ Programming Course (C++03/11/14/17/20/23/26)

Home Page:https://federico-busato.github.io/Modern-CPP-Programming/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Code fix in std::map example

eugenefil opened this issue · comments

On p.33 in file 17.Iterators_Containers_Alg.pdf under "std::map example" there are couple fixes in the last chunk:

         cout << it.second << " "; // 3, 5, 0, 7

     map1.insert( {"jj", 1} ); // insert pair
-    auto search = set1.find("jj"); // iterator
-    cout << search != set1.end(); // true
-    auto it = set1.lower_bound("bb");
-    cout << *it.second;
+    auto search = map1.find("jj"); // iterator
+    cout << (search != map1.end()); // true
+    auto it = map1.lower_bound("bb");
+    cout << (*it).second; // 5

Namely:

  • replaced set1 with map1
  • added parens around search != set1.end() due to << having higher precedence
  • added parens around *it due to postfix .second having higher precedence

Thanks for your careful review, @eugenefil

No, it's thank you, @federico-busato. Huge effort on your part. I'm trying to get up to speed with modern c++ and your course really helps. And the very format (practical, concise, like an index) is right on point.