MORE ON ALGORITHMS
The algorithm and numeric headers define a large number of algorithms. The algorithms in the numeric header are primarily devoted to processing arrays of numerical values, whereas those in the algorithm header are more general purpose and provide such things as the ability to search, sort, copy, and merge sequences of objects specified by iterators. There are far too many to discuss in detail in this introductory chapter, so I’ll just introduce a few of the most useful algorithms from the algorithm header to give you a basic idea of how they can be used.
You have already seen the sort() and copy() algorithms from the algorithm header in action. Let’s take a brief look at a few other of the more interesting functions in the algorithm header:
The fill() algorithm
fill(ForwardIterator begin, ForwardIterator end, const Type& value)
fill(v.begin(), v.begin()+10, "invalid");
The replace() algorithm
replace(ForwardIterator begin, ForwardIterator end,
const Type& oldValue, const Type& newValue)
Get Ivor Horton's Beginning Visual C++ 2012 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.