-
Book Overview & Buying
-
Table Of Contents
C++20 STL Cookbook
By :
An ordered task list (or a ToDo list) is a common computing application. Formally stated, it's a list of tasks associated with a priority, sorted in reverse numerical order.
You may be tempted to use a priority_queue for this, because as the name implies, it's already sorted in priority (reverse numerical) order. The disadvantage of a priority_queue is that it has no iterators, so it's difficult to operate on it without pushing and popping items to and from the queue.
For this recipe, we'll use a multimap for the ordered list. The multimap associative container keeps items in order, and it can be accessed using reverse iterators for the proper sort order.
This is a short and simple recipe that initializes a multimap and prints it in reverse order.
multimap:using todomap = multimap<int, string>;
Our todomap is a multimap with an int key and a string...