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 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 ...

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