After reading the previous recipe, some of the readers may start using fast pool allocators everywhere; especially, for std::set
and std::map
. Well, I'm not going to stop you from doing that, but at least let's take a look at an alternative: flat associative containers. These containers are implemented on top of the traditional vector container and store the values ordered.
The flat containers are part of the Boost.Container
library. We already saw how to use some of its containers in the previous recipes. In this recipe, we'll be using a flat_set
associative container:
- We'll need to include only a single header file:
#include <boost/container/flat_set.hpp>
- After that, we are free to construct the flat container and experiment with it:
#include <algorithm> #include <cassert> int main() { boost::container::flat_set<int> set;
- Reserving...