C++17 STL Cookbook
上QQ阅读APP看书,第一时间看更新

Filtering duplicates from user input and printing them in alphabetical order with std::set

std::set is a strange container: It kind of works like std::map, but it contains only keys as values, no key-value pairs. So it can hardly be used as a way to map values of one type to the other. Seemingly, just because there are less obvious use cases for it, a lot of developers do not even know about its existence. Then they start to implement things themselves, although std::set would be of great help in some of these situations.

This section shows how to put std::set to use in an example where we collect potentially many different items, in order to filter them and output a selection of the unique ones.