C++11: Standard Library Functions begin and end

Image

In Section 7.7, we showed how to sort an array object with the C++ Standard Library function sort. We sorted an array of strings called colors as follows:

sort( colors.begin(), colors.end() ); // sort contents of colors

The array class’s begin and end functions specified that the entire array should be sorted. Function sort (and many other C++ Standard Library functions) can also be applied to built-in arrays. For example, to sort the built-in array n shown earlier in this section, you can write:

sort( begin( n ), end( n ) ); // sort contents of built-in array n

C++11’s new begin and end functions ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.