Skip to content

Commit

Permalink
A comment about the erase-remove idiom.
Browse files Browse the repository at this point in the history
  • Loading branch information
Queequeg92 committed Nov 26, 2014
1 parent e7ca21b commit 28a95d7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ch11/ex11_3_4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
//! Exercise 11.4
void word_count_pro(std::map<std::string, int> &m)
{
for(std::string word; std::cin >> word; /* */)
std::string word;
while(std::cin >> word)
{
for(auto& ch : word)
for(auto& ch : word)
ch = std::tolower(ch);
//! According to the erase-remove idiom.
//! For more information about the erase-remove idiom, please refer to
//! http://en.wikipedia.org/wiki/Erase-remove_idiom
word.erase(std::remove_if(word.begin(), word.end(), ispunct), word.end());
++m[word];
}
Expand All @@ -32,7 +36,8 @@ void word_count_pro(std::map<std::string, int> &m)
void ex11_3()
{
std::map<std::string, std::size_t> word_count;
for(std::string word; std::cin >> word; /* */)
std::string word;
while(std::cin >> word)
{
++word_count[word];
for (const auto &elem : word_count)
Expand Down

0 comments on commit 28a95d7

Please sign in to comment.