June 2017
Intermediate to advanced
532 pages
12h 59m
English
As std::copy is one of the simplest STL algorithms, its implementation is very short. Let's have a look at how it could be implemented:
template <typename InputIterator, typename OutputIterator>OutputIterator copy(InputIterator it, InputIterator end_it, OutputIterator out_it){ for (; it != end_it; ++it, ++out_it) { *out_it = *it; } return out_it;}
This looks exactly as one would implement the copying of items from one iterable range to the other by hand, naively. At this point, one could also ask, "So why not implementing it by hand, the loop is simple enough and I don't even need the return value?", which is, of course, a good question.
While std::copy is not the best example for making code significantly shorter, a lot ...
Read now
Unlock full access