Daily bit(e) of C++ | std::front_inserter, std::back_inserter, std::inserter
Daily bit(e) of C++ #99, The iterator adapters that insert elements into ranges: std::front_inserter, std::back_inserter, std::inserter
Preallocating capacity for elements is generally the performance-optimal approach. However, it adds code complexity, and we might not know the number of elements upfront.
Inserter adapters solve this problem by adapting the destination range and calling push_back (back_inserter), push_front (front_inserter) or insert (inserter) on each write.