How to do it...

In this section, we will implement our own prefix tree only made from STL data structures and algorithms.

  1. We will include all the headers from the STL parts we use and declare that we use the std namespace by default:
      #include <iostream>      #include <optional>      #include <algorithm>      #include <functional>      #include <iterator>      #include <map>      #include <vector>      #include <string>      using namespace std;
  1. The entire program revolves around a trie for which we have to implement a class first. In our implementation, a trie is basically a recursive map of maps. Every trie node contains a map, which maps from an instance of the payload type T to the next trie node:
      template <typename T>      class trie      {          map<T, trie> tries;
  1. The code for ...

Get C++17 STL Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.