Daily bit(e) of C++ | std::front_inserter, std::back_inserter, std::inserter
Daily bit(e) of C++ ♻️99, Inserting new elements into containers using inserter iterator adapters.
Preallocating sufficient capacity for elements is generally the performance-optimal approach when working with standard containers. However, this can add code complexity, and the required capacity might not even be known 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.