May 2017
Intermediate to advanced
590 pages
17h 18m
English
These iterator adapters are intended to be used with algorithms or functions that insert multiple elements into a range. They can be used, of course, to insert a single element, but that is rather an anti-pattern, since simply calling push_back(), push_front(), or insert() is much simpler and intuitive in this case. The following examples should be avoided:
std::vector<int> v{ 1,2,3,4,5 }; *std::back_inserter(v) = 6; // v = {1,2,3,4,5,6} std::back_insert_iterator<std::vector<int>> it(v); *it = 7; // v = {1,2,3,4,5,6,7}
Read now
Unlock full access