C++C++11C++14C++17Iterators

Insert Iterators Adapters in C++

Let’s slightly modify the example from The Move Iterator Adapter in C++ post: #include #include #include #include /// @warning BUG! PLEASE, DON'T USE! auto deep_copy_to_list(const std::vector& src) { std::list dst; // constructs the empty list copy(cbegin(src), cend(src), begin(dst)); // cause memory corruption (if !src.empty())! return dst; } In the example above the object of…
Read more
C++C++11C++14C++17IteratorsLearn C++

Reverse Iterators in C++

By using bidirectional iterator or random access iterator (see Iterator Categories in C++) it’s possible to traverse the sequence in backward direction by using operator -- or by using the special adapter template class std::reverse_iterator. But why to bother with reverse…