O'Reilly logo

C++17 STL Cookbook by Jacek Galowicz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

In this section, we will implement a terminal app, which accepts some input and then tries to guess what the user might want to look for, based on a cheap text file database:

  1. As always, includes come first, and we define that we use the std namespace:
      #include <iostream>      #include <optional>      #include <algorithm>      #include <functional>      #include <iterator>      #include <map>      #include <list>      #include <string>      #include <sstream>      #include <fstream>        using namespace std;
  1. We use the trie implementation from the trie recipe:
      template <typename T>      class trie      {          map<T, trie> tries;            public:          template <typename It>          void insert(It it, It end_it) {              if (it == end_it) { return; }              tries[*it].insert(next(it), end_it);          } template <typename C> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required