All Iterator Adapters
All Iterator Adapters
A compact scan page for reverse, move, insert, and stream iterator adapters plus the related helper functions.
All Iterator Adapters
A compact scan page for reverse, move, insert, and stream iterator adapters plus the related helper functions.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
std::reverse_iteratorstd::move_iteratorrbegin and rendstd::back_insert_iteratorstd::front_insert_iteratorstd::insert_iteratorback_inserter, front_inserter, inserterstd::istream_iteratorstd::ostream_iteratorstd::istreambuf_iteratorstd::ostreambuf_iteratormove_iterator changes value category behavior, not ownership by itself.#include <algorithm>
#include <iterator>
#include <vector>
int main() {
std::vector<int> source{1, 2, 3};
std::vector<int> dest;
std::copy(source.begin(), source.end(), std::back_inserter(dest));
return dest.back();
}
Use back_inserter when an algorithm should grow the destination container instead of assuming preallocated output space.
std::vector<std::string> src{"Ada", "Grace"};
std::vector<std::string> dst;
std::move(std::make_move_iterator(src.begin()),
std::make_move_iterator(src.end()),
std::back_inserter(dst));
Use move_iterator when the algorithm should move from the source range instead of copying.
#include <algorithm>
#include <iterator>
#include <vector>
int main() {
std::vector<int> source{1, 2, 3};
std::vector<int> dest;
std::copy(source.begin(), source.end(), std::back_inserter(dest));
return dest.back();
}