June 2017
Intermediate to advanced
532 pages
12h 59m
English
The split algorithm works in a similar manner to std::transform because it accepts a pair of begin/end iterators of an input range and an output iterator. It does something with the input range, which, in the end, results in assignments to the output iterator. Apart from that, it accepts an item value called split_val and a binary function. Let's revisit the whole implementation to fully understand it:
template <typename InIt, typename OutIt, typename T, typename F>InIt split(InIt it, InIt end_it, OutIt out_it, T split_val, F bin_func){ while (it != end_it) { auto slice_end (find(it, end_it, split_val)); *out_it++ = bin_func(it, slice_end); if (slice_end == end_it) { return end_it; } it = next(slice_end); } return it;}
Read now
Unlock full access