C++C++11C++14C++17Generic ProgrammingIteratorsLearn C++

Helpers for Generic C++ Code Iterating Over Sequences

The iterator library that is part of the C++ Standard Library provides the following helpers for writing generic code: #include <iterator> // helpers are defined here template<class Container> void foo(Container& c) { // Generic way to obtain (constant) iterators auto b = std::begin(c); // (1) auto cb = std::cbegin(c); // (2) auto e = std::end(c); //…
Read more
C++C++11C++14C++17Iterators

The Move Iterator Adapter in C++

The dereference prefix operator * being applied to iterator returns the lvalue reference to the element pointed by the iterator. Therefore, algorithms such as std::copy or std::transform calls copying constructors of processed elements, for example: #include <algorithm> #include <list> #include <string> #include <vector> auto deep_copy_to_list(const…
Read more