Chapter 4. The array Class Template

Even Solomon in all his glory was not arrayed like one of these.

The Gospel According to Saint Matthew, 6:29

C-style arrays are tricky to use with STL algorithms. The size of the array is not part of its type, and the name of the array in almost all contexts decays into a pointer to its first element. So code that creates iterators into C-style arrays has to deal directly with the size of the array.

Example 4.1. C-style Arrays and the STL (contarray/carray.cpp)

#include <algorithm>#include <iostream>using std::cout; using std::sort;void do_sort (int *values, int count)  { // sort contents of array  sort (values,  values + count);  }int main ()  { // demonstrate use of C-style array as STL sequence  const int ELEMS = 6; ...

Get The C++ Standard Library Extensions A Tutorial and Reference 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.