June 2017
Intermediate to advanced
532 pages
12h 59m
English
We solved the whole complexity of the problem without any loop or manual comparison of items. We only provided a predicate function, which tells if two given characters are whitespace characters. Then we fed that predicate into std::unique and poof, all the excess whitespace vanished. While this chapter also contains some recipes where we had to fight a bit more to express our programs with STL algorithms, this algorithm is a really nice and short example.
How does this interesting combination work in detail? Let's have a look at a possible implementation of std::unique first:
template<typename It, typename P>It unique(It it, It end, P p){ if (it == end) { return end; } It result {it}; while (++it != end) { if (!p(*result, ...Read now
Unlock full access