16.1 Introduction

This chapter discusses the Standard Library’s algorithms, focusing on common container manipulations such as searching, sorting and comparing elements or entire containers. The Standard Library provides over 90 algorithms—many were added in C++11 and some are new in C++14. For the complete list, see


http://en.cppreference.com/w/cpp/algorithm
http://en.cppreference.com/w/cpp/numeric

As you’ll see, various algorithms can receive a function pointer as an argument—recall that a function’s name is implictly convertible to a pointer to that function’s code. Such algorithms use the pointer to call the function, typically with one or two container elements as arguments. For most of the examples in this chapter, rather than function pointers we’ll use lambda expressions—C++11’s convenient shorthand notation for creating anonymous functions (that is, functions that do not have names). Later in the chapter we’ll present the concept of a function object, which is similar to a lambda or a function pointer but is implemented as an object of a class that has an overloaded function-call operator (operator()). This allows the object’s name to be used like a function name.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset