#include <iostream>
#include <map>
#include <string>
std::map<std::string, int> ages;
// *** before: ***
void oldWay() {
// the full type had to be spelled out, and iterator types were long
std::map<std::string, int>::const_iterator it = ages.find("Ann");
if (it != ages.end())
std::cout << it->first << " is " << it->second << "\n";
for (std::map<std::string, int>::const_iterator i = ages.begin();
i != ages.end(); ++i)
std::cout << i->first << " ";
std::cout << "\n";
}
// *** in version C++11: ***
void newWay() {
auto it = ages.find("Ann"); // the type is taken from the initialiser
if (it != ages.end())
std::cout << it->first << " is " << it->second << "\n";
auto count = 0; // int
auto ratio = 1.5; // double
auto name = std::string("Bob"); // std::string
// auto drops the reference and const, so they are added by hand
const auto& first = *ages.begin();
std::cout << count << " " << ratio << " " << name
<< " " << first.first << "\n";
}
int main() {
ages["Ann"] = 31;
ages["Bob"] = 27;
oldWay();
newWay();
}